-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
1238 lines (1039 loc) · 26.7 KB
/
types.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
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Package pandoc implements the [Pandoc] AST as defined in [Pandoc Types].
//
// [Pandoc]: https://pandoc.org/
// [Pandoc Types]: https://hackage.haskell.org/package/pandoc-types
package pandoc
import (
"strconv"
"strings"
)
// Implemented Pandoc protocol version.
const Version = "1.23.1"
var _Version = func() []int {
c := strings.Split(Version, ".")
v := make([]int, len(c))
for i, s := range c {
n, _ := strconv.ParseInt(s, 10, 64)
v[i] = int(n)
}
return v
}()
// A convenience function to check if an element is of a particular type.
//
// Example:
//
// if pandoc.Is[*pandoc.Str](elt) {
// ...
//
// if pandoc.Is[pandoc.Inline](elt) {
// ...
func Is[P any, S Element](elt S) bool {
_, ok := any(elt).(*P)
return ok
}
// Returs a shallow copy of an element. Intended for use in Filter.
func Clone[P Element](elt P) P {
return elt.clone().(P)
}
// Pandoc AST element interface
type Element interface {
writable
element()
clone() Element
}
type inlinesContainer interface {
inlines() []Inline
}
type blocksContainer interface {
blocks() []Block
}
// Pandoc AST element that can be referred to.
type Linkable interface {
Element
Ident() string
SetIdent(string)
}
// Pandoc AST object tag
type Tag string
func (t Tag) Tag() Tag { return t }
func (t Tag) String() string { return string(t) }
// Pandoc AST object with tag
type Tagged interface {
Tag() Tag
}
// Pandoc AST inline element
type Inline interface {
Element
Tagged
inline()
}
// Pandoc AST inline's whitespaces (Space, SoftBreak, LineBreak)
type WhiteSpace interface {
Inline
space()
}
// Pandoc AST block element
type Block interface {
Element
Tagged
block()
}
// Pandoc document metadata value
type MetaValue interface {
Element
Tagged
meta()
}
// Pandoc document
type Pandoc struct {
Meta Meta
Blocks []Block
}
func (p *Pandoc) element() {}
func (p *Pandoc) clone() Element {
c := *p
return &c
}
func (p *Pandoc) blocks() []Block { return p.Blocks }
func (p *Pandoc) Apply(transformers ...func(*Pandoc) (*Pandoc, error)) (*Pandoc, error) {
return apply(p, transformers...)
}
// Pandoc's MetaMap entry.
type MetaMapEntry struct {
Key string
Value MetaValue
}
func (m MetaMapEntry) element() {}
func (m MetaMapEntry) clone() Element { return m }
// Pandoc's Meta
type Meta []MetaMapEntry
// Returns a value of the given key or nil if the key is not present.
func (m *Meta) Get(key string) MetaValue {
for _, e := range *m {
if e.Key == key {
return e.Value
}
}
return nil
}
// Sets a value for the given key. If the value is nil, the key is removed.
func (m *Meta) Set(key string, value MetaValue) {
for i, e := range *m {
if e.Key == key {
if value == nil {
*m = append((*m)[:i], (*m)[i+1:]...)
} else {
(*m)[i].Value = value
}
return
}
}
if value != nil {
*m = append(*m, MetaMapEntry{key, value})
}
}
// Sets a boolean value for the given key.
func (m *Meta) SetBool(key string, value bool) {
m.Set(key, MetaBool(value))
}
// Sets a list of blocks for the given key.
func (m *Meta) SetBlocks(key string, value ...Block) {
m.Set(key, &MetaBlocks{value})
}
// Sets a list of inlines for the given key.
func (m *Meta) SetInlines(key string, value ...Inline) {
m.Set(key, &MetaInlines{value})
}
// Sets a string value for the given key.
func (m *Meta) SetString(key string, value string) {
m.Set(key, MetaString(value))
}
// Pandoc document metadata map
type MetaMap struct {
Entries Meta
}
const MetaMapTag = Tag("MetaMap")
func (m *MetaMap) Tag() Tag { return MetaMapTag }
func (m *MetaMap) clone() Element {
c := *m
return &c
}
func (m *MetaMap) element() {}
func (m *MetaMap) meta() {}
// Returns a value of the given key or nil if the key is not present.
func (m *MetaMap) Get(key string) MetaValue {
return m.Entries.Get(key)
}
// Sets a value for the given key. If the value is nil, the key is removed.
func (m *MetaMap) Set(key string, value MetaValue) {
m.Entries.Set(key, value)
}
// Pandoc document metadata list
type MetaList struct {
Entries []MetaValue
}
const MetaListTag = Tag("MetaList")
func (m *MetaList) Tag() Tag { return MetaListTag }
func (m *MetaList) clone() Element {
c := *m
return &c
}
func (m *MetaList) element() {}
func (m *MetaList) meta() {}
// Pandoc document metadata inlines block
type MetaInlines struct {
Inlines []Inline
}
const MetaInlinesTag = Tag("MetaInlines")
func (m *MetaInlines) Tag() Tag { return MetaInlinesTag }
func (m *MetaInlines) inlines() []Inline { return m.Inlines }
func (m *MetaInlines) clone() Element {
c := *m
return &c
}
func (m *MetaInlines) element() {}
func (m *MetaInlines) meta() {}
func (m *MetaInlines) Text() string {
var sb strings.Builder
walkList(m.Inlines, func(i Inline) ([]Inline, error) {
switch i := i.(type) {
case *Str:
sb.WriteString(i.Text)
case *Space:
sb.WriteByte(' ')
case *SoftBreak:
sb.WriteByte('\n')
case *LineBreak:
sb.WriteByte('\n')
case *Note:
return nil, Skip
}
return nil, Continue
})
return sb.String()
}
// Pandoc document metadata blocks block
type MetaBlocks struct {
Blocks []Block
}
const MetaBlocksTag = Tag("MetaBlocks")
func (m *MetaBlocks) Tag() Tag { return MetaBlocksTag }
func (m *MetaBlocks) blocks() []Block { return m.Blocks }
func (m *MetaBlocks) clone() Element {
c := *m
return &c
}
func (m *MetaBlocks) element() {}
func (m *MetaBlocks) meta() {}
// Pandoc document metadata boolean
type MetaBool bool
const MetaBoolTag = Tag("MetaBool")
func (b MetaBool) Tag() Tag { return MetaBoolTag }
func (b MetaBool) clone() Element { return b }
func (b MetaBool) element() {}
func (b MetaBool) meta() {}
// Pandoc document metadata string
type MetaString string
const MetaStringTag = Tag("MetaString")
func (MetaString) Tag() Tag { return MetaStringTag }
func (s MetaString) clone() Element { return s }
func (s MetaString) String() string { return string(s) }
func (MetaString) element() {}
func (MetaString) meta() {}
// Pandoc elements attribute' key-value pair.
type KV struct {
Key string
Value string
}
// Pandoc elements attribute.
type Attr struct {
Id string // Element ID
Classes []string // Element classes
KVs []KV // Element attributes' key-value pairs
}
// Returns the element's ID.
func (a *Attr) Ident() string {
return a.Id
}
// Sets the element's ID in-place. This method is intended to quickly
// modify an element's ID in Query or QueryE without cloning it.
func (a *Attr) SetIdent(id string) {
a.Id = id
}
// Returns a copy of attributes with the given ID.
func (a Attr) WithIdent(id string) Attr {
a.Id = id
return a
}
// Returns true if attribute has the given class.
func (a *Attr) HasClass(c string) bool {
for _, cl := range a.Classes {
if cl == c {
return true
}
}
return false
}
// Returns true if attribute has one of the given classes.
func (a *Attr) HasOneOfClasses(c ...string) bool {
for _, cl := range a.Classes {
for _, c := range c {
if cl == c {
return true
}
}
}
return false
}
// Returns a value of the given key or false if the key is not present.
func (a *Attr) Get(key string) (string, bool) {
for _, kv := range a.KVs {
if kv.Key == key {
return kv.Value, true
}
}
return "", false
}
// Returns a copy of attributes with the given class.
func (a Attr) WithClass(c string) Attr {
if !a.HasClass(c) {
a.Classes = append(a.Classes, c)
}
return a
}
// Returns a copy of attributes without the given class.
func (a Attr) WithoutClass(c string) Attr {
for i, cl := range a.Classes {
if cl == c {
a.Classes = append(a.Classes[:i], a.Classes[i+1:]...)
return a
}
}
return a
}
// Returns a copy of attributes with the given key-value pair.
func (a Attr) WithKV(key, value string) Attr {
for i, kv := range a.KVs {
if kv.Key == key {
a.KVs[i].Value = value
return a
}
}
a.KVs = append(a.KVs, KV{key, value})
return a
}
// Returns a copy of attributes without the given key.
func (a Attr) WithoutKey(key string) Attr {
for i, kv := range a.KVs {
if kv.Key == key {
a.KVs = append(a.KVs[:i], a.KVs[i+1:]...)
return a
}
}
return a
}
// Returns a copy of attributes with the given key-value pairs.
func (a Attr) WithKVs(pairs ...string) Attr {
kvs := append(make([]KV, 0, len(a.KVs)+len(pairs)/2), a.KVs...)
next:
for i := 0; i+1 < len(pairs); i += 2 {
for j := range kvs {
if kvs[j].Key == pairs[i] {
kvs[j].Value = pairs[i+1]
continue next
}
}
kvs = append(kvs, KV{pairs[i], pairs[i+1]})
}
a.KVs = kvs
return a
}
// Returns a copy of attributes without the given keys.
func (a Attr) WithoutKeys(keys ...string) Attr {
kvs := append(make([]KV, 0, len(a.KVs)), a.KVs...)
for i := range keys {
for j := range kvs {
if a.KVs[j].Key == keys[i] {
copy(kvs[j:], kvs[j+1:])
kvs = kvs[:len(kvs)-1]
break
}
}
}
a.KVs = kvs
return a
}
// Text (string)
type Str struct {
Text string
}
const StrTag = Tag("Str")
func (s *Str) Tag() Tag { return StrTag }
func (s *Str) clone() Element {
c := *s
return &c
}
func (s *Str) inline() {}
func (s *Str) element() {}
// Emphasized text (list of inlines)
type Emph struct {
Inlines []Inline
}
const EmphTag = Tag("Emph")
func (e *Emph) Tag() Tag { return EmphTag }
func (e *Emph) inlines() []Inline { return e.Inlines }
func (e *Emph) clone() Element {
c := *e
return &c
}
func (e *Emph) inline() {}
func (e *Emph) element() {}
func (e *Emph) Apply(transformers ...func(*Emph) (*Emph, error)) (*Emph, error) {
return apply(e, transformers...)
}
// Underlined text (list of inlines)
type Underline struct {
Inlines []Inline
}
const UnderlineTag = Tag("Underline")
func (u *Underline) Tag() Tag { return UnderlineTag }
func (u *Underline) inlines() []Inline { return u.Inlines }
func (u *Underline) inline() {}
func (u *Underline) clone() Element {
c := *u
return &c
}
func (u *Underline) element() {}
func (u *Underline) Apply(transformers ...func(*Underline) (*Underline, error)) (*Underline, error) {
return apply(u, transformers...)
}
// Strongly emphasized text (list of inlines)
type Strong struct {
Inlines []Inline
}
const StrongTag = Tag("Strong")
func (s *Strong) Tag() Tag { return StrongTag }
func (s *Strong) inlines() []Inline { return s.Inlines }
func (s *Strong) inline() {}
func (s *Strong) clone() Element {
c := *s
return &c
}
func (s *Strong) element() {}
func (s *Strong) Apply(transformers ...func(*Strong) (*Strong, error)) (*Strong, error) {
return apply(s, transformers...)
}
// Strikeout text (list of inlines)
type Strikeout struct {
Inlines []Inline
}
const StrikeoutTag = Tag("Strikeout")
func (s *Strikeout) Tag() Tag { return StrikeoutTag }
func (s *Strikeout) inlines() []Inline { return s.Inlines }
func (s *Strikeout) inline() {}
func (s *Strikeout) clone() Element {
c := *s
return &c
}
func (s *Strikeout) element() {}
func (s *Strikeout) Apply(transformers ...func(*Strikeout) (*Strikeout, error)) (*Strikeout, error) {
return apply(s, transformers...)
}
// Superscripted text (list of inlines)
type Superscript struct {
Inlines []Inline
}
const SuperscriptTag = Tag("Superscript")
func (s *Superscript) Tag() Tag { return SuperscriptTag }
func (s *Superscript) inlines() []Inline { return s.Inlines }
func (s *Superscript) clone() Element {
c := *s
return &c
}
func (s *Superscript) inline() {}
func (s *Superscript) element() {}
func (s *Superscript) Apply(transformers ...func(*Superscript) (*Superscript, error)) (*Superscript, error) {
return apply(s, transformers...)
}
// Subscripted text (list of inlines)
type Subscript struct {
Inlines []Inline
}
const SubscriptTag = Tag("Subscript")
func (s *Subscript) Tag() Tag { return SubscriptTag }
func (s *Subscript) inlines() []Inline { return s.Inlines }
func (s *Subscript) inline() {}
func (s *Subscript) clone() Element {
c := *s
return &c
}
func (s *Subscript) element() {}
func (s *Subscript) Apply(transformers ...func(*Subscript) (*Subscript, error)) (*Subscript, error) {
return apply(s, transformers...)
}
// Small capitals (list of inlines)
type SmallCaps struct {
Inlines []Inline
}
const SmallCapsTag = Tag("SmallCaps")
func (s *SmallCaps) Tag() Tag { return SmallCapsTag }
func (s *SmallCaps) inlines() []Inline { return s.Inlines }
func (s *SmallCaps) inline() {}
func (s *SmallCaps) clone() Element {
c := *s
return &c
}
func (s *SmallCaps) element() {}
func (s *SmallCaps) Apply(transformers ...func(*SmallCaps) (*SmallCaps, error)) (*SmallCaps, error) {
return apply(s, transformers...)
}
type QuoteType Tag
const (
SingleQuote QuoteType = "SingleQuote"
DoubleQuote QuoteType = "DoubleQuote"
)
// Quoted text (list of inlines)
type Quoted struct {
QuoteType QuoteType
Inlines []Inline
}
const QuotedTag = Tag("Quoted")
func (q *Quoted) Tag() Tag { return QuotedTag }
func (q *Quoted) inlines() []Inline { return q.Inlines }
func (q *Quoted) inline() {}
func (q *Quoted) clone() Element {
c := *q
return &c
}
func (q *Quoted) element() {}
func (q *Quoted) Apply(transformers ...func(*Quoted) (*Quoted, error)) (*Quoted, error) {
return apply(q, transformers...)
}
type CitationMode Tag
const (
NormalCitation CitationMode = "NormalCitation"
SuppressAuthor CitationMode = "SuppressAuthor"
AuthorInText CitationMode = "AuthorInText"
)
type Citation struct {
Id string
Prefix []Inline
Suffix []Inline
Mode CitationMode
NoteNum int
Hash int
}
func (c *Citation) element() {}
func (c *Citation) clone() Element {
c1 := *c
return &c1
}
func (c *Citation) Apply(transformers ...func(*Citation) (*Citation, error)) (*Citation, error) {
return apply(c, transformers...)
}
// Citation (list of inlines)
type Cite struct {
Citations []*Citation
Inlines []Inline
}
const CiteTag = Tag("Cite")
func (c *Cite) Tag() Tag { return CiteTag }
func (c *Cite) inline() {}
func (c *Cite) clone() Element {
c2 := *c
return &c2
}
func (c *Cite) element() {}
func (c *Cite) Apply(transformers ...func(*Cite) (*Cite, error)) (*Cite, error) {
return apply(c, transformers...)
}
// Inline code (literal)
type Code struct {
Attr
Text string
}
const CodeTag = Tag("Code")
func (c *Code) Tag() Tag { return CodeTag }
func (c *Code) clone() Element {
c1 := *c
return &c1
}
func (c *Code) inline() {}
func (c *Code) element() {}
var SP = &Space{}
// Inter-word space
type Space struct{}
const SpaceTag = Tag("Space")
func (*Space) Tag() Tag { return SpaceTag }
func (*Space) space() {}
func (*Space) clone() Element { return SP }
func (*Space) inline() {}
func (*Space) element() {}
var SB = &SoftBreak{}
// Soft line break
type SoftBreak struct{}
const SoftBreakTag = Tag("SoftBreak")
func (*SoftBreak) Tag() Tag { return SoftBreakTag }
func (*SoftBreak) space() {}
func (*SoftBreak) clone() Element { return SB }
func (*SoftBreak) inline() {}
func (*SoftBreak) element() {}
var LB = &LineBreak{}
// Hard line break
type LineBreak struct{}
const LineBreakTag = Tag("LineBreak")
func (*LineBreak) Tag() Tag { return LineBreakTag }
func (*LineBreak) space() {}
func (*LineBreak) clone() Element { return LB }
func (*LineBreak) inline() {}
func (*LineBreak) element() {}
type MathType Tag
const (
DisplayMath MathType = "DisplayMath"
InlineMath MathType = "InlineMath"
)
// TeX math (literal)
type Math struct {
MathType MathType
Text string
}
const MathTag = Tag("Math")
func (m *Math) Tag() Tag { return MathTag }
func (m *Math) clone() Element {
c := *m
return &c
}
func (m *Math) inline() {}
func (m *Math) element() {}
// Raw inline
type RawInline struct {
Format string
Text string
}
const RawInlineTag = Tag("RawInline")
func (r *RawInline) Tag() Tag { return RawInlineTag }
func (r *RawInline) clone() Element {
c := *r
return &c
}
func (r *RawInline) element() {}
func (r *RawInline) inline() {}
type Target struct {
Url string
Title string
}
// Hyperlink: alt text (list of inlines), target
type Link struct {
Attr
Inlines []Inline
Target Target
}
const LinkTag = Tag("Link")
func (l *Link) Tag() Tag { return LinkTag }
func (l *Link) inlines() []Inline { return l.Inlines }
func (l *Link) clone() Element {
c := *l
return &c
}
func (l *Link) inline() {}
func (l *Link) element() {}
func (l *Link) Apply(transformers ...func(*Link) (*Link, error)) (*Link, error) {
return apply(l, transformers...)
}
// Image: alt text (list of inlines), target
type Image struct {
Attr
Inlines []Inline
Target Target
}
const ImageTag = Tag("Image")
func (i *Image) Tag() Tag { return ImageTag }
func (i *Image) inlines() []Inline { return i.Inlines }
func (i *Image) clone() Element {
c := *i
return &c
}
func (i *Image) element() {}
func (i *Image) inline() {}
func (i *Image) Apply(transformers ...func(*Image) (*Image, error)) (*Image, error) {
return apply(i, transformers...)
}
// Footnote: list of blocks
type Note struct {
Blocks []Block
}
const NoteTag = Tag("Note")
func (n *Note) Tag() Tag { return NoteTag }
func (n *Note) blocks() []Block { return n.Blocks }
func (n *Note) clone() Element {
c := *n
return &c
}
func (n *Note) element() {}
func (n *Note) inline() {}
func (n *Note) Apply(transformers ...func(*Note) (*Note, error)) (*Note, error) {
return apply(n, transformers...)
}
// Generic inline container with attributes
type Span struct {
Attr
Inlines []Inline
}
const SpanTag = Tag("Span")
func (s *Span) Tag() Tag { return SpanTag }
func (s *Span) inlines() []Inline { return s.Inlines }
func (s *Span) clone() Element {
c := *s
return &c
}
func (s *Span) inline() {}
func (s *Span) element() {}
func (s *Span) Apply(transformers ...func(*Span) (*Span, error)) (*Span, error) {
return apply(s, transformers...)
}
// Plain text, not a paragraph
type Plain struct {
Inlines []Inline
}
const PlainTag = Tag("Plain")
func (p *Plain) Tag() Tag { return PlainTag }
func (p *Plain) inlines() []Inline { return p.Inlines }
func (p *Plain) clone() Element {
c := *p
return &c
}
func (p *Plain) block() {}
func (p *Plain) element() {}
func (p *Plain) Apply(transformers ...func(*Plain) (*Plain, error)) (*Plain, error) {
return apply(p, transformers...)
}
// Paragraph (list of inlines)
type Para struct {
Inlines []Inline
}
const ParaTag = Tag("Para")
func (p *Para) Tag() Tag { return ParaTag }
func (p *Para) inlines() []Inline { return p.Inlines }
func (p *Para) clone() Element {
c := *p
return &c
}
func (p *Para) block() {}
func (p *Para) element() {}
func (p *Para) Apply(transformers ...func(*Para) (*Para, error)) (*Para, error) {
return apply(p, transformers...)
}
// Multiple non-breaking lines
type LineBlock struct {
Inlines [][]Inline
}
const LineBlockTag = Tag("LineBlock")
func (b *LineBlock) Tag() Tag { return LineBlockTag }
func (b *LineBlock) clone() Element {
c := *b
return &c
}
func (b *LineBlock) block() {}
func (b *LineBlock) element() {}
func (b *LineBlock) Apply(transformers ...func(*LineBlock) (*LineBlock, error)) (*LineBlock, error) {
return apply(b, transformers...)
}
// Code block (literal)
type CodeBlock struct {
Attr
Text string
}
const CodeBlockTag = Tag("CodeBlock")
func (b *CodeBlock) Tag() Tag { return CodeBlockTag }
func (b *CodeBlock) clone() Element {
c := *b
return &c
}
func (b *CodeBlock) block() {}
func (b *CodeBlock) element() {}
// Raw block
type RawBlock struct {
Format string
Text string
}
const RawBlockTag = Tag("RawBlock")
func (b *RawBlock) Tag() Tag { return RawBlockTag }
func (b *RawBlock) clone() Element {
c := *b
return &c
}
func (b *RawBlock) block() {}
func (b *RawBlock) element() {}
// Block quote (list of blocks)
type BlockQuote struct {
Blocks []Block
}
const BlockQuoteTag = Tag("BlockQuote")
func (b *BlockQuote) Tag() Tag { return BlockQuoteTag }
func (b *BlockQuote) blocks() []Block { return b.Blocks }
func (b *BlockQuote) clone() Element {
c := *b
return &c
}
func (b *BlockQuote) block() {}
func (b *BlockQuote) element() {}
func (b *BlockQuote) Apply(transformers ...func(*BlockQuote) (*BlockQuote, error)) (*BlockQuote, error) {
return apply(b, transformers...)
}
type ListNumberStyle Tag
const (
DefaultStyle ListNumberStyle = "DefaultStyle"
Example ListNumberStyle = "Example"
Decimal ListNumberStyle = "Decimal"
LowerRoman ListNumberStyle = "LowerRoman"
UpperRoman ListNumberStyle = "UpperRoman"
LowerAlpha ListNumberStyle = "LowerAlpha"
UpperAlpha ListNumberStyle = "UpperAlpha"
)
type ListNumberDelim Tag
const (
DefaultDelim ListNumberDelim = "DefaultDelim"
Period ListNumberDelim = "Period"
OneParen ListNumberDelim = "OneParen"
TwoParens ListNumberDelim = "TwoParens"
)
type ListAttrs struct {
Start int
Style ListNumberStyle
Delimiter ListNumberDelim
}
// Ordered list (attributes and a list of items, each a list of blocks)
type OrderedList struct {
Attr ListAttrs
Items [][]Block
}
const OrderedListTag = Tag("OrderedList")
func (l *OrderedList) Tag() Tag { return OrderedListTag }
func (l *OrderedList) clone() Element {
c := *l
return &c
}
func (l *OrderedList) block() {}
func (l *OrderedList) element() {}
func (l *OrderedList) Apply(transformers ...func(*OrderedList) (*OrderedList, error)) (*OrderedList, error) {
return apply(l, transformers...)
}
// Bullet list (list of items, each a list of blocks)
type BulletList struct {
Items [][]Block
}
const BulletListTag = Tag("BulletList")
func (l *BulletList) Tag() Tag { return BulletListTag }
func (l *BulletList) clone() Element {
c := *l
return &c
}
func (l *BulletList) block() {}
func (l *BulletList) element() {}
func (l *BulletList) Apply(transformers ...func(*BulletList) (*BulletList, error)) (*BulletList, error) {
return apply(l, transformers...)
}
type Definition struct {