Skip to content

Commit

Permalink
Don't output references in the HTML output (#90)
Browse files Browse the repository at this point in the history
* Dont output references in html output

Signed-off-by: Miek Gieben <[email protected]>

* Don't output references in the HTML output

<references> are XML2RFC XML tags and should not be outputted in the
HTML. Make a new ast: mast.ReferenceBlock to refer to these and ignore
those in the mhtml handler. For xml and xml2 they *do* need to be
outputted.

Signed-off-by: Miek Gieben <[email protected]>
  • Loading branch information
miekg authored Aug 19, 2019
1 parent f85099d commit 9165eaf
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 4 deletions.
8 changes: 8 additions & 0 deletions mast/reference.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package mast

import "github.com/gomarkdown/markdown/ast"

// ReferenceBlock represents markdown reference node.
type ReferenceBlock struct {
ast.Leaf
}
4 changes: 2 additions & 2 deletions mparser/bibliography.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ func ReferenceHook(data []byte) (ast.Node, []byte, int) {
return nil, nil, 0
}

node := &ast.HTMLBlock{}
node := &mast.ReferenceBlock{}
node.Literal = fmtReference(ref)
return node, nil, len(ref)
}

// IfReference returns wether data contains a reference.
// IsReference returns wether data contains a reference.
func IsReference(data []byte) ([]byte, bool) {
if !bytes.HasPrefix(data, []byte("<reference ")) {
return nil, false
Expand Down
2 changes: 2 additions & 0 deletions render/man/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ func (r *Renderer) RenderNode(w io.Writer, node ast.Node, entering bool) ast.Wal
case *mast.Bibliography:
case *mast.BibliographyItem:
case *mast.DocumentIndex, *mast.IndexLetter, *mast.IndexItem, *mast.IndexSubItem, *mast.IndexLink:
case *mast.ReferenceBlock:
// ignore
case *ast.Footnotes:
r.footnotes(w, node, entering)
case *ast.Text:
Expand Down
4 changes: 4 additions & 0 deletions render/markdown/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,10 @@ func (r *Renderer) RenderNode(w io.Writer, node ast.Node, entering bool) ast.Wal
case *mast.Bibliography:
case *mast.BibliographyItem:
case *mast.DocumentIndex, *mast.IndexLetter, *mast.IndexItem, *mast.IndexSubItem, *mast.IndexLink:
case *mast.ReferenceBlock:
r.out(w, node.Literal)
r.endline(w)
r.newline(w)
case *ast.Footnotes:
// do nothing, we're not outputing a footnote list
case *ast.Text:
Expand Down
3 changes: 3 additions & 0 deletions render/mhtml/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ func (r RenderOptions) RenderHook(w io.Writer, node ast.Node, entering bool) (as
io.WriteString(w, ` <a class="index-return" href="#`+string(node.Destination)+`">`)
io.WriteString(w, IndexReturnLinkContents)
return ast.GoToNext, true
case *mast.ReferenceBlock:
// ignore these for HTML output as this is XML and not used at all.
return ast.GoToNext, true
}
return ast.GoToNext, false
}
Expand Down
6 changes: 5 additions & 1 deletion render/xml/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,10 @@ func (r *Renderer) RenderNode(w io.Writer, node ast.Node, entering bool) ast.Wal
r.bibliographyItem(w, node)
case *mast.DocumentIndex, *mast.IndexLetter, *mast.IndexItem, *mast.IndexSubItem, *mast.IndexLink:
// generated by xml2rfc, do nothing.
case *mast.ReferenceBlock:
r.out(w, node.Literal)
r.cr(w)
r.cr(w)
case *ast.Text:
r.text(w, node)
case *ast.Softbreak:
Expand Down Expand Up @@ -667,7 +671,7 @@ func (r *Renderer) RenderNode(w io.Writer, node ast.Node, entering bool) ast.Wal
case *ast.HTMLSpan:
r.htmlSpan(w, node)
case *ast.HTMLBlock:
// discard; we use these only for <references>.
r.out(w, node.Literal)
case *ast.List:
r.list(w, node, entering)
case *ast.ListItem:
Expand Down
6 changes: 5 additions & 1 deletion render/xml2/renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,10 @@ func (r *Renderer) RenderNode(w io.Writer, node ast.Node, entering bool) ast.Wal
r.bibliographyItem(w, node)
case *mast.DocumentIndex, *mast.IndexLetter, *mast.IndexItem, *mast.IndexSubItem, *mast.IndexLink:
// generated by xml2rfc, do nothing.
case *mast.ReferenceBlock:
r.out(w, node.Literal)
r.cr(w)
r.cr(w)
case *ast.Text:
r.text(w, node)
case *ast.Softbreak:
Expand Down Expand Up @@ -763,7 +767,7 @@ func (r *Renderer) RenderNode(w io.Writer, node ast.Node, entering bool) ast.Wal
case *ast.HTMLSpan:
r.htmlSpan(w, node) // only html comments are allowed.
case *ast.HTMLBlock:
// discard; we use these only for <references>.
r.out(w, node.Literal)
case *ast.List:
r.list(w, node, entering)
case *ast.ListItem:
Expand Down

0 comments on commit 9165eaf

Please sign in to comment.