Update heading renderer to latest Gemini spec
Gemini spec p. 5.5.1 used to only allow up to three #-s in a heading before requiring a mandatory space. It changed to an optional space in recent updates, allowing to no longer pad Markdown H4-H6. As clients treat everything after ### a title continuation, the renderer will now insert H4-H6 verbatim; the end-user behavior doesn't change as extra space means nothing for a Gemtext renderer displaying the title in a special way. Relates to #1. PS: Gemini spec doesn't appear to be properly versioned, saying the latest version is 0.14.3, 2020-11-29. The discussion on #1 clearly shows it used to be different a while ago.
This commit is contained in:
parent
45180f9315
commit
8135d1e0b3
1 changed files with 2 additions and 11 deletions
|
@ -140,25 +140,16 @@ func (r Renderer) superscript(w io.Writer, node *ast.Superscript, 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; Gemini spec allows 3 at
|
||||
// maximum before the space, therefore add one after 3 and keep padding
|
||||
// pad headings with the relevant number of #-s; Gemini spec
|
||||
// used to allow 3 at maximum before a space
|
||||
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)
|
||||
r.text(w, node)
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue