Handle H4-H6 in accordance with Gemini spec
Unlike Markdown, which has 6 levels of headings, Gemini spec (p. 5.5.1) only allows up to 3 shebang characters before a space. This adds an extra space before levels 4-6 in order to comply with the spec. Fixes #1.
This commit is contained in:
parent
2ea0b7d5fa
commit
0be85fc7f9
1 changed files with 13 additions and 2 deletions
|
@ -91,14 +91,25 @@ func (r Renderer) blockquote(w io.Writer, node *ast.BlockQuote, entering bool) {
|
|||
}
|
||||
}
|
||||
|
||||
const gemtextHeadingLevelLimit = 3
|
||||
|
||||
func (r Renderer) heading(w io.Writer, node *ast.Heading, entering bool) {
|
||||
if entering {
|
||||
// pad headings with the relevant number of #-s
|
||||
heading := make([]byte, node.Level+1)
|
||||
// pad headings with the relevant number of #-s; Gemini spec allows 3 at
|
||||
// maximum before the space, therefore add one after 3 and keep padding
|
||||
bufLength := node.Level + 1
|
||||
spaceNeeded := node.Level > gemtextHeadingLevelLimit
|
||||
if spaceNeeded {
|
||||
bufLength++
|
||||
}
|
||||
heading := make([]byte, bufLength)
|
||||
heading[len(heading)-1] = ' '
|
||||
for i := 0; i < len(heading)-1; i++ {
|
||||
heading[i] = '#'
|
||||
}
|
||||
if spaceNeeded {
|
||||
heading[gemtextHeadingLevelLimit] = ' '
|
||||
}
|
||||
w.Write(heading)
|
||||
for _, text := range node.Children {
|
||||
w.Write(text.AsLeaf().Literal)
|
||||
|
|
Loading…
Reference in a new issue