-
Notifications
You must be signed in to change notification settings - Fork 48
/
renderer.go
780 lines (677 loc) · 18.3 KB
/
renderer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
package xml2
import (
"fmt"
"io"
"log"
"strings"
"github.com/gomarkdown/markdown/ast"
"github.com/gomarkdown/markdown/html"
"github.com/mmarkdown/mmark/mast"
"github.com/mmarkdown/mmark/xml"
)
// Flags control optional behavior of XML2 renderer.
type Flags int
// HTML renderer configuration options.
const (
FlagsNone Flags = 0
XMLFragment Flags = 1 << iota // Don't generate a complete XML document
SkipHTML // Skip preformatted HTML blocks - skips comments
SkipImages // Skip embedded images, set to true for XML2
CommonFlags Flags = SkipImages
)
// RendererOptions is a collection of supplementary parameters tweaking
// the behavior of various parts of XML2 renderer.
type RendererOptions struct {
// Callouts are supported and detected by setting this option to the callout prefix.
Callout string
Flags Flags // Flags allow customizing this renderer's behavior
// if set, called at the start of RenderNode(). Allows replacing
// rendering of some nodes
RenderNodeHook html.RenderNodeFunc
// Comments is a list of comments the renderer should detect when
// parsing code blocks and detecting callouts.
Comments [][]byte
}
// Renderer implements Renderer interface for IETF XMLv2 output. See RFC 7941.
type Renderer struct {
opts RendererOptions
documentMatter ast.DocumentMatters // keep track of front/main/back matter
section *ast.Heading // current open section
title bool // did we output a title block
filter mast.FilterFunc // filter for attributes.
// Track heading IDs to prevent ID collision in a single generation.
headingIDs map[string]int
}
var filterFunc mast.FilterFunc = func(s string) bool {
switch s {
case "id": // will translate to anchor so OK.
return true
case "class": // there are no classes
return false
case "empty": // newer attributes from RFC 7991
return false
}
// l33t data- HTML5 attributes
if strings.HasPrefix(s, "data-") {
return false
}
return true
}
// NewRenderer creates and configures an Renderer object, which satisfies the Renderer interface.
func NewRenderer(opts RendererOptions) *Renderer {
html.IDTag = "anchor"
return &Renderer{opts: opts, headingIDs: make(map[string]int), filter: filterFunc}
}
func (r *Renderer) text(w io.Writer, text *ast.Text) {
if _, parentIsLink := text.Parent.(*ast.Link); parentIsLink {
r.out(w, text.Literal)
return
}
if heading, parentIsHeading := text.Parent.(*ast.Heading); parentIsHeading {
if heading.IsSpecial && xml.IsAbstract(heading.Literal) {
return
}
html.EscapeHTML(w, text.Literal)
r.outs(w, `">`)
return
}
html.EscapeHTML(w, text.Literal)
if _, parentIsCaption := text.Parent.(*ast.Caption); parentIsCaption {
r.outs(w, `">`)
}
}
func (r *Renderer) hardBreak(w io.Writer, node *ast.Hardbreak) {
r.outs(w, "<vspace />")
r.cr(w)
}
func (r *Renderer) strong(w io.Writer, node *ast.Strong, entering bool) {
// *iff* we have a text node as a child *and* that text is 2119, we output bcp14 tags, otherwise just string.
text := ast.GetFirstChild(node)
if t, ok := text.(*ast.Text); ok {
if xml.Is2119(t.Literal) {
// out as-is.
r.outOneOf(w, entering, "", "")
return
}
}
r.outOneOf(w, entering, `<spanx style="strong">`, "</spanx>")
}
func (r *Renderer) matter(w io.Writer, node *ast.DocumentMatter) {
r.sectionClose(w, nil)
switch node.Matter {
case ast.DocumentMatterFront:
r.cr(w)
r.outs(w, "<front>")
r.cr(w)
case ast.DocumentMatterMain:
r.cr(w)
r.outs(w, "</front>")
r.cr(w)
r.cr(w)
r.outs(w, "<middle>")
r.cr(w)
case ast.DocumentMatterBack:
r.cr(w)
r.outs(w, "</middle>")
r.cr(w)
r.cr(w)
r.outs(w, "<back>")
r.cr(w)
}
r.documentMatter = node.Matter
}
func (r *Renderer) headingEnter(w io.Writer, heading *ast.Heading) {
r.cr(w)
tag := "<section"
if heading.IsSpecial {
tag = "<note"
if xml.IsAbstract(heading.Literal) {
tag = "<abstract>"
r.outs(w, tag)
return
}
}
mast.AttributeInit(heading)
if mast.Attribute(heading, "id") == nil && heading.HeadingID != "" {
id := r.ensureUniqueHeadingID(heading.HeadingID)
mast.SetAttribute(heading, "id", []byte(id))
}
// If we want to support block level attributes here, it will clash with the
// title= attribute that is outed in text() - and thus later.
r.outs(w, tag)
r.outAttr(w, html.BlockAttrs(heading))
r.outs(w, ` title="`)
}
func (r *Renderer) headingExit(w io.Writer, heading *ast.Heading) {
r.cr(w)
}
func (r *Renderer) heading(w io.Writer, node *ast.Heading, entering bool) {
if !entering {
r.headingExit(w, node)
return
}
r.sectionClose(w, node)
r.headingEnter(w, node)
}
func (r *Renderer) citation(w io.Writer, node *ast.Citation, entering bool) {
if !entering {
return
}
for i, c := range node.Destination {
if node.Type[i] == ast.CitationTypeSuppressed {
continue
}
r.outTag(w, "<xref", []string{fmt.Sprintf(`target="%s"`, c)})
r.outs(w, "</xref>")
}
}
func (r *Renderer) paragraphEnter(w io.Writer, para *ast.Paragraph) {
if p, ok := para.Parent.(*ast.ListItem); ok {
// Skip outputting <t> in lists.
// Fake multiple paragraphs by inserting a hard break.
if len(p.GetChildren()) > 1 {
first := ast.GetFirstChild(para.Parent)
if first != para {
r.hardBreak(w, &ast.Hardbreak{})
}
}
return
}
tag := tagWithAttributes("<t", html.BlockAttrs(para))
r.outs(w, tag)
}
func (r *Renderer) paragraphExit(w io.Writer, para *ast.Paragraph) {
if _, ok := para.Parent.(*ast.ListItem); ok {
// Skip outputting </t> in lists.
return
}
r.outs(w, "</t>")
r.cr(w)
}
func (r *Renderer) paragraph(w io.Writer, para *ast.Paragraph, entering bool) {
if entering {
r.paragraphEnter(w, para)
} else {
r.paragraphExit(w, para)
}
}
func (r *Renderer) listEnter(w io.Writer, nodeData *ast.List) {
if nodeData.IsFootnotesList {
return
}
r.cr(w)
openTag := "<list"
// if there is a block level attribute with style, we shouldn't use ours.
if mast.Attribute(nodeData, "style") == nil {
mast.AttributeInit(nodeData)
mast.SetAttribute(nodeData, "style", []byte("symbols"))
if nodeData.ListFlags&ast.ListTypeOrdered != 0 {
mast.SetAttribute(nodeData, "style", []byte("numbers"))
if nodeData.Start > 0 {
log.Printf("Attribute \"start\" not supported for list style=\"numbers\"")
}
}
if nodeData.ListFlags&ast.ListTypeDefinition != 0 {
mast.SetAttribute(nodeData, "style", []byte("hanging"))
}
}
r.outTag(w, openTag, html.BlockAttrs(nodeData))
r.cr(w)
}
func (r *Renderer) listExit(w io.Writer, list *ast.List) {
if list.IsFootnotesList {
return
}
closeTag := "</list>"
if list.ListFlags&ast.ListTypeOrdered != 0 {
//closeTag = "</ol>"
}
if list.ListFlags&ast.ListTypeDefinition != 0 {
//closeTag = "</dl>"
}
r.outs(w, closeTag)
parent := list.Parent
switch parent.(type) {
case *ast.ListItem:
if ast.GetNextNode(list) != nil {
r.cr(w)
}
case *ast.Document, *ast.BlockQuote, *ast.Aside:
r.cr(w)
}
}
func (r *Renderer) list(w io.Writer, list *ast.List, entering bool) {
// need to be wrapped in a paragraph, except when we're already in a list.
_, parentIsList := list.Parent.(*ast.ListItem)
if entering {
if !parentIsList {
r.paragraphEnter(w, &ast.Paragraph{})
}
r.listEnter(w, list)
} else {
r.listExit(w, list)
if !parentIsList {
r.paragraphExit(w, &ast.Paragraph{})
}
}
}
func (r *Renderer) listItemEnter(w io.Writer, listItem *ast.ListItem) {
if listItem.RefLink != nil { // footnotes
return
}
openTag := "<t>"
if listItem.ListFlags&ast.ListTypeDefinition != 0 {
openTag = "<vspace />"
}
if listItem.ListFlags&ast.ListTypeTerm != 0 {
openTag = "<t hangText=\""
}
r.outs(w, openTag)
}
func (r *Renderer) listItemExit(w io.Writer, listItem *ast.ListItem) {
if listItem.RefLink != nil {
return
}
closeTag := "</t>"
if listItem.ListFlags&ast.ListTypeTerm != 0 {
closeTag = `">`
}
r.outs(w, closeTag)
r.cr(w)
}
func (r *Renderer) listItem(w io.Writer, listItem *ast.ListItem, entering bool) {
if entering {
r.listItemEnter(w, listItem)
} else {
r.listItemExit(w, listItem)
}
}
func (r *Renderer) codeBlock(w io.Writer, codeBlock *ast.CodeBlock) {
mast.DeleteAttribute(codeBlock, "id")
mast.AttributeInit(codeBlock)
appendLanguageAttr(codeBlock, codeBlock.Info)
r.cr(w)
_, inFigure := codeBlock.Parent.(*ast.CaptionFigure)
if inFigure {
r.outTag(w, "<artwork", html.BlockAttrs(codeBlock))
} else {
r.outTag(w, "<figure><artwork", html.BlockAttrs(codeBlock))
}
if r.opts.Comments != nil {
xml.EscapeHTMLCallouts(w, codeBlock.Literal, r.opts.Comments)
} else {
html.EscapeHTML(w, codeBlock.Literal)
}
if inFigure {
r.outs(w, "</artwork>")
} else {
r.outs(w, "</artwork></figure>")
}
r.cr(w)
}
func (r *Renderer) tableCell(w io.Writer, tableCell *ast.TableCell, entering bool) {
if !entering {
r.outOneOf(w, tableCell.IsHeader, "</ttcol>", "</c>")
r.cr(w)
return
}
// entering
mast.AttributeInit(tableCell)
openTag := "<c"
if tableCell.IsHeader {
openTag = "<ttcol"
}
align := tableCell.Align.String()
if align != "" {
mast.SetAttribute(tableCell, "align", []byte(align))
}
if ast.GetPrevNode(tableCell) == nil {
r.cr(w)
}
r.outTag(w, openTag, html.BlockAttrs(tableCell))
}
func (r *Renderer) tableBody(w io.Writer, node *ast.TableBody, entering bool) {
r.outOneOfCr(w, entering, "", "")
}
func (r *Renderer) htmlSpan(w io.Writer, span *ast.HTMLSpan) {
if r.opts.Flags&SkipHTML == 0 {
html.EscapeHTML(w, span.Literal)
}
}
func (r *Renderer) callout(w io.Writer, callout *ast.Callout) {
r.outs(w, `<spanx style="emph">`)
r.out(w, callout.ID)
r.outs(w, "</spanx>")
}
func (r *Renderer) crossReference(w io.Writer, cr *ast.CrossReference, entering bool) {
if isHangText(cr) {
if entering {
w.Write(cr.Destination)
}
return
}
if entering {
r.outTag(w, "<xref", []string{"target=\"" + string(cr.Destination) + "\""})
return
}
r.outs(w, "</xref>")
}
func (r *Renderer) index(w io.Writer, index *ast.Index) {
r.outs(w, "<iref")
r.outs(w, " item=\"")
html.EscapeHTML(w, index.Item)
r.outs(w, "\"")
if index.Primary {
r.outs(w, ` primary="true"`)
}
if len(index.Subitem) != 0 {
r.outs(w, " subitem=\"")
html.EscapeHTML(w, index.Subitem)
r.outs(w, "\"")
}
r.outs(w, "/>")
}
func (r *Renderer) link(w io.Writer, link *ast.Link, entering bool) {
if link.Footnote != nil {
log.Printf("Skipping footnote")
return
}
if !entering {
r.outs(w, `</eref>`)
return
}
if isHangText(link) {
w.Write(link.Destination)
return
}
r.outs(w, "<eref")
r.outs(w, " target=\"")
html.EscapeHTML(w, link.Destination)
r.outs(w, `">`)
}
func (r *Renderer) image(w io.Writer, node *ast.Image, entering bool) {
// Discard images for now
return
if entering {
r.imageEnter(w, node)
} else {
r.imageExit(w, node)
}
}
func (r *Renderer) imageEnter(w io.Writer, image *ast.Image) {
dest := image.Destination
r.outs(w, `<img src="`)
html.EscapeHTML(w, dest)
r.outs(w, `" alt="`)
}
func (r *Renderer) imageExit(w io.Writer, image *ast.Image) {
if image.Title != nil {
r.outs(w, `" name="`)
html.EscapeHTML(w, image.Title)
}
r.outs(w, `" />`)
}
func (r *Renderer) code(w io.Writer, node *ast.Code) {
if isHangText(node) {
html.EscapeHTML(w, node.Literal)
return
}
r.outs(w, `<spanx style="verb">`)
html.EscapeHTML(w, node.Literal)
r.outs(w, "</spanx>")
}
func (r *Renderer) mathBlock(w io.Writer, mathBlock *ast.MathBlock) {
r.outs(w, `<figure><artwork type="math">`+"\n")
if r.opts.Comments != nil {
xml.EscapeHTMLCallouts(w, mathBlock.Literal, r.opts.Comments)
} else {
html.EscapeHTML(w, mathBlock.Literal)
}
r.outs(w, `</artwork></figure>`)
r.cr(w)
}
func (r *Renderer) captionFigure(w io.Writer, captionFigure *ast.CaptionFigure, entering bool) {
for _, child := range captionFigure.GetChildren() {
if _, ok := child.(*ast.Table); ok {
return
}
if _, ok := child.(*ast.BlockQuote); ok {
return
}
}
if !entering {
r.outs(w, "</figure>")
return
}
r.outs(w, "<figure")
r.outAttr(w, html.BlockAttrs(captionFigure))
r.outs(w, ` title="`)
// Now render the caption and then *remove* it from the tree.
for _, child := range captionFigure.GetChildren() {
if caption, ok := child.(*ast.Caption); ok {
ast.WalkFunc(caption, func(node ast.Node, entering bool) ast.WalkStatus {
return r.RenderNode(w, node, entering)
})
ast.RemoveFromTree(caption)
}
}
}
func (r *Renderer) table(w io.Writer, tab *ast.Table, entering bool) {
if !entering {
r.outs(w, "</texttable>")
return
}
r.outs(w, "<texttable")
r.outAttr(w, html.BlockAttrs(tab))
// Now render the caption if our parent is a ast.CaptionFigure
// and then *remove* it from the tree.
captionFigure, ok := tab.Parent.(*ast.CaptionFigure)
if !ok {
r.outs(w, `>`)
return
}
r.outs(w, ` title="`)
for _, child := range captionFigure.GetChildren() {
if caption, ok := child.(*ast.Caption); ok {
ast.WalkFunc(caption, func(node ast.Node, entering bool) ast.WalkStatus {
return r.RenderNode(w, node, entering)
})
ast.RemoveFromTree(caption)
break
}
}
}
func (r *Renderer) blockQuote(w io.Writer, block *ast.BlockQuote, entering bool) {
if !entering {
return
}
// Fake a list. TODO(miek): list in list checks, see? Make fake parent??
list := &ast.List{}
list.Attribute = block.Attribute
if list.Attribute == nil {
list.Attribute = &ast.Attribute{Attrs: make(map[string][]byte)}
}
list.Attribute.Attrs["style"] = []byte("empty")
listItem := &ast.ListItem{}
mast.MoveChildren(listItem, block)
ast.AppendChild(list, listItem)
if captionFigure, ok := block.Parent.(*ast.CaptionFigure); ok {
for _, child := range captionFigure.GetChildren() {
if caption, ok := child.(*ast.Caption); ok {
listItem := &ast.ListItem{}
mast.MoveChildren(listItem, caption)
ast.AppendChild(list, listItem)
ast.RemoveFromTree(caption)
}
}
}
ast.WalkFunc(list, func(node ast.Node, entering bool) ast.WalkStatus {
return r.RenderNode(w, node, entering)
})
}
// RenderNode renders a markdown node to XML.
func (r *Renderer) RenderNode(w io.Writer, node ast.Node, entering bool) ast.WalkStatus {
mast.AttributeFilter(node, r.filter)
if r.opts.RenderNodeHook != nil {
status, didHandle := r.opts.RenderNodeHook(w, node, entering)
if didHandle {
return status
}
}
switch node := node.(type) {
case *ast.Document:
// do nothing
case *mast.Title:
r.titleBlock(w, node)
r.title = true
case *mast.Bibliography:
r.bibliography(w, node, entering)
case *mast.BibliographyItem:
r.bibliographyItem(w, node)
case *mast.DocumentIndex, *mast.IndexLetter, *mast.IndexItem, *mast.IndexSubItem, *mast.IndexLink:
// generated by xml2rfc, do nothing.
case *ast.Text:
r.text(w, node)
case *ast.Softbreak:
r.cr(w)
case *ast.Hardbreak:
r.hardBreak(w, node)
case *ast.Callout:
r.callout(w, node)
case *ast.Emph:
if isHangText(node) {
if entering {
html.EscapeHTML(w, node.Literal)
}
} else {
r.outOneOf(w, entering, `<spanx style="emph">`, "</spanx>")
}
case *ast.Strong:
r.strong(w, node, entering)
case *ast.Del:
// ala strikethrough, just keep the tildes
r.outOneOf(w, entering, "~", "~")
case *ast.Citation:
r.citation(w, node, entering)
case *ast.DocumentMatter:
if entering {
r.matter(w, node)
}
case *ast.Heading:
r.heading(w, node, entering)
case *ast.Paragraph:
r.paragraph(w, node, entering)
case *ast.HTMLSpan:
r.htmlSpan(w, node) // only html comments are allowed.
case *ast.HTMLBlock:
// discard; we use these only for <references>.
case *ast.List:
r.list(w, node, entering)
case *ast.ListItem:
r.listItem(w, node, entering)
case *ast.CodeBlock:
r.codeBlock(w, node)
case *ast.Caption:
// no tags because we are used in attributes, i.e. title=
// See comment in xml/renderer.go. The same is true here, *but*, because we don't
// output any tags, the problem does not show up. As a matter of consistency we apply
// the same (dumb) precaution.
if len(node.GetChildren()) > 0 {
r.outOneOf(w, entering, "", "")
}
case *ast.CaptionFigure:
r.captionFigure(w, node, entering)
case *ast.Table:
r.table(w, node, entering)
case *ast.TableCell:
r.tableCell(w, node, entering)
case *ast.TableHeader:
r.outOneOf(w, entering, "", "")
case *ast.TableBody:
r.tableBody(w, node, entering)
case *ast.TableRow:
r.outOneOf(w, entering, "", "")
case *ast.TableFooter:
r.outOneOf(w, entering, "", "")
case *ast.BlockQuote:
r.blockQuote(w, node, entering)
case *ast.Aside:
// ignore and text render the child text as-is.
case *ast.CrossReference:
r.crossReference(w, node, entering)
case *ast.Index:
if entering {
r.index(w, node)
}
case *ast.Link:
r.link(w, node, entering)
case *ast.Math:
r.outOneOf(w, true, `<spanx style="verb">`, "</spanx>")
html.EscapeHTML(w, node.Literal)
r.outOneOf(w, false, `<spanx style="verb">`, "</spanx>")
case *ast.Image:
if r.opts.Flags&SkipImages != 0 {
return ast.SkipChildren
}
r.image(w, node, entering)
case *ast.Code:
r.code(w, node)
case *ast.MathBlock:
r.mathBlock(w, node)
case *ast.Subscript:
r.outOneOf(w, true, "_(", ")")
if entering {
html.Escape(w, node.Literal)
}
r.outOneOf(w, false, "_(", ")")
case *ast.Superscript:
r.outOneOf(w, true, "^(", ")")
if entering {
html.Escape(w, node.Literal)
}
r.outOneOf(w, false, "^(", ")")
default:
panic(fmt.Sprintf("Unknown node %T", node))
}
return ast.GoToNext
}
// RenderHeader writes HTML document preamble and TOC if requested.
func (r *Renderer) RenderHeader(w io.Writer, ast ast.Node) {
if r.opts.Flags&XMLFragment != 0 {
return
}
r.writeDocumentHeader(w)
}
// RenderFooter writes HTML document footer.
func (r *Renderer) RenderFooter(w io.Writer, _ ast.Node) {
r.sectionClose(w, nil)
switch r.documentMatter {
case ast.DocumentMatterFront:
r.outs(w, "\n</front>\n")
case ast.DocumentMatterMain:
r.outs(w, "\n</middle>\n")
case ast.DocumentMatterBack:
r.outs(w, "\n</back>\n")
}
if r.title {
io.WriteString(w, "\n</rfc>")
}
}
func (r *Renderer) writeDocumentHeader(w io.Writer) {
if r.opts.Flags&XMLFragment != 0 {
return
}
r.outs(w, `<?xml version="1.0" encoding="utf-8"?>`)
r.cr(w)
r.outs(w, `<!-- name="GENERATOR" content="github.com/mmarkdown/mmark markdown processor for Go" -->`)
r.cr(w)
r.outs(w, `<!DOCTYPE rfc SYSTEM 'rfc2629.dtd' []>`)
r.cr(w)
}
func tagWithAttributes(name string, attrs []string) string {
s := name
if len(attrs) > 0 {
s += " " + strings.Join(attrs, " ")
}
return s + ">"
}