all repos — grayfriday @ ee98bc0bf4ddd4670dfad41751d5162470c18dca

blackfriday fork with a few changes

Massive replacement of C_STYLE flags to typed ones
Vytautas Ĺ altenis vytas@rtfb.lt
Mon, 26 Oct 2015 18:16:57 +0200
commit

ee98bc0bf4ddd4670dfad41751d5162470c18dca

parent

06515e91255c2ca096c97d491b1ec81455c64f0c

9 files changed, 194 insertions(+), 202 deletions(-)

jump to
M block.goblock.go

@@ -63,7 +63,7 @@ //

// % stuff // % more stuff // % even more stuff - if p.flags&EXTENSION_TITLEBLOCK != 0 { + if p.flags&Titleblock != 0 { if data[0] == '%' { if i := p.titleBlock(out, data, true); i > 0 { data = data[i:]

@@ -101,7 +101,7 @@ // }

// return n * fact(n-1) // } // ``` - if p.flags&EXTENSION_FENCED_CODE != 0 { + if p.flags&FencedCode != 0 { if i := p.fencedCode(out, data, true); i > 0 { data = data[i:] continue

@@ -139,7 +139,7 @@ // Name | Age | Phone

// ------|-----|--------- // Bob | 31 | 555-1234 // Alice | 27 | 555-4321 - if p.flags&EXTENSION_TABLES != 0 { + if p.flags&Tables != 0 { if i := p.table(out, data); i > 0 { data = data[i:] continue

@@ -162,7 +162,7 @@ //

// 1. Item 1 // 2. Item 2 if p.oliPrefix(data) > 0 { - data = data[p.list(out, data, LIST_TYPE_ORDERED):] + data = data[p.list(out, data, ListTypeOrdered):] continue }

@@ -174,9 +174,9 @@ // : Definition b

// // Term 2 // : Definition c - if p.flags&EXTENSION_DEFINITION_LISTS != 0 { + if p.flags&DefinitionLists != 0 { if p.dliPrefix(data) > 0 { - data = data[p.list(out, data, LIST_TYPE_DEFINITION):] + data = data[p.list(out, data, ListTypeDefinition):] continue } }

@@ -194,7 +194,7 @@ if data[0] != '#' {

return false } - if p.flags&EXTENSION_SPACE_HEADERS != 0 { + if p.flags&SpaceHeaders != 0 { level := 0 for level < 6 && data[level] == '#' { level++

@@ -215,7 +215,7 @@ i := skipChar(data, level, ' ')

end := skipUntilChar(data, i, '\n') skip := end id := "" - if p.flags&EXTENSION_HEADER_IDS != 0 { + if p.flags&HeaderIDs != 0 { j, k := 0, 0 // find start/end of header id for j = i; j < end-1 && (data[j] != '{' || data[j+1] != '#'); j++ {

@@ -242,7 +242,7 @@ for end > 0 && data[end-1] == ' ' {

end-- } if end > i { - if id == "" && p.flags&EXTENSION_AUTO_HEADER_IDS != 0 { + if id == "" && p.flags&AutoHeaderIDs != 0 { id = sanitized_anchor_name.Create(string(data[i:end])) } work := func() bool {

@@ -484,7 +484,7 @@ if i >= len(data) {

return i } - if p.flags&EXTENSION_LAX_HTML_BLOCKS != 0 { + if p.flags&LaxHTMLBlocks != 0 { return i } if skip = p.isEmpty(data[i:]); skip == 0 {

@@ -767,7 +767,7 @@ dashes := 0

if data[i] == ':' { i++ - columns[col] |= TABLE_ALIGNMENT_LEFT + columns[col] |= TableAlignmentLeft dashes++ } for data[i] == '-' {

@@ -776,7 +776,7 @@ dashes++

} if data[i] == ':' { i++ - columns[col] |= TABLE_ALIGNMENT_RIGHT + columns[col] |= TableAlignmentRight dashes++ } for data[i] == ' ' {

@@ -913,7 +913,7 @@ // Step over whole lines, collecting them. While doing that, check for

// fenced code and if one's found, incorporate it altogether, // irregardless of any contents inside it for data[end] != '\n' { - if p.flags&EXTENSION_FENCED_CODE != 0 { + if p.flags&FencedCode != 0 { if i := p.fencedCode(out, data[end:], false); i > 0 { // -1 to compensate for the extra end++ after the loop: end += i - 1

@@ -1049,18 +1049,18 @@ return i + 2

} // parse ordered or unordered list block -func (p *parser) list(out *bytes.Buffer, data []byte, flags int) int { +func (p *parser) list(out *bytes.Buffer, data []byte, flags ListType) int { i := 0 - flags |= LIST_ITEM_BEGINNING_OF_LIST + flags |= ListItemBeginningOfList work := func() bool { for i < len(data) { skip := p.listItem(out, data[i:], &flags) i += skip - if skip == 0 || flags&LIST_ITEM_END_OF_LIST != 0 { + if skip == 0 || flags&ListItemEndOfList != 0 { break } - flags &= ^LIST_ITEM_BEGINNING_OF_LIST + flags &= ^ListItemBeginningOfList } return true }

@@ -1071,7 +1071,7 @@ }

// Parse a single list item. // Assumes initial prefix is already removed if this is a sublist. -func (p *parser) listItem(out *bytes.Buffer, data []byte, flags *int) int { +func (p *parser) listItem(out *bytes.Buffer, data []byte, flags *ListType) int { // keep track of the indentation of the first line itemIndent := 0 for itemIndent < 3 && data[itemIndent] == ' ' {

@@ -1086,13 +1086,13 @@ if i == 0 {

i = p.dliPrefix(data) // reset definition term flag if i > 0 { - *flags &= ^LIST_TYPE_TERM + *flags &= ^ListTypeTerm } } if i == 0 { // if in defnition list, set term flag and continue - if *flags&LIST_TYPE_DEFINITION != 0 { - *flags |= LIST_TYPE_TERM + if *flags&ListTypeDefinition != 0 { + *flags |= ListTypeTerm } else { return 0 }

@@ -1153,7 +1153,7 @@ p.oliPrefix(chunk) > 0 ||

p.dliPrefix(chunk) > 0: if containsBlankLine { - *flags |= LIST_ITEM_CONTAINS_BLOCK + *flags |= ListItemContainsBlock } // to be a nested list, it must be indented more

@@ -1172,16 +1172,16 @@ case p.isPrefixHeader(chunk):

// if the header is not indented, it is not nested in the list // and thus ends the list if containsBlankLine && indent < 4 { - *flags |= LIST_ITEM_END_OF_LIST + *flags |= ListItemEndOfList break gatherlines } - *flags |= LIST_ITEM_CONTAINS_BLOCK + *flags |= ListItemContainsBlock // anything following an empty line is only part // of this item if it is indented 4 spaces // (regardless of the indentation of the beginning of the item) case containsBlankLine && indent < 4: - if *flags&LIST_TYPE_DEFINITION != 0 && i < len(data)-1 { + if *flags&ListTypeDefinition != 0 && i < len(data)-1 { // is the next item still a part of this list? next := i for data[next] != '\n' {

@@ -1191,17 +1191,17 @@ for next < len(data)-1 && data[next] == '\n' {

next++ } if i < len(data)-1 && data[i] != ':' && data[next] != ':' { - *flags |= LIST_ITEM_END_OF_LIST + *flags |= ListItemEndOfList } } else { - *flags |= LIST_ITEM_END_OF_LIST + *flags |= ListItemEndOfList } break gatherlines // a blank line means this should be parsed as a block case containsBlankLine: raw.WriteByte('\n') - *flags |= LIST_ITEM_CONTAINS_BLOCK + *flags |= ListItemContainsBlock } // if this line was preceeded by one or more blanks,

@@ -1222,7 +1222,7 @@ rawBytes := raw.Bytes()

// render the contents of the list item var cooked bytes.Buffer - if *flags&LIST_ITEM_CONTAINS_BLOCK != 0 && *flags&LIST_TYPE_TERM == 0 { + if *flags&ListItemContainsBlock != 0 && *flags&ListTypeTerm == 0 { // intermediate render of block item, except for definition term if sublist > 0 { p.block(&cooked, rawBytes[:sublist])

@@ -1296,9 +1296,9 @@

// did we find a blank line marking the end of the paragraph? if n := p.isEmpty(current); n > 0 { // did this blank line followed by a definition list item? - if p.flags&EXTENSION_DEFINITION_LISTS != 0 { + if p.flags&DefinitionLists != 0 { if i < len(data)-1 && data[i+1] == ':' { - return p.list(out, data[prev:], LIST_TYPE_DEFINITION) + return p.list(out, data[prev:], ListTypeDefinition) } }

@@ -1331,7 +1331,7 @@ }

}(out, p, data[prev:eol]) id := "" - if p.flags&EXTENSION_AUTO_HEADER_IDS != 0 { + if p.flags&AutoHeaderIDs != 0 { id = sanitized_anchor_name.Create(string(data[prev:eol])) }

@@ -1346,7 +1346,7 @@ }

} // if the next line starts a block of HTML, then the paragraph ends here - if p.flags&EXTENSION_LAX_HTML_BLOCKS != 0 { + if p.flags&LaxHTMLBlocks != 0 { if data[i] == '<' && p.html(out, current, false) > 0 { // rewind to before the HTML block p.renderParagraph(out, data[:i])

@@ -1361,7 +1361,7 @@ return i

} // if there's a fenced code block, paragraph is over - if p.flags&EXTENSION_FENCED_CODE != 0 { + if p.flags&FencedCode != 0 { if p.fencedCode(out, current, false) > 0 { p.renderParagraph(out, data[:i]) return i

@@ -1369,14 +1369,14 @@ }

} // if there's a definition list item, prev line is a definition term - if p.flags&EXTENSION_DEFINITION_LISTS != 0 { + if p.flags&DefinitionLists != 0 { if p.dliPrefix(current) != 0 { - return p.list(out, data[prev:], LIST_TYPE_DEFINITION) + return p.list(out, data[prev:], ListTypeDefinition) } } // if there's a list after this, paragraph is over - if p.flags&EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK != 0 { + if p.flags&NoEmptyLineBeforeBlock != 0 { if p.uliPrefix(current) != 0 || p.oliPrefix(current) != 0 || p.quotePrefix(current) != 0 ||
M block_test.goblock_test.go

@@ -18,35 +18,27 @@ "strings"

"testing" ) -func runMarkdownBlockWithRenderer(input string, extensions int, renderer Renderer) string { +func runMarkdownBlockWithRenderer(input string, extensions Extensions, renderer Renderer) string { return string(Markdown([]byte(input), renderer, extensions)) } -func runMarkdownBlock(input string, extensions int) string { - htmlFlags := 0 - htmlFlags |= HTML_USE_XHTML - - renderer := HtmlRenderer(htmlFlags, "", "") - +func runMarkdownBlock(input string, extensions Extensions) string { + renderer := HtmlRenderer(UseXHTML, "", "") return runMarkdownBlockWithRenderer(input, extensions, renderer) } -func runnerWithRendererParameters(parameters HtmlRendererParameters) func(string, int) string { - return func(input string, extensions int) string { - htmlFlags := 0 - htmlFlags |= HTML_USE_XHTML - - renderer := HtmlRendererWithParameters(htmlFlags, "", "", parameters) - +func runnerWithRendererParameters(parameters HtmlRendererParameters) func(string, Extensions) string { + return func(input string, extensions Extensions) string { + renderer := HtmlRendererWithParameters(UseXHTML, "", "", parameters) return runMarkdownBlockWithRenderer(input, extensions, renderer) } } -func doTestsBlock(t *testing.T, tests []string, extensions int) { +func doTestsBlock(t *testing.T, tests []string, extensions Extensions) { doTestsBlockWithRunner(t, tests, extensions, runMarkdownBlock) } -func doTestsBlockWithRunner(t *testing.T, tests []string, extensions int, runner func(string, int) string) { +func doTestsBlockWithRunner(t *testing.T, tests []string, extensions Extensions, runner func(string, Extensions) string) { // catch and report panics var candidate string defer func() {

@@ -203,7 +195,7 @@ "* List\n * Nested list\n # Nested header\n",

"<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" + "<h1>Nested header</h1></li>\n</ul></li>\n</ul>\n", } - doTestsBlock(t, tests, EXTENSION_SPACE_HEADERS) + doTestsBlock(t, tests, SpaceHeaders) } func TestPrefixHeaderIdExtension(t *testing.T) {

@@ -263,7 +255,7 @@ "* List\n * Nested list\n # Nested header {#someid}\n",

"<ul>\n<li><p>List</p>\n\n<ul>\n<li><p>Nested list</p>\n\n" + "<h1 id=\"someid\">Nested header</h1></li>\n</ul></li>\n</ul>\n", } - doTestsBlock(t, tests, EXTENSION_HEADER_IDS) + doTestsBlock(t, tests, HeaderIDs) } func TestPrefixHeaderIdExtensionWithPrefixAndSuffix(t *testing.T) {

@@ -311,7 +303,7 @@ HeaderIDPrefix: "PRE:",

HeaderIDSuffix: ":POST", } - doTestsBlockWithRunner(t, tests, EXTENSION_HEADER_IDS, runnerWithRendererParameters(parameters)) + doTestsBlockWithRunner(t, tests, HeaderIDs, runnerWithRendererParameters(parameters)) } func TestPrefixAutoHeaderIdExtension(t *testing.T) {

@@ -362,7 +354,7 @@

"# Header\n\n# Header 1\n\n# Header\n\n# Header", "<h1 id=\"header\">Header</h1>\n\n<h1 id=\"header-1\">Header 1</h1>\n\n<h1 id=\"header-1-1\">Header</h1>\n\n<h1 id=\"header-1-2\">Header</h1>\n", } - doTestsBlock(t, tests, EXTENSION_AUTO_HEADER_IDS) + doTestsBlock(t, tests, AutoHeaderIDs) } func TestPrefixAutoHeaderIdExtensionWithPrefixAndSuffix(t *testing.T) {

@@ -419,7 +411,7 @@ HeaderIDPrefix: "PRE:",

HeaderIDSuffix: ":POST", } - doTestsBlockWithRunner(t, tests, EXTENSION_AUTO_HEADER_IDS, runnerWithRendererParameters(parameters)) + doTestsBlockWithRunner(t, tests, AutoHeaderIDs, runnerWithRendererParameters(parameters)) } func TestPrefixMultipleHeaderExtensions(t *testing.T) {

@@ -427,7 +419,7 @@ var tests = []string{

"# Header\n\n# Header {#header}\n\n# Header 1", "<h1 id=\"header\">Header</h1>\n\n<h1 id=\"header-1\">Header</h1>\n\n<h1 id=\"header-1-1\">Header 1</h1>\n", } - doTestsBlock(t, tests, EXTENSION_AUTO_HEADER_IDS|EXTENSION_HEADER_IDS) + doTestsBlock(t, tests, AutoHeaderIDs|HeaderIDs) } func TestUnderlineHeaders(t *testing.T) {

@@ -527,7 +519,7 @@

"Header 1\n========\n\nHeader 1\n========\n", "<h1 id=\"header-1\">Header 1</h1>\n\n<h1 id=\"header-1-1\">Header 1</h1>\n", } - doTestsBlock(t, tests, EXTENSION_AUTO_HEADER_IDS) + doTestsBlock(t, tests, AutoHeaderIDs) } func TestHorizontalRule(t *testing.T) {

@@ -901,7 +893,7 @@ "<dd><p>Definition b</p></dd>\n" +

"</dl>\n" + "\n<p>Text 2</p>\n", } - doTestsBlock(t, tests, EXTENSION_DEFINITION_LISTS) + doTestsBlock(t, tests, DefinitionLists) } func TestPreformattedHtml(t *testing.T) {

@@ -977,7 +969,7 @@

"Paragraph\n\n<div>\nHow about here? >&<\n</div>\n\nAnd here?\n", "<p>Paragraph</p>\n\n<div>\nHow about here? >&<\n</div>\n\n<p>And here?</p>\n", } - doTestsBlock(t, tests, EXTENSION_LAX_HTML_BLOCKS) + doTestsBlock(t, tests, LaxHTMLBlocks) } func TestFencedCodeBlock(t *testing.T) {

@@ -1063,7 +1055,7 @@

"Some text before a fenced code block\n``` oz\ncode blocks breakup paragraphs\n```\nSome text in between\n``` oz\nmultiple code blocks work okay\n```\nAnd some text after a fenced code block", "<p>Some text before a fenced code block</p>\n\n<pre><code class=\"language-oz\">code blocks breakup paragraphs\n</code></pre>\n\n<p>Some text in between</p>\n\n<pre><code class=\"language-oz\">multiple code blocks work okay\n</code></pre>\n\n<p>And some text after a fenced code block</p>\n", } - doTestsBlock(t, tests, EXTENSION_FENCED_CODE) + doTestsBlock(t, tests, FencedCode) } func TestFencedCodeInsideBlockquotes(t *testing.T) {

@@ -1175,7 +1167,7 @@ `

tests = append(tests, forms[0], want) tests = append(tests, forms[1], want) - doTestsBlock(t, tests, EXTENSION_FENCED_CODE) + doTestsBlock(t, tests, FencedCode) } func TestTable(t *testing.T) {

@@ -1222,7 +1214,7 @@

"a|b\\|c|d\n---|---|---\nf|g\\|h|i\n", "<table>\n<thead>\n<tr>\n<th>a</th>\n<th>b|c</th>\n<th>d</th>\n</tr>\n</thead>\n\n<tbody>\n<tr>\n<td>f</td>\n<td>g|h</td>\n<td>i</td>\n</tr>\n</tbody>\n</table>\n", } - doTestsBlock(t, tests, EXTENSION_TABLES) + doTestsBlock(t, tests, Tables) } func TestUnorderedListWith_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) {

@@ -1333,7 +1325,7 @@

"* List\n\n * sublist\n\n normal text\n\n * another sublist\n", "<ul>\n<li><p>List</p>\n\n<ul>\n<li>sublist</li>\n</ul>\n\n<p>normal text</p>\n\n<ul>\n<li>another sublist</li>\n</ul></li>\n</ul>\n", } - doTestsBlock(t, tests, EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK) + doTestsBlock(t, tests, NoEmptyLineBeforeBlock) } func TestOrderedList_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) {

@@ -1429,7 +1421,7 @@

"1. numbers\n1. are ignored\n", "<ol>\n<li>numbers</li>\n<li>are ignored</li>\n</ol>\n", } - doTestsBlock(t, tests, EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK) + doTestsBlock(t, tests, NoEmptyLineBeforeBlock) } func TestFencedCodeBlock_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) {

@@ -1500,7 +1492,7 @@

" ``` oz\nleading spaces\n ```\n", "<pre><code>``` oz\n</code></pre>\n\n<p>leading spaces</p>\n\n<pre><code>```\n</code></pre>\n", } - doTestsBlock(t, tests, EXTENSION_FENCED_CODE|EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK) + doTestsBlock(t, tests, FencedCode|NoEmptyLineBeforeBlock) } func TestTitleBlock_EXTENSION_TITLEBLOCK(t *testing.T) {

@@ -1514,7 +1506,7 @@ "Another title line\n" +

"Yep, more here too\n" + "</h1>", } - doTestsBlock(t, tests, EXTENSION_TITLEBLOCK) + doTestsBlock(t, tests, Titleblock) } func TestBlockComments(t *testing.T) {
M html.gohtml.go

@@ -79,7 +79,7 @@ // Html is a type that implements the Renderer interface for HTML output.

// // Do not create this directly, instead use the HtmlRenderer function. type Html struct { - flags int // HTML_* options + flags HtmlFlags closeTag string // how to end singleton tags: either " />" or ">" title string // document title css string // optional css file url (used with HTML_COMPLETE_PAGE)

@@ -106,19 +106,19 @@

// HtmlRenderer creates and configures an Html object, which // satisfies the Renderer interface. // -// flags is a set of HTML_* options ORed together. +// flags is a set of HtmlFlags ORed together. // title is the title of the document, and css is a URL for the document's // stylesheet. // title and css are only used when HTML_COMPLETE_PAGE is selected. -func HtmlRenderer(flags int, title string, css string) Renderer { +func HtmlRenderer(flags HtmlFlags, title string, css string) Renderer { return HtmlRendererWithParameters(flags, title, css, HtmlRendererParameters{}) } -func HtmlRendererWithParameters(flags int, title string, +func HtmlRendererWithParameters(flags HtmlFlags, title string, css string, renderParameters HtmlRendererParameters) Renderer { // configure the rendering engine closeTag := htmlClose - if flags&HTML_USE_XHTML != 0 { + if flags&UseXHTML != 0 { closeTag = xhtmlClose }

@@ -190,7 +190,7 @@ }

attrEscape(out, src[end:]) } -func (options *Html) GetFlags() int { +func (options *Html) GetFlags() HtmlFlags { return options.flags }

@@ -206,7 +206,7 @@ func (options *Html) Header(out *bytes.Buffer, text func() bool, level int, id string) {

marker := out.Len() doubleSpace(out) - if id == "" && options.flags&HTML_TOC != 0 { + if id == "" && options.flags&Toc != 0 { id = fmt.Sprintf("toc_%d", options.headerCount) }

@@ -233,7 +233,7 @@ return

} // are we building a table of contents? - if options.flags&HTML_TOC != 0 { + if options.flags&Toc != 0 { options.TocHeaderWithAnchor(out.Bytes()[tocMarker:], level, id) }

@@ -241,7 +241,7 @@ out.WriteString(fmt.Sprintf("</h%d>\n", level))

} func (options *Html) BlockHtml(out *bytes.Buffer, text []byte) { - if options.flags&HTML_SKIP_HTML != 0 { + if options.flags&SkipHTML != 0 { return }

@@ -314,11 +314,11 @@

func (options *Html) TableHeaderCell(out *bytes.Buffer, text []byte, align int) { doubleSpace(out) switch align { - case TABLE_ALIGNMENT_LEFT: + case TableAlignmentLeft: out.WriteString("<th align=\"left\">") - case TABLE_ALIGNMENT_RIGHT: + case TableAlignmentRight: out.WriteString("<th align=\"right\">") - case TABLE_ALIGNMENT_CENTER: + case TableAlignmentCenter: out.WriteString("<th align=\"center\">") default: out.WriteString("<th>")

@@ -331,11 +331,11 @@

func (options *Html) TableCell(out *bytes.Buffer, text []byte, align int) { doubleSpace(out) switch align { - case TABLE_ALIGNMENT_LEFT: + case TableAlignmentLeft: out.WriteString("<td align=\"left\">") - case TABLE_ALIGNMENT_RIGHT: + case TableAlignmentRight: out.WriteString("<td align=\"right\">") - case TABLE_ALIGNMENT_CENTER: + case TableAlignmentCenter: out.WriteString("<td align=\"center\">") default: out.WriteString("<td>")

@@ -348,12 +348,12 @@

func (options *Html) Footnotes(out *bytes.Buffer, text func() bool) { out.WriteString("<div class=\"footnotes\">\n") options.HRule(out) - options.List(out, text, LIST_TYPE_ORDERED) + options.List(out, text, ListTypeOrdered) out.WriteString("</div>\n") } -func (options *Html) FootnoteItem(out *bytes.Buffer, name, text []byte, flags int) { - if flags&LIST_ITEM_CONTAINS_BLOCK != 0 || flags&LIST_ITEM_BEGINNING_OF_LIST != 0 { +func (options *Html) FootnoteItem(out *bytes.Buffer, name, text []byte, flags ListType) { + if flags&ListItemContainsBlock != 0 || flags&ListItemBeginningOfList != 0 { doubleSpace(out) } slug := slugify(name)

@@ -363,7 +363,7 @@ out.WriteString(options.parameters.FootnoteAnchorPrefix)

out.Write(slug) out.WriteString(`">`) out.Write(text) - if options.flags&HTML_FOOTNOTE_RETURN_LINKS != 0 { + if options.flags&FootnoteReturnLinks != 0 { out.WriteString(` <a class="footnote-return" href="#`) out.WriteString(`fnref:`) out.WriteString(options.parameters.FootnoteAnchorPrefix)

@@ -375,13 +375,13 @@ }

out.WriteString("</li>\n") } -func (options *Html) List(out *bytes.Buffer, text func() bool, flags int) { +func (options *Html) List(out *bytes.Buffer, text func() bool, flags ListType) { marker := out.Len() doubleSpace(out) - if flags&LIST_TYPE_DEFINITION != 0 { + if flags&ListTypeDefinition != 0 { out.WriteString("<dl>") - } else if flags&LIST_TYPE_ORDERED != 0 { + } else if flags&ListTypeOrdered != 0 { out.WriteString("<ol>") } else { out.WriteString("<ul>")

@@ -390,31 +390,31 @@ if !text() {

out.Truncate(marker) return } - if flags&LIST_TYPE_DEFINITION != 0 { + if flags&ListTypeDefinition != 0 { out.WriteString("</dl>\n") - } else if flags&LIST_TYPE_ORDERED != 0 { + } else if flags&ListTypeOrdered != 0 { out.WriteString("</ol>\n") } else { out.WriteString("</ul>\n") } } -func (options *Html) ListItem(out *bytes.Buffer, text []byte, flags int) { - if (flags&LIST_ITEM_CONTAINS_BLOCK != 0 && flags&LIST_TYPE_DEFINITION == 0) || - flags&LIST_ITEM_BEGINNING_OF_LIST != 0 { +func (options *Html) ListItem(out *bytes.Buffer, text []byte, flags ListType) { + if (flags&ListItemContainsBlock != 0 && flags&ListTypeDefinition == 0) || + flags&ListItemBeginningOfList != 0 { doubleSpace(out) } - if flags&LIST_TYPE_TERM != 0 { + if flags&ListTypeTerm != 0 { out.WriteString("<dt>") - } else if flags&LIST_TYPE_DEFINITION != 0 { + } else if flags&ListTypeDefinition != 0 { out.WriteString("<dd>") } else { out.WriteString("<li>") } out.Write(text) - if flags&LIST_TYPE_TERM != 0 { + if flags&ListTypeTerm != 0 { out.WriteString("</dt>\n") - } else if flags&LIST_TYPE_DEFINITION != 0 { + } else if flags&ListTypeDefinition != 0 { out.WriteString("</dd>\n") } else { out.WriteString("</li>\n")

@@ -433,9 +433,9 @@ }

out.WriteString("</p>\n") } -func (options *Html) AutoLink(out *bytes.Buffer, link []byte, kind int) { +func (options *Html) AutoLink(out *bytes.Buffer, link []byte, kind LinkType) { skipRanges := htmlEntity.FindAllIndex(link, -1) - if options.flags&HTML_SAFELINK != 0 && !isSafeLink(link) && kind != LINK_TYPE_EMAIL { + if options.flags&Safelink != 0 && !isSafeLink(link) && kind != LinkTypeEmail { // mark it but don't link it if it is not a safe link: no smartypants out.WriteString("<tt>") entityEscapeWithSkip(out, link, skipRanges)

@@ -444,7 +444,7 @@ return

} out.WriteString("<a href=\"") - if kind == LINK_TYPE_EMAIL { + if kind == LinkTypeEmail { out.WriteString("mailto:") } else { options.maybeWriteAbsolutePrefix(out, link)

@@ -453,10 +453,10 @@

entityEscapeWithSkip(out, link, skipRanges) var relAttrs []string - if options.flags&HTML_NOFOLLOW_LINKS != 0 && !isRelativeLink(link) { + if options.flags&NofollowLinks != 0 && !isRelativeLink(link) { relAttrs = append(relAttrs, "nofollow") } - if options.flags&HTML_NOREFERRER_LINKS != 0 && !isRelativeLink(link) { + if options.flags&NoreferrerLinks != 0 && !isRelativeLink(link) { relAttrs = append(relAttrs, "noreferrer") } if len(relAttrs) > 0 {

@@ -464,7 +464,7 @@ out.WriteString(fmt.Sprintf("\" rel=\"%s", strings.Join(relAttrs, " ")))

} // blank target only add to external link - if options.flags&HTML_HREF_TARGET_BLANK != 0 && !isRelativeLink(link) { + if options.flags&HrefTargetBlank != 0 && !isRelativeLink(link) { out.WriteString("\" target=\"_blank") }

@@ -516,7 +516,7 @@ }

} func (options *Html) Image(out *bytes.Buffer, link []byte, title []byte, alt []byte) { - if options.flags&HTML_SKIP_IMAGES != 0 { + if options.flags&SkipImages != 0 { return }

@@ -543,7 +543,7 @@ out.WriteByte('\n')

} func (options *Html) Link(out *bytes.Buffer, link []byte, title []byte, content []byte) { - if options.flags&HTML_SKIP_LINKS != 0 { + if options.flags&SkipLinks != 0 { // write the link text out but don't link it, just mark it with typewriter font out.WriteString("<tt>") attrEscape(out, content)

@@ -551,7 +551,7 @@ out.WriteString("</tt>")

return } - if options.flags&HTML_SAFELINK != 0 && !isSafeLink(link) { + if options.flags&Safelink != 0 && !isSafeLink(link) { // write the link text out but don't link it, just mark it with typewriter font out.WriteString("<tt>") attrEscape(out, content)

@@ -567,10 +567,10 @@ out.WriteString("\" title=\"")

attrEscape(out, title) } var relAttrs []string - if options.flags&HTML_NOFOLLOW_LINKS != 0 && !isRelativeLink(link) { + if options.flags&NofollowLinks != 0 && !isRelativeLink(link) { relAttrs = append(relAttrs, "nofollow") } - if options.flags&HTML_NOREFERRER_LINKS != 0 && !isRelativeLink(link) { + if options.flags&NoreferrerLinks != 0 && !isRelativeLink(link) { relAttrs = append(relAttrs, "noreferrer") } if len(relAttrs) > 0 {

@@ -578,7 +578,7 @@ out.WriteString(fmt.Sprintf("\" rel=\"%s", strings.Join(relAttrs, " ")))

} // blank target only add to external link - if options.flags&HTML_HREF_TARGET_BLANK != 0 && !isRelativeLink(link) { + if options.flags&HrefTargetBlank != 0 && !isRelativeLink(link) { out.WriteString("\" target=\"_blank") }

@@ -589,16 +589,16 @@ return

} func (options *Html) RawHtmlTag(out *bytes.Buffer, text []byte) { - if options.flags&HTML_SKIP_HTML != 0 { + if options.flags&SkipHTML != 0 { return } - if options.flags&HTML_SKIP_STYLE != 0 && isHtmlTag(text, "style") { + if options.flags&SkipStyle != 0 && isHtmlTag(text, "style") { return } - if options.flags&HTML_SKIP_LINKS != 0 && isHtmlTag(text, "a") { + if options.flags&SkipLinks != 0 && isHtmlTag(text, "a") { return } - if options.flags&HTML_SKIP_IMAGES != 0 && isHtmlTag(text, "img") { + if options.flags&SkipImages != 0 && isHtmlTag(text, "img") { return } out.Write(text)

@@ -636,7 +636,7 @@ out.Write(entity)

} func (options *Html) NormalText(out *bytes.Buffer, text []byte) { - if options.flags&HTML_USE_SMARTYPANTS != 0 { + if options.flags&UseSmartypants != 0 { options.Smartypants(out, text) } else { attrEscape(out, text)

@@ -673,12 +673,12 @@ }

} func (options *Html) DocumentHeader(out *bytes.Buffer) { - if options.flags&HTML_COMPLETE_PAGE == 0 { + if options.flags&CompletePage == 0 { return } ending := "" - if options.flags&HTML_USE_XHTML != 0 { + if options.flags&UseXHTML != 0 { out.WriteString("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" ") out.WriteString("\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n") out.WriteString("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n")

@@ -714,7 +714,7 @@ }

func (options *Html) DocumentFooter(out *bytes.Buffer) { // finalize and insert the table of contents - if options.flags&HTML_TOC != 0 { + if options.flags&Toc != 0 { options.TocFinalize() // now we have to insert the table of contents into the document

@@ -727,7 +727,7 @@ // now clear the copied material from the main output buffer

out.Truncate(options.tocMarker) // corner case spacing issue - if options.flags&HTML_COMPLETE_PAGE != 0 { + if options.flags&CompletePage != 0 { out.WriteByte('\n') }

@@ -737,17 +737,17 @@ out.Write(options.toc.Bytes())

out.WriteString("</nav>\n") // corner case spacing issue - if options.flags&HTML_COMPLETE_PAGE == 0 && options.flags&HTML_OMIT_CONTENTS == 0 { + if options.flags&CompletePage == 0 && options.flags&OmitContents == 0 { out.WriteByte('\n') } // write out everything that came after it - if options.flags&HTML_OMIT_CONTENTS == 0 { + if options.flags&OmitContents == 0 { out.Write(temp.Bytes()) } } - if options.flags&HTML_COMPLETE_PAGE != 0 { + if options.flags&CompletePage != 0 { out.WriteString("\n</body>\n") out.WriteString("</html>\n") }
M inline.goinline.go

@@ -168,10 +168,10 @@ out.Truncate(eol)

precededByTwoSpaces := offset >= 2 && data[offset-2] == ' ' && data[offset-1] == ' ' precededByBackslash := offset >= 1 && data[offset-1] == '\\' // see http://spec.commonmark.org/0.18/#example-527 - precededByBackslash = precededByBackslash && p.flags&EXTENSION_BACKSLASH_LINE_BREAK != 0 + precededByBackslash = precededByBackslash && p.flags&BackslashLineBreak != 0 // should there be a hard line break here? - if p.flags&EXTENSION_HARD_LINE_BREAK == 0 && !precededByTwoSpaces && !precededByBackslash { + if p.flags&HardLineBreak == 0 && !precededByTwoSpaces && !precededByBackslash { return 0 }

@@ -209,14 +209,14 @@ var t linkType

switch { // special case: ![^text] == deferred footnote (that follows something with // an exclamation point) - case p.flags&EXTENSION_FOOTNOTES != 0 && len(data)-1 > offset && data[offset+1] == '^': + case p.flags&Footnotes != 0 && len(data)-1 > offset && data[offset+1] == '^': t = linkDeferredFootnote // ![alt] == image case offset > 0 && data[offset-1] == '!': t = linkImg // ^[text] == inline footnote // [^refId] == deferred footnote - case p.flags&EXTENSION_FOOTNOTES != 0: + case p.flags&Footnotes != 0: if offset > 0 && data[offset-1] == '^' { t = linkInlineFootnote } else if len(data)-1 > offset && data[offset+1] == '^' {

@@ -582,13 +582,13 @@

// '<' when tags or autolinks are allowed func leftAngle(p *parser, out *bytes.Buffer, data []byte, offset int) int { data = data[offset:] - altype := LINK_TYPE_NOT_AUTOLINK + altype := LinkTypeNotAutolink end := tagLength(data, &altype) if size := p.inlineHtmlComment(out, data); size > 0 { end = size } if end > 2 { - if altype != LINK_TYPE_NOT_AUTOLINK { + if altype != LinkTypeNotAutolink { var uLink bytes.Buffer unescapeText(&uLink, data[1:end+1-2]) if uLink.Len() > 0 {

@@ -790,7 +790,7 @@ var uLink bytes.Buffer

unescapeText(&uLink, data[:linkEnd]) if uLink.Len() > 0 { - p.r.AutoLink(out, uLink.Bytes(), LINK_TYPE_NORMAL) + p.r.AutoLink(out, uLink.Bytes(), LinkTypeNormal) } return linkEnd - rewind

@@ -826,7 +826,7 @@ return false

} // return the length of the given tag, or 0 is it's not valid -func tagLength(data []byte, autolink *int) int { +func tagLength(data []byte, autolink *LinkType) int { var i, j int // a valid tag can't be shorter than 3 chars

@@ -849,7 +849,7 @@ return 0

} // scheme test - *autolink = LINK_TYPE_NOT_AUTOLINK + *autolink = LinkTypeNotAutolink // try to find the beginning of an URI for i < len(data) && (isalnum(data[i]) || data[i] == '.' || data[i] == '+' || data[i] == '-') {

@@ -858,20 +858,20 @@ }

if i > 1 && i < len(data) && data[i] == '@' { if j = isMailtoAutoLink(data[i:]); j != 0 { - *autolink = LINK_TYPE_EMAIL + *autolink = LinkTypeEmail return i + j } } if i > 2 && i < len(data) && data[i] == ':' { - *autolink = LINK_TYPE_NORMAL + *autolink = LinkTypeNormal i++ } // complete autolink test: no whitespace or ' or " switch { case i >= len(data): - *autolink = LINK_TYPE_NOT_AUTOLINK + *autolink = LinkTypeNotAutolink case *autolink != 0: j = i

@@ -894,7 +894,7 @@ return i + 1

} // one of the forbidden chars has been found - *autolink = LINK_TYPE_NOT_AUTOLINK + *autolink = LinkTypeNotAutolink } // look for something looking like a tag end

@@ -1039,7 +1039,7 @@ }

if data[i] == c && !isspace(data[i-1]) { - if p.flags&EXTENSION_NO_INTRA_EMPHASIS != 0 { + if p.flags&NoIntraEmphasis != 0 { if !(i+1 == len(data) || isspace(data[i+1]) || ispunct(data[i+1])) { continue }
M inline_test.goinline_test.go

@@ -20,11 +20,11 @@

"strings" ) -func runMarkdownInline(input string, opts Options, htmlFlags int, params HtmlRendererParameters) string { - opts.Extensions |= EXTENSION_AUTOLINK - opts.Extensions |= EXTENSION_STRIKETHROUGH +func runMarkdownInline(input string, opts Options, htmlFlags HtmlFlags, params HtmlRendererParameters) string { + opts.Extensions |= Autolink + opts.Extensions |= Strikethrough - htmlFlags |= HTML_USE_XHTML + htmlFlags |= UseXHTML renderer := HtmlRendererWithParameters(htmlFlags, "", "", params)

@@ -46,17 +46,17 @@ doTestsInlineParam(t, transformTests, Options{}, commonHtmlFlags, params)

} func doSafeTestsInline(t *testing.T, tests []string) { - doTestsInlineParam(t, tests, Options{}, HTML_SAFELINK, HtmlRendererParameters{}) + doTestsInlineParam(t, tests, Options{}, Safelink, HtmlRendererParameters{}) // All the links in this test should not have the prefix appended, so // just rerun it with different parameters and the same expectations. prefix := "http://localhost" params := HtmlRendererParameters{AbsolutePrefix: prefix} transformTests := transformLinks(tests, prefix) - doTestsInlineParam(t, transformTests, Options{}, HTML_SAFELINK, params) + doTestsInlineParam(t, transformTests, Options{}, Safelink, params) } -func doTestsInlineParam(t *testing.T, tests []string, opts Options, htmlFlags int, +func doTestsInlineParam(t *testing.T, tests []string, opts Options, htmlFlags HtmlFlags, params HtmlRendererParameters) { // catch and report panics var candidate string

@@ -425,7 +425,7 @@ "this has an \nextra space\n",

"<p>this has an<br />\nextra space</p>\n", } doTestsInlineParam(t, tests, Options{ - Extensions: EXTENSION_BACKSLASH_LINE_BREAK}, + Extensions: BackslashLineBreak}, 0, HtmlRendererParameters{}) }

@@ -566,7 +566,7 @@

"[foo](../bar)\n", "<p><a href=\"../bar\">foo</a></p>\n", } - doTestsInlineParam(t, nofollowTests, Options{}, HTML_SAFELINK|HTML_NOFOLLOW_LINKS, + doTestsInlineParam(t, nofollowTests, Options{}, Safelink|NofollowLinks, HtmlRendererParameters{}) var noreferrerTests = []string{

@@ -576,7 +576,7 @@

"[foo](/bar/)\n", "<p><a href=\"/bar/\">foo</a></p>\n", } - doTestsInlineParam(t, noreferrerTests, Options{}, HTML_SAFELINK|HTML_NOREFERRER_LINKS, + doTestsInlineParam(t, noreferrerTests, Options{}, Safelink|NoreferrerLinks, HtmlRendererParameters{}) var nofollownoreferrerTests = []string{

@@ -586,7 +586,7 @@

"[foo](/bar/)\n", "<p><a href=\"/bar/\">foo</a></p>\n", } - doTestsInlineParam(t, nofollownoreferrerTests, Options{}, HTML_SAFELINK|HTML_NOFOLLOW_LINKS|HTML_NOREFERRER_LINKS, + doTestsInlineParam(t, nofollownoreferrerTests, Options{}, Safelink|NofollowLinks|NoreferrerLinks, HtmlRendererParameters{}) }

@@ -614,7 +614,7 @@

"[foo](http://example.com)\n", "<p><a href=\"http://example.com\" target=\"_blank\">foo</a></p>\n", } - doTestsInlineParam(t, tests, Options{}, HTML_SAFELINK|HTML_HREF_TARGET_BLANK, HtmlRendererParameters{}) + doTestsInlineParam(t, tests, Options{}, Safelink|HrefTargetBlank, HtmlRendererParameters{}) } func TestSafeInlineLink(t *testing.T) {

@@ -988,7 +988,7 @@ `,

} func TestFootnotes(t *testing.T) { - doTestsInlineParam(t, footnoteTests, Options{Extensions: EXTENSION_FOOTNOTES}, 0, HtmlRendererParameters{}) + doTestsInlineParam(t, footnoteTests, Options{Extensions: Footnotes}, 0, HtmlRendererParameters{}) } func TestFootnotesWithParameters(t *testing.T) {

@@ -1013,7 +1013,7 @@ FootnoteAnchorPrefix: prefix,

FootnoteReturnLinkContents: returnText, } - doTestsInlineParam(t, tests, Options{Extensions: EXTENSION_FOOTNOTES}, HTML_FOOTNOTE_RETURN_LINKS, params) + doTestsInlineParam(t, tests, Options{Extensions: Footnotes}, FootnoteReturnLinks, params) } func TestNestedFootnotes(t *testing.T) {

@@ -1039,7 +1039,7 @@ </ol>

</div> `, } - doTestsInlineParam(t, tests, Options{Extensions: EXTENSION_FOOTNOTES}, 0, + doTestsInlineParam(t, tests, Options{Extensions: Footnotes}, 0, HtmlRendererParameters{}) }

@@ -1069,7 +1069,7 @@

"blahblah\n<!--- foo -->\nrhubarb\n", "<p>blahblah\n<!--- foo -->\nrhubarb</p>\n", } - doTestsInlineParam(t, tests, Options{}, HTML_USE_SMARTYPANTS|HTML_SMARTYPANTS_DASHES, HtmlRendererParameters{}) + doTestsInlineParam(t, tests, Options{}, UseSmartypants|SmartypantsDashes, HtmlRendererParameters{}) } func TestSmartDoubleQuotes(t *testing.T) {

@@ -1081,7 +1081,7 @@ "<p>this &ldquo; single double</p>\n",

"two pair of \"some\" quoted \"text\".\n", "<p>two pair of &ldquo;some&rdquo; quoted &ldquo;text&rdquo;.</p>\n"} - doTestsInlineParam(t, tests, Options{}, HTML_USE_SMARTYPANTS, HtmlRendererParameters{}) + doTestsInlineParam(t, tests, Options{}, UseSmartypants, HtmlRendererParameters{}) } func TestSmartAngledDoubleQuotes(t *testing.T) {

@@ -1093,7 +1093,7 @@ "<p>this &laquo; single double</p>\n",

"two pair of \"some\" quoted \"text\".\n", "<p>two pair of &laquo;some&raquo; quoted &laquo;text&raquo;.</p>\n"} - doTestsInlineParam(t, tests, Options{}, HTML_USE_SMARTYPANTS|HTML_SMARTYPANTS_ANGLED_QUOTES, HtmlRendererParameters{}) + doTestsInlineParam(t, tests, Options{}, UseSmartypants|SmartypantsAngledQuotes, HtmlRendererParameters{}) } func TestSmartFractions(t *testing.T) {

@@ -1103,7 +1103,7 @@ "<p>&frac12;, &frac14; and &frac34;; &frac14;th and &frac34;ths</p>\n",

"1/2/2015, 1/4/2015, 3/4/2015; 2015/1/2, 2015/1/4, 2015/3/4.\n", "<p>1/2/2015, 1/4/2015, 3/4/2015; 2015/1/2, 2015/1/4, 2015/3/4.</p>\n"} - doTestsInlineParam(t, tests, Options{}, HTML_USE_SMARTYPANTS, HtmlRendererParameters{}) + doTestsInlineParam(t, tests, Options{}, UseSmartypants, HtmlRendererParameters{}) tests = []string{ "1/2, 2/3, 81/100 and 1000000/1048576.\n",

@@ -1111,7 +1111,7 @@ "<p><sup>1</sup>&frasl;<sub>2</sub>, <sup>2</sup>&frasl;<sub>3</sub>, <sup>81</sup>&frasl;<sub>100</sub> and <sup>1000000</sup>&frasl;<sub>1048576</sub>.</p>\n",

"1/2/2015, 1/4/2015, 3/4/2015; 2015/1/2, 2015/1/4, 2015/3/4.\n", "<p>1/2/2015, 1/4/2015, 3/4/2015; 2015/1/2, 2015/1/4, 2015/3/4.</p>\n"} - doTestsInlineParam(t, tests, Options{}, HTML_USE_SMARTYPANTS|HTML_SMARTYPANTS_FRACTIONS, HtmlRendererParameters{}) + doTestsInlineParam(t, tests, Options{}, UseSmartypants|SmartypantsFractions, HtmlRendererParameters{}) } func TestDisableSmartDashes(t *testing.T) {

@@ -1130,7 +1130,7 @@ "foo -- bar\n",

"<p>foo &mdash; bar</p>\n", "foo --- bar\n", "<p>foo &mdash;&ndash; bar</p>\n", - }, Options{}, HTML_USE_SMARTYPANTS|HTML_SMARTYPANTS_DASHES, HtmlRendererParameters{}) + }, Options{}, UseSmartypants|SmartypantsDashes, HtmlRendererParameters{}) doTestsInlineParam(t, []string{ "foo - bar\n", "<p>foo - bar</p>\n",

@@ -1138,7 +1138,7 @@ "foo -- bar\n",

"<p>foo &ndash; bar</p>\n", "foo --- bar\n", "<p>foo &mdash; bar</p>\n", - }, Options{}, HTML_USE_SMARTYPANTS|HTML_SMARTYPANTS_LATEX_DASHES|HTML_SMARTYPANTS_DASHES, + }, Options{}, UseSmartypants|SmartypantsLatexDashes|SmartypantsDashes, HtmlRendererParameters{}) doTestsInlineParam(t, []string{ "foo - bar\n",

@@ -1148,6 +1148,6 @@ "<p>foo -- bar</p>\n",

"foo --- bar\n", "<p>foo --- bar</p>\n", }, Options{}, - HTML_USE_SMARTYPANTS|HTML_SMARTYPANTS_LATEX_DASHES, + UseSmartypants|SmartypantsLatexDashes, HtmlRendererParameters{}) }
M latex.golatex.go

@@ -34,7 +34,7 @@ func LatexRenderer(flags int) Renderer {

return &Latex{} } -func (options *Latex) GetFlags() int { +func (options *Latex) GetFlags() HtmlFlags { return 0 }

@@ -100,9 +100,9 @@ func (options *Latex) HRule(out *bytes.Buffer) {

out.WriteString("\n\\HRule\n") } -func (options *Latex) List(out *bytes.Buffer, text func() bool, flags int) { +func (options *Latex) List(out *bytes.Buffer, text func() bool, flags ListType) { marker := out.Len() - if flags&LIST_TYPE_ORDERED != 0 { + if flags&ListTypeOrdered != 0 { out.WriteString("\n\\begin{enumerate}\n") } else { out.WriteString("\n\\begin{itemize}\n")

@@ -111,14 +111,14 @@ if !text() {

out.Truncate(marker) return } - if flags&LIST_TYPE_ORDERED != 0 { + if flags&ListTypeOrdered != 0 { out.WriteString("\n\\end{enumerate}\n") } else { out.WriteString("\n\\end{itemize}\n") } } -func (options *Latex) ListItem(out *bytes.Buffer, text []byte, flags int) { +func (options *Latex) ListItem(out *bytes.Buffer, text []byte, flags ListType) { out.WriteString("\n\\item ") out.Write(text) }

@@ -137,9 +137,9 @@ func (options *Latex) Table(out *bytes.Buffer, header []byte, body []byte, columnData []int) {

out.WriteString("\n\\begin{tabular}{") for _, elt := range columnData { switch elt { - case TABLE_ALIGNMENT_LEFT: + case TableAlignmentLeft: out.WriteByte('l') - case TABLE_ALIGNMENT_RIGHT: + case TableAlignmentRight: out.WriteByte('r') default: out.WriteByte('c')

@@ -178,13 +178,13 @@ func (options *Latex) Footnotes(out *bytes.Buffer, text func() bool) {

} -func (options *Latex) FootnoteItem(out *bytes.Buffer, name, text []byte, flags int) { +func (options *Latex) FootnoteItem(out *bytes.Buffer, name, text []byte, flags ListType) { } -func (options *Latex) AutoLink(out *bytes.Buffer, link []byte, kind int) { +func (options *Latex) AutoLink(out *bytes.Buffer, link []byte, kind LinkType) { out.WriteString("\\href{") - if kind == LINK_TYPE_EMAIL { + if kind == LinkTypeEmail { out.WriteString("mailto:") } out.Write(link)
M markdown.gomarkdown.go

@@ -165,19 +165,19 @@ BlockQuote(out *bytes.Buffer, text []byte)

BlockHtml(out *bytes.Buffer, text []byte) Header(out *bytes.Buffer, text func() bool, level int, id string) HRule(out *bytes.Buffer) - List(out *bytes.Buffer, text func() bool, flags int) - ListItem(out *bytes.Buffer, text []byte, flags int) + List(out *bytes.Buffer, text func() bool, flags ListType) + ListItem(out *bytes.Buffer, text []byte, flags ListType) Paragraph(out *bytes.Buffer, text func() bool) Table(out *bytes.Buffer, header []byte, body []byte, columnData []int) TableRow(out *bytes.Buffer, text []byte) TableHeaderCell(out *bytes.Buffer, text []byte, flags int) TableCell(out *bytes.Buffer, text []byte, flags int) Footnotes(out *bytes.Buffer, text func() bool) - FootnoteItem(out *bytes.Buffer, name, text []byte, flags int) + FootnoteItem(out *bytes.Buffer, name, text []byte, flags ListType) TitleBlock(out *bytes.Buffer, text []byte) // Span-level callbacks - AutoLink(out *bytes.Buffer, link []byte, kind int) + AutoLink(out *bytes.Buffer, link []byte, kind LinkType) CodeSpan(out *bytes.Buffer, text []byte) DoubleEmphasis(out *bytes.Buffer, text []byte) Emphasis(out *bytes.Buffer, text []byte)

@@ -197,7 +197,7 @@ // Header and footer

DocumentHeader(out *bytes.Buffer) DocumentFooter(out *bytes.Buffer) - GetFlags() int + GetFlags() HtmlFlags } // Callback functions for inline parsing. One such function is defined

@@ -211,7 +211,7 @@ r Renderer

refOverride ReferenceOverrideFunc refs map[string]*reference inlineCallback [256]inlineParser - flags int // TODO: int ==> Extensions + flags Extensions nesting int maxNesting int insideLink bool

@@ -270,8 +270,8 @@ // Options represents configurable overrides and callbacks (in addition to the

// extension flag set) for configuring a Markdown parse. type Options struct { // Extensions is a flag set of bit-wise ORed extension bits. See the - // EXTENSION_* flags defined in this package. - Extensions int + // Extensions flags defined in this package. + Extensions Extensions // ReferenceOverride is an optional function callback that is called every // time a reference is resolved.

@@ -294,7 +294,7 @@ // MarkdownBasic is a convenience function for simple rendering.

// It processes markdown input with no extensions enabled. func MarkdownBasic(input []byte) []byte { // set up the HTML renderer - htmlFlags := HTML_USE_XHTML + htmlFlags := UseXHTML renderer := HtmlRenderer(htmlFlags, "", "") // set up the parser

@@ -334,7 +334,7 @@ // which non-standard extensions are enabled.

// // To use the supplied Html or LaTeX renderers, see HtmlRenderer and // LatexRenderer, respectively. -func Markdown(input []byte, renderer Renderer, extensions int) []byte { +func Markdown(input []byte, renderer Renderer, extensions Extensions) []byte { return MarkdownOptions(input, renderer, Options{ Extensions: extensions}) }

@@ -361,7 +361,7 @@

// register inline parsers p.inlineCallback['*'] = emphasis p.inlineCallback['_'] = emphasis - if extensions&EXTENSION_STRIKETHROUGH != 0 { + if extensions&Strikethrough != 0 { p.inlineCallback['~'] = emphasis } p.inlineCallback['`'] = codeSpan

@@ -371,11 +371,11 @@ p.inlineCallback['<'] = leftAngle

p.inlineCallback['\\'] = escape p.inlineCallback['&'] = entity - if extensions&EXTENSION_AUTOLINK != 0 { + if extensions&Autolink != 0 { p.inlineCallback[':'] = autoLink } - if extensions&EXTENSION_FOOTNOTES != 0 { + if extensions&Footnotes != 0 { p.notes = make([]*reference, 0) }

@@ -391,9 +391,9 @@ // - normalize newlines

// - copy everything else func firstPass(p *parser, input []byte) []byte { var out bytes.Buffer - tabSize := TAB_SIZE_DEFAULT - if p.flags&EXTENSION_TAB_SIZE_EIGHT != 0 { - tabSize = TAB_SIZE_EIGHT + tabSize := TabSizeDefault + if p.flags&TabSizeEight != 0 { + tabSize = TabSizeDouble } beg, end := 0, 0 lastFencedCodeBlockEnd := 0

@@ -406,7 +406,7 @@ for end < len(input) && input[end] != '\n' && input[end] != '\r' {

end++ } - if p.flags&EXTENSION_FENCED_CODE != 0 { + if p.flags&FencedCode != 0 { // track fenced code block boundaries to suppress tab expansion // inside them: if beg >= lastFencedCodeBlockEnd {

@@ -452,20 +452,20 @@

p.r.DocumentHeader(&output) p.block(&output, input) - if p.flags&EXTENSION_FOOTNOTES != 0 && len(p.notes) > 0 { + if p.flags&Footnotes != 0 && len(p.notes) > 0 { p.r.Footnotes(&output, func() bool { - flags := LIST_ITEM_BEGINNING_OF_LIST + flags := ListItemBeginningOfList for i := 0; i < len(p.notes); i += 1 { ref := p.notes[i] var buf bytes.Buffer if ref.hasBlock { - flags |= LIST_ITEM_CONTAINS_BLOCK + flags |= ListItemContainsBlock p.block(&buf, ref.title) } else { p.inline(&buf, ref.title) } p.r.FootnoteItem(&output, ref.link, buf.Bytes(), flags) - flags &^= LIST_ITEM_BEGINNING_OF_LIST | LIST_ITEM_CONTAINS_BLOCK + flags &^= ListItemBeginningOfList | ListItemContainsBlock } return true

@@ -546,7 +546,7 @@ if data[i] != '[' {

return 0 } i++ - if p.flags&EXTENSION_FOOTNOTES != 0 { + if p.flags&Footnotes != 0 { if i < len(data) && data[i] == '^' { // we can set it to anything here because the proper noteIds will // be assigned later during the second pass. It just has to be != 0

@@ -593,7 +593,7 @@ raw []byte

hasBlock bool ) - if p.flags&EXTENSION_FOOTNOTES != 0 && noteId != 0 { + if p.flags&Footnotes != 0 && noteId != 0 { linkOffset, linkEnd, raw, hasBlock = scanFootnote(p, data, i, tabSize) lineEnd = linkEnd } else {
M ref_test.goref_test.go

@@ -19,12 +19,12 @@ "path/filepath"

"testing" ) -func runMarkdownReference(input string, flag int) string { +func runMarkdownReference(input string, flag Extensions) string { renderer := HtmlRenderer(0, "", "") return string(Markdown([]byte(input), renderer, flag)) } -func doTestsReference(t *testing.T, files []string, flag int) { +func doTestsReference(t *testing.T, files []string, flag Extensions) { // catch and report panics var candidate string defer func() {

@@ -124,5 +124,5 @@ "Strong and em together",

"Tabs", "Tidyness", } - doTestsReference(t, files, EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK) + doTestsReference(t, files, NoEmptyLineBeforeBlock) }
M smartypants.gosmartypants.go

@@ -367,9 +367,9 @@ type smartCallback func(out *bytes.Buffer, smrt *smartypantsData, previousChar byte, text []byte) int

type smartypantsRenderer [256]smartCallback -func smartypants(flags int) *smartypantsRenderer { +func smartypants(flags HtmlFlags) *smartypantsRenderer { r := new(smartypantsRenderer) - if flags&HTML_SMARTYPANTS_ANGLED_QUOTES == 0 { + if flags&SmartypantsAngledQuotes == 0 { r['"'] = smartDoubleQuote r['&'] = smartAmp } else {

@@ -378,15 +378,15 @@ r['&'] = smartAmpAngledQuote

} r['\''] = smartSingleQuote r['('] = smartParens - if flags&HTML_SMARTYPANTS_DASHES != 0 { - if flags&HTML_SMARTYPANTS_LATEX_DASHES == 0 { + if flags&SmartypantsDashes != 0 { + if flags&SmartypantsLatexDashes == 0 { r['-'] = smartDash } else { r['-'] = smartDashLatex } } r['.'] = smartPeriod - if flags&HTML_SMARTYPANTS_FRACTIONS == 0 { + if flags&SmartypantsFractions == 0 { r['1'] = smartNumber r['3'] = smartNumber } else {