// getTextNode splits the `p` into two parts `textNode` and `rest` by the first encountered rune that resembles a span tag. If there is none, `textNode = p`, `rest = ""`. It handles escaping with backslash.
funcgetTextNode(input*bytes.Buffer)string{
var(
textNodeBuffer=bytes.Buffer{}
escaping=false
)
// Always read the first byte in advance to avoid endless loops that kill computers (sad experience)
ifinput.Len()!=0{
b,_:=input.ReadByte()
textNodeBuffer.WriteByte(b)
}
forinput.Len()!=0{
// Assume no error is possible because we check for length
b,_:=input.ReadByte()
ifescaping{
textNodeBuffer.WriteByte(b)
escaping=false
}elseifb=='\\'{
escaping=true
}elseifstrings.IndexByte("/*`^,!",b)>=0{
input.UnreadByte()
break
}else{
textNodeBuffer.WriteByte(b)
}
}
returntextNodeBuffer.String()
}
funcParagraphToHtml(inputstring)string{
var(
p=bytes.NewBufferString(input)
retstrings.Builder
// true = tag is opened, false = tag is not opened