> with the callout HTML, i.e. by calling r.callout() with a newly created
+// ast.Callout node.
+func (r *Renderer) EscapeHTMLCallouts(w io.Writer, d []byte) {
+ ld := len(d)
+Parse:
+ for i := 0; i < ld; i++ {
+ for _, comment := range r.opts.Comments {
+ if !bytes.HasPrefix(d[i:], comment) {
+ break
+ }
+
+ lc := len(comment)
+ if i+lc < ld {
+ if id, consumed := parser.IsCallout(d[i+lc:]); consumed > 0 {
+ // We have seen a callout
+ callout := &ast.Callout{ID: id}
+ r.Callout(w, callout)
+ i += consumed + lc - 1
+ continue Parse
+ }
+ }
+ }
+
+ escSeq := Escaper[d[i]]
+ if escSeq != nil {
+ w.Write(escSeq)
+ } else {
+ w.Write([]byte{d[i]})
+ }
+ }
+}
+
+// CodeBlock writes ast.CodeBlock node
+func (r *Renderer) CodeBlock(w io.Writer, codeBlock *ast.CodeBlock) {
var attrs []string
// TODO(miek): this can add multiple class= attribute, they should be coalesced into one.
// This is probably true for some other elements as well
attrs = appendLanguageAttr(attrs, codeBlock.Info)
attrs = append(attrs, BlockAttrs(codeBlock)...)
- r.cr(w)
+ r.CR(w)
- r.outs(w, "")
- code := tagWithAttributes("")
+ code := TagWithAttributes("")
- r.outs(w, "")
+ r.Outs(w, "")
+ r.Outs(w, "")
if !isListItem(codeBlock.Parent) {
- r.cr(w)
+ r.CR(w)
}
}
-func (r *Renderer) caption(w io.Writer, caption *ast.Caption, entering bool) {
+// Caption writes ast.Caption node
+func (r *Renderer) Caption(w io.Writer, caption *ast.Caption, entering bool) {
if entering {
- r.outs(w, "")
+ r.Outs(w, "")
return
}
- r.outs(w, "")
+ r.Outs(w, "")
}
-func (r *Renderer) captionFigure(w io.Writer, figure *ast.CaptionFigure, entering bool) {
+// CaptionFigure writes ast.CaptionFigure node
+func (r *Renderer) CaptionFigure(w io.Writer, figure *ast.CaptionFigure, entering bool) {
// TODO(miek): copy more generic ways of mmark over to here.
fig := ""
}
- r.outOneOf(w, entering, fig, "\n\n")
+ r.OutOneOf(w, entering, fig, "\n\n")
}
-func (r *Renderer) tableCell(w io.Writer, tableCell *ast.TableCell, entering bool) {
+// TableCell writes ast.TableCell node
+func (r *Renderer) TableCell(w io.Writer, tableCell *ast.TableCell, entering bool) {
if !entering {
- r.outOneOf(w, tableCell.IsHeader, "", "")
- r.cr(w)
+ r.OutOneOf(w, tableCell.IsHeader, "", "")
+ r.CR(w)
return
}
@@ -847,45 +957,51 @@ func (r *Renderer) tableCell(w io.Writer, tableCell *ast.TableCell, entering boo
if align != "" {
attrs = append(attrs, fmt.Sprintf(`align="%s"`, align))
}
+ if colspan := tableCell.ColSpan; colspan > 0 {
+ attrs = append(attrs, fmt.Sprintf(`colspan="%d"`, colspan))
+ }
if ast.GetPrevNode(tableCell) == nil {
- r.cr(w)
+ r.CR(w)
}
r.outTag(w, openTag, attrs)
}
-func (r *Renderer) tableBody(w io.Writer, node *ast.TableBody, entering bool) {
+// TableBody writes ast.TableBody node
+func (r *Renderer) TableBody(w io.Writer, node *ast.TableBody, entering bool) {
if entering {
- r.cr(w)
- r.outs(w, "")
+ r.CR(w)
+ r.Outs(w, "")
// XXX: this is to adhere to a rather silly test. Should fix test.
if ast.GetFirstChild(node) == nil {
- r.cr(w)
+ r.CR(w)
}
} else {
- r.outs(w, "")
- r.cr(w)
+ r.Outs(w, "")
+ r.CR(w)
}
}
-func (r *Renderer) matter(w io.Writer, node *ast.DocumentMatter, entering bool) {
+// DocumentMatter writes ast.DocumentMatter
+func (r *Renderer) DocumentMatter(w io.Writer, node *ast.DocumentMatter, entering bool) {
if !entering {
return
}
if r.documentMatter != ast.DocumentMatterNone {
- r.outs(w, "\n")
+ r.Outs(w, "\n")
}
switch node.Matter {
case ast.DocumentMatterFront:
- r.outs(w, ``)
+ r.Outs(w, ``)
case ast.DocumentMatterMain:
- r.outs(w, ``)
+ r.Outs(w, ``)
case ast.DocumentMatterBack:
- r.outs(w, ``)
+ r.Outs(w, ``)
}
r.documentMatter = node.Matter
}
-func (r *Renderer) citation(w io.Writer, node *ast.Citation) {
+// Citation writes ast.Citation node
+func (r *Renderer) Citation(w io.Writer, node *ast.Citation) {
for i, c := range node.Destination {
attr := []string{`class="none"`}
switch node.Type[i] {
@@ -897,23 +1013,25 @@ func (r *Renderer) citation(w io.Writer, node *ast.Citation) {
attr[0] = `class="suppressed"`
}
r.outTag(w, "`+r.opts.CitationFormatString+``, c, c))
- r.outs(w, "")
+ r.Outs(w, fmt.Sprintf(``+r.opts.CitationFormatString+``, c, c))
+ r.Outs(w, "")
}
}
-func (r *Renderer) callout(w io.Writer, node *ast.Callout) {
+// Callout writes ast.Callout node
+func (r *Renderer) Callout(w io.Writer, node *ast.Callout) {
attr := []string{`class="callout"`}
r.outTag(w, "")
+ r.Out(w, node.ID)
+ r.Outs(w, "")
}
-func (r *Renderer) index(w io.Writer, node *ast.Index) {
+// Index writes ast.Index node
+func (r *Renderer) Index(w io.Writer, node *ast.Index) {
// there is no in-text representation.
attr := []string{`class="index"`, fmt.Sprintf(`id="%s"`, node.ID)}
r.outTag(w, "")
+ r.Outs(w, "")
}
// RenderNode renders a markdown node to HTML
@@ -926,102 +1044,102 @@ func (r *Renderer) RenderNode(w io.Writer, node ast.Node, entering bool) ast.Wal
}
switch node := node.(type) {
case *ast.Text:
- r.text(w, node)
+ r.Text(w, node)
case *ast.Softbreak:
- r.cr(w)
+ r.CR(w)
// TODO: make it configurable via out(renderer.softbreak)
case *ast.Hardbreak:
- r.hardBreak(w, node)
+ r.HardBreak(w, node)
case *ast.NonBlockingSpace:
- r.nonBlockingSpace(w, node)
+ r.NonBlockingSpace(w, node)
case *ast.Emph:
- r.outOneOf(w, entering, "", "")
+ r.OutOneOf(w, entering, "", "")
case *ast.Strong:
- r.outOneOf(w, entering, "", "")
+ r.OutOneOf(w, entering, "", "")
case *ast.Del:
- r.outOneOf(w, entering, "", "")
+ r.OutOneOf(w, entering, "", "")
case *ast.BlockQuote:
- tag := tagWithAttributes("")
+ tag := TagWithAttributes("")
case *ast.Aside:
- tag := tagWithAttributes("