if addNBSP && !*isOpen {
out .WriteString (" " )
}
out .WriteByte ('&' )
if *isOpen {
out .WriteByte ('l' )
} else {
out .WriteByte ('r' )
}
out .WriteByte (quote )
out .WriteString ("quo;" )
if addNBSP && *isOpen {
out .WriteString (" " )
}
return true
}
func (r *SPRenderer ) smartSingleQuote (out *bytes .Buffer , previousChar byte , text []byte ) int {
if len (text ) >= 2 {
t1 := tolower (text [1 ])
if t1 == '\'' {
nextChar := byte (0 )
if len (text ) >= 3 {
nextChar = text [2 ]
}
if smartQuoteHelper (out , previousChar , nextChar , 'd' , &r .inDoubleQuote , false ) {
return 1
}
}
if (t1 == 's' || t1 == 't' || t1 == 'm' || t1 == 'd' ) && (len (text ) < 3 || wordBoundary (text [2 ])) {
out .WriteString ("’" )
return 0
}
if len (text ) >= 3 {
t2 := tolower (text [2 ])
if ((t1 == 'r' && t2 == 'e' ) || (t1 == 'l' && t2 == 'l' ) || (t1 == 'v' && t2 == 'e' )) &&
(len (text ) < 4 || wordBoundary (text [3 ])) {
out .WriteString ("’" )
return 0
}
}
}
nextChar := byte (0 )
if len (text ) > 1 {
nextChar = text [1 ]
}
if smartQuoteHelper (out , previousChar , nextChar , 's' , &r .inSingleQuote , false ) {
return 0
}
out .WriteByte (text [0 ])
return 0
}
func (r *SPRenderer ) smartParens (out *bytes .Buffer , previousChar byte , text []byte ) int {
if len (text ) >= 3 {
t1 := tolower (text [1 ])
t2 := tolower (text [2 ])
if t1 == 'c' && t2 == ')' {
out .WriteString ("©" )
return 2
}
if t1 == 'r' && t2 == ')' {
out .WriteString ("®" )
return 2
}
if len (text ) >= 4 && t1 == 't' && t2 == 'm' && text [3 ] == ')' {
out .WriteString ("™" )
return 3
}
}
out .WriteByte (text [0 ])
return 0
}
func (r *SPRenderer ) smartDash (out *bytes .Buffer , previousChar byte , text []byte ) int {
if len (text ) >= 2 {
if text [1 ] == '-' {
out .WriteString ("—" )
return 1
}
if wordBoundary (previousChar ) && wordBoundary (text [1 ]) {
out .WriteString ("–" )
return 0
}
}
out .WriteByte (text [0 ])
return 0
}
func (r *SPRenderer ) smartDashLatex (out *bytes .Buffer , previousChar byte , text []byte ) int {
if len (text ) >= 3 && text [1 ] == '-' && text [2 ] == '-' {
out .WriteString ("—" )
return 2
}
if len (text ) >= 2 && text [1 ] == '-' {
out .WriteString ("–" )
return 1
}
out .WriteByte (text [0 ])
return 0
}
func (r *SPRenderer ) smartAmpVariant (out *bytes .Buffer , previousChar byte , text []byte , quote byte , addNBSP bool ) int {
if bytes .HasPrefix (text , []byte (""" )) {
nextChar := byte (0 )
if len (text ) >= 7 {
nextChar = text [6 ]
}
if smartQuoteHelper (out , previousChar , nextChar , quote , &r .inDoubleQuote , addNBSP ) {
return 5
}
}
if bytes .HasPrefix (text , []byte ("�" )) {
return 3
}
out .WriteByte ('&' )
return 0
}
func (r *SPRenderer ) smartAmp (angledQuotes , addNBSP bool ) func (*bytes .Buffer , byte , []byte ) int {
var quote byte = 'd'
if angledQuotes {
quote = 'a'
}
return func (out *bytes .Buffer , previousChar byte , text []byte ) int {
return r .smartAmpVariant (out , previousChar , text , quote , addNBSP )
}
}
func (r *SPRenderer ) smartPeriod (out *bytes .Buffer , previousChar byte , text []byte ) int {
if len (text ) >= 3 && text [1 ] == '.' && text [2 ] == '.' {
out .WriteString ("…" )
return 2
}
if len (text ) >= 5 && text [1 ] == ' ' && text [2 ] == '.' && text [3 ] == ' ' && text [4 ] == '.' {
out .WriteString ("…" )
return 4
}
out .WriteByte (text [0 ])
return 0
}
func (r *SPRenderer ) smartBacktick (out *bytes .Buffer , previousChar byte , text []byte ) int {
if len (text ) >= 2 && text [1 ] == '`' {
nextChar := byte (0 )
if len (text ) >= 3 {
nextChar = text [2 ]
}
if smartQuoteHelper (out , previousChar , nextChar , 'd' , &r .inDoubleQuote , false ) {
return 1
}
}
out .WriteByte (text [0 ])
return 0
}
func (r *SPRenderer ) smartNumberGeneric (out *bytes .Buffer , previousChar byte , text []byte ) int {