From 8135d1e0b3753feb1df38a608d6e70a7ba130925 Mon Sep 17 00:00:00 2001 From: Timur Demin Date: Fri, 17 Sep 2021 23:02:17 +0500 Subject: [PATCH] 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. --- internal/renderer/renderer.go | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/internal/renderer/renderer.go b/internal/renderer/renderer.go index 8b84b90..9f35bf7 100644 --- a/internal/renderer/renderer.go +++ b/internal/renderer/renderer.go @@ -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 {