package markdown import ( "html" "strings" ) var ( headerStart = []string{"
") out.WriteString(html.EscapeString(paragraph.String())) out.WriteString("
") paragraph.Reset() } for { if i > len(markdown) { flush() return out.String() } if i != len(markdown) && markdown[i] != '\n' { i++ continue } line := markdown[lineStart:i] lineStart = i + 1 i++ switch { case strings.HasPrefix(line, "#"): flush() space := strings.IndexByte(line, ' ') if space > 0 && space <= 6 { out.WriteString(headerStart[space-1]) out.WriteString(html.EscapeString(line[space+1:])) out.WriteString(headerEnd[space-1]) } default: if len(line) == 0 { continue } if paragraph.Len() > 0 { paragraph.WriteByte(' ') } paragraph.WriteString(line) } } }