diff --git a/elemheap.go b/elemheap.go index b403021..6ce5b17 100644 --- a/elemheap.go +++ b/elemheap.go @@ -14,7 +14,7 @@ field. */ type elemHeap struct { - rows [][]element + rows [][]Element heapPos rowSize int @@ -24,13 +24,13 @@ type elemHeap struct { type heapPos struct { iRow int - row []element + row []Element } -func (h *elemHeap) nextRow() []element { +func (h *elemHeap) nextRow() []Element { h.iRow++ if h.iRow == len(h.rows) { - h.rows = append(h.rows, make([]element, h.rowSize)) + h.rows = append(h.rows, make([]Element, h.rowSize)) } h.row = h.rows[h.iRow] return h.row @@ -38,7 +38,7 @@ func (h *elemHeap) nextRow() []element { func (h *elemHeap) init(size int) { h.rowSize = size - h.rows = [][]element{make([]element, size)} + h.rows = [][]Element{make([]Element, size)} h.row = h.rows[h.iRow] h.base = h.heapPos } diff --git a/markdown.go b/markdown.go index 39c7146..e227f82 100644 --- a/markdown.go +++ b/markdown.go @@ -68,7 +68,7 @@ func NewParser(x *Extensions) (p *Parser) { // method is called, which may, for example, print footnotes. // A Formatter can be reused. type Formatter interface { - FormatBlock(*element) + FormatBlock(*Element) Finish() } @@ -97,7 +97,7 @@ func (p *Parser) Markdown(src io.Reader, f Formatter) { f.Finish() } -func (p *Parser) parseRule(rule int, s string) (tree *element) { +func (p *Parser) parseRule(rule int, s string) (tree *Element) { old := p.yy.ResetBuffer(s) if old != "" && strings.Trim(old, "\r\n ") != "" { log.Fatalln("Buffer not empty", "["+old+"]") @@ -113,34 +113,34 @@ func (p *Parser) parseRule(rule int, s string) (tree *element) { return } -/* process_raw_blocks - traverses an element list, replacing any RAW elements with +/* process_raw_blocks - traverses an Element list, replacing any RAW elements with * the result of parsing them as markdown text, and recursing into the children * of parent elements. The result should be a tree of elements without any RAWs. */ -func (p *Parser) processRawBlocks(input *element) *element { +func (p *Parser) processRawBlocks(input *Element) *Element { - for current := input; current != nil; current = current.next { - if current.key == RAW { + for current := input; current != nil; current = current.Next { + if current.Key == RAW { /* \001 is used to indicate boundaries between nested lists when there * is no blank line. We split the string by \001 and parse * each chunk separately. */ - current.key = LIST - current.children = nil - listEnd := ¤t.children - for _, contents := range strings.Split(current.contents.str, "\001") { - if list := p.parseRule(ruleDoc, contents); list != nil { + current.Key = LIST + current.Children = nil + listEnd := ¤t.Children + for _, Contents := range strings.Split(current.Contents.Str, "\001") { + if list := p.parseRule(ruleDoc, Contents); list != nil { *listEnd = list - for list.next != nil { - list = list.next + for list.Next != nil { + list = list.Next } - listEnd = &list.next + listEnd = &list.Next } } - current.contents.str = "" + current.Contents.Str = "" } - if current.children != nil { - current.children = p.processRawBlocks(current.children) + if current.Children != nil { + current.Children = p.processRawBlocks(current.Children) } } return input diff --git a/misc/c2go.sed b/misc/c2go.sed index 07d707b..7fc76d4 100644 --- a/misc/c2go.sed +++ b/misc/c2go.sed @@ -14,7 +14,7 @@ s,find_reference,p.findReference,g s,->key,.key,g s,->children,.children,g -s,->contents.str,.contents.str,g +s,->Contents.Str,.Contents.Str,g /{ *if (extens/ { s,if (,if , @@ -30,7 +30,7 @@ s,->contents.str,.contents.str,g s,extension.EXT_NOTES.,extension.Notes,g } -s,{ *element \*[a-z]*\; *$,{, +s,{ *Element \*[a-z]*\; *$,{, /raw\.key =/ s,;$,, /result =/ s,;$,, diff --git a/out-groffmm.go b/out-groffmm.go index 0fe3c16..083dbbc 100644 --- a/out-groffmm.go +++ b/out-groffmm.go @@ -38,7 +38,7 @@ func ToGroffMM(w Writer) Formatter { f.escape = strings.NewReplacer(`\`, `\e`) return f } -func (f *troffOut) FormatBlock(tree *element) { +func (f *troffOut) FormatBlock(tree *Element) { f.elist(tree) } func (f *troffOut) Finish() { @@ -76,10 +76,10 @@ func (w *troffOut) str(s string) *troffOut { return w } -func (w *troffOut) children(el *element) *troffOut { - return w.elist(el.children) +func (w *troffOut) children(el *Element) *troffOut { + return w.elist(el.Children) } -func (w *troffOut) inline(pfx string, el *element, sfx string) *troffOut { +func (w *troffOut) inline(pfx string, el *Element, sfx string) *troffOut { return w.s(pfx).children(el).s(sfx) } @@ -88,24 +88,24 @@ func (w *troffOut) req(name string) *troffOut { } // write a list of elements -func (w *troffOut) elist(list *element) *troffOut { +func (w *troffOut) elist(list *Element) *troffOut { for i := 0; list != nil; i++ { w.elem(list, i == 0) - list = list.next + list = list.Next } return w } -func (w *troffOut) elem(elt *element, isFirst bool) *troffOut { +func (w *troffOut) elem(elt *Element, isFirst bool) *troffOut { var s string - switch elt.key { + switch elt.Key { case SPACE: - s = elt.contents.str + s = elt.Contents.Str case LINEBREAK: w.req("br\n") case STR: - w.str(elt.contents.str) + w.str(elt.Contents.Str) case ELLIPSIS: s = "..." case EMDASH: @@ -119,15 +119,15 @@ func (w *troffOut) elem(elt *element, isFirst bool) *troffOut { case DOUBLEQUOTED: w.inline(`\[lq]`, elt, `\[rq]`) case CODE: - w.s(`\fC`).str(elt.contents.str).s(`\fR`) + w.s(`\fC`).str(elt.Contents.Str).s(`\fR`) case HTML: /* don't print HTML */ case LINK: - link := elt.contents.link - w.elist(link.label) - w.s(" (").s(link.url).s(")") + link := elt.Contents.Link + w.elist(link.Label) + w.s(" (").s(link.URL).s(")") case IMAGE: - w.s("[IMAGE: ").elist(elt.contents.link.label).s("]") + w.s("[IMAGE: ").elist(elt.Contents.Link.Label).s("]") /* not supported */ case EMPH: w.inline(`\fI`, elt, `\fR`) @@ -150,7 +150,7 @@ func (w *troffOut) elem(elt *element, isFirst bool) *troffOut { /* Shouldn't occur - these are handled by process_raw_blocks() */ log.Fatalf("RAW") case H1, H2, H3, H4, H5, H6: - h := ".H " + string('1'+elt.key-H1) + ` "` /* assumes H1 ... H6 are in order */ + h := ".H " + string('1'+elt.Key-H1) + ` "` /* assumes H1 ... H6 are in order */ w.br().inline(h, elt, `"`) case PLAIN: w.br().children(elt) @@ -166,7 +166,7 @@ func (w *troffOut) elem(elt *element, isFirst bool) *troffOut { /* don't print HTML block */ case VERBATIM: w.req("VERBON 2\n") - w.str(elt.contents.str) + w.str(elt.Contents.Str) w.s(".VERBOFF") case BULLETLIST: w.req("BL").children(elt).req("LE 1") @@ -191,9 +191,9 @@ func (w *troffOut) elem(elt *element, isFirst bool) *troffOut { w.children(elt) w.req("DE") case NOTE: - /* if contents.str == 0, then print note; else ignore, since this + /* if Contents.Str == 0, then print note; else ignore, since this * is a note block that has been incorporated into the notes list */ - if elt.contents.str == "" { + if elt.Contents.Str == "" { w.s("\\*F\n") w.s(".FS\n") w.skipPadding() @@ -203,7 +203,7 @@ func (w *troffOut) elem(elt *element, isFirst bool) *troffOut { case REFERENCE: /* Nonprinting */ default: - log.Fatalf("troffOut.elem encountered unknown element key = %d\n", elt.key) + log.Fatalf("troffOut.elem encountered unknown Element key = %d\n", elt.Key) } if s != "" { w.s(s) diff --git a/output.go b/output.go index 7a57c86..2d948d0 100644 --- a/output.go +++ b/output.go @@ -43,7 +43,7 @@ type htmlOut struct { obfuscate bool notenum int - endNotes []*element /* List of endnotes to print after main content. */ + endNotes []*Element /* List of endnotes to print after main content. */ } func ToHTML(w Writer) Formatter { @@ -51,7 +51,7 @@ func ToHTML(w Writer) Formatter { f.baseWriter = baseWriter{w, 2} return f } -func (f *htmlOut) FormatBlock(tree *element) { +func (f *htmlOut) FormatBlock(tree *Element) { f.elist(tree) } func (f *htmlOut) Finish() { @@ -140,40 +140,40 @@ func (w *htmlOut) str(s string) *htmlOut { return w } -func (w *htmlOut) children(el *element) *htmlOut { - return w.elist(el.children) +func (w *htmlOut) children(el *Element) *htmlOut { + return w.elist(el.Children) } -func (w *htmlOut) inline(tag string, el *element) *htmlOut { +func (w *htmlOut) inline(tag string, el *Element) *htmlOut { return w.s(tag).children(el).s("\n" case STR: - w.str(elt.contents.str) + w.str(elt.Contents.Str) case ELLIPSIS: s = "…" case EMDASH: @@ -187,25 +187,25 @@ func (w *htmlOut) elem(elt *element) *htmlOut { case DOUBLEQUOTED: w.s("“").children(elt).s("”") case CODE: - w.s("").str(elt.contents.str).s("") + w.s("").str(elt.Contents.Str).s("") case HTML: - s = elt.contents.str + s = elt.Contents.Str case LINK: o := w.obfuscate - if strings.Index(elt.contents.link.url, "mailto:") == 0 { + if strings.Index(elt.Contents.Link.URL, "mailto:") == 0 { w.obfuscate = true /* obfuscate mailto: links */ } - w.s(` 0 { - w.s(` title="`).str(elt.contents.link.title).s(`"`) + w.s(` 0 { + w.s(` title="`).str(elt.Contents.Link.Title).s(`"`) } - w.s(">").elist(elt.contents.link.label).s("") + w.s(">").elist(elt.Contents.Link.Label).s("") w.obfuscate = o case IMAGE: - w.s(``)
-		w.elist(elt.contents.link.label).s(` 0 { - w.s(` title="`).str(elt.contents.link.title).s(`"`) + w.s(``)
+		w.elist(elt.Contents.Link.Label).s(` 0 { + w.s(` title="`).str(elt.Contents.Link.Title).s(`"`) } w.s(" />") case EMPH: @@ -220,7 +220,7 @@ func (w *htmlOut) elem(elt *element) *htmlOut { /* Shouldn't occur - these are handled by process_raw_blocks() */ log.Fatalf("RAW") case H1, H2, H3, H4, H5, H6: - h := "" /* assumes H1 ... H6 are in order */ + h := "" /* assumes H1 ... H6 are in order */ w.sp().inline(h, elt) case PLAIN: w.br().children(elt) @@ -229,9 +229,9 @@ func (w *htmlOut) elem(elt *element) *htmlOut { case HRULE: w.sp().s("
") case HTMLBLOCK: - w.sp().s(elt.contents.str) + w.sp().s(elt.Contents.Str) case VERBATIM: - w.sp().s("
").str(elt.contents.str).s("
") + w.sp().s("
").str(elt.Contents.Str).s("
") case BULLETLIST: w.listBlock("