Skip to content

Commit

Permalink
Update heading renderer to latest Gemini spec
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tdemin committed Sep 17, 2021
1 parent 45180f9 commit 8135d1e
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions internal/renderer/renderer.go
Expand Up @@ -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 {
Expand Down

0 comments on commit 8135d1e

Please sign in to comment.