Skip to content

Commit

Permalink
Add preformatted text block support
Browse files Browse the repository at this point in the history
  • Loading branch information
tdemin committed Nov 7, 2020
1 parent 98d6ff6 commit b2a941b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
7 changes: 7 additions & 0 deletions cmd/gmnhg/main.go
Expand Up @@ -35,6 +35,13 @@ This is some more plain text. More of it!
* text.
3. Yay.
` + "```" + `
some preformatted text
another line of preformatted text
more lines of preformatted text
` + "```" + `
## Subheading 2
More text!
Expand Down
21 changes: 8 additions & 13 deletions internal/gemini/renderer.go
Expand Up @@ -26,7 +26,6 @@ func NewRenderer() Renderer {
}

// TODO: lists
// TODO: code renderer

func (r Renderer) link(w io.Writer, node *ast.Link, entering bool) {
if entering {
Expand Down Expand Up @@ -183,14 +182,10 @@ func (r Renderer) paragraph(w io.Writer, node *ast.Paragraph, entering bool) (no
return
}

func (r Renderer) code(w io.Writer, node *ast.Code, entering bool) {
// TODO: Renderer.code: untested yet
if entering {
w.Write([]byte("```\n"))
w.Write(node.Content)
} else {
w.Write([]byte("```\n"))
}
func (r Renderer) code(w io.Writer, node *ast.CodeBlock) {
w.Write([]byte("```\n"))
w.Write(node.Literal)
w.Write([]byte("```\n"))
}

func (r Renderer) text(w io.Writer, node *ast.Text) {
Expand All @@ -215,10 +210,10 @@ func (r Renderer) RenderNode(w io.Writer, node ast.Node, entering bool) ast.Walk
if !parentIsBlockQuote {
noNewLine = r.paragraph(w, node, entering)
}
case *ast.Code:
// TODO: *ast.Code render is likely to be merged into paragraph
r.code(w, node, entering)
noNewLine = false
case *ast.CodeBlock:
r.code(w, node)
// code block is not considered a wrapping element
w.Write(lineBreak)
}
if !noNewLine && !entering {
w.Write(lineBreak)
Expand Down

0 comments on commit b2a941b

Please sign in to comment.