diff --git a/block.go b/block.go index b5b0841..281eb99 100644 --- a/block.go +++ b/block.go @@ -63,7 +63,7 @@ func (p *parser) block(out *bytes.Buffer, data []byte) { // % 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 @@ func (p *parser) block(out *bytes.Buffer, data []byte) { // 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 @@ func (p *parser) block(out *bytes.Buffer, data []byte) { // ------|-----|--------- // 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 @@ func (p *parser) block(out *bytes.Buffer, data []byte) { // 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 @@ func (p *parser) block(out *bytes.Buffer, data []byte) { // // 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 @@ func (p *parser) isPrefixHeader(data []byte) bool { 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 @@ func (p *parser) prefixHeader(out *bytes.Buffer, data []byte) int { 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 @@ func (p *parser) prefixHeader(out *bytes.Buffer, data []byte) int { 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 @@ func (p *parser) htmlFindEnd(tag string, data []byte) int { 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 @@ func (p *parser) tableHeader(out *bytes.Buffer, data []byte) (size int, columns if data[i] == ':' { i++ - columns[col] |= TABLE_ALIGNMENT_LEFT + columns[col] |= TableAlignmentLeft dashes++ } for data[i] == '-' { @@ -776,7 +776,7 @@ func (p *parser) tableHeader(out *bytes.Buffer, data []byte) (size int, columns } if data[i] == ':' { i++ - columns[col] |= TABLE_ALIGNMENT_RIGHT + columns[col] |= TableAlignmentRight dashes++ } for data[i] == ' ' { @@ -913,7 +913,7 @@ func (p *parser) quote(out *bytes.Buffer, data []byte) int { // 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 @@ func (p *parser) dliPrefix(data []byte) int { } // 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 @@ func (p *parser) list(out *bytes.Buffer, data []byte, flags int) int { // 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 @@ func (p *parser) listItem(out *bytes.Buffer, data []byte, flags *int) int { 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 @@ gatherlines: 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 @@ gatherlines: // 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 @@ gatherlines: 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 @@ gatherlines: // 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 @@ func (p *parser) paragraph(out *bytes.Buffer, data []byte) int { // 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 @@ func (p *parser) paragraph(out *bytes.Buffer, data []byte) int { }(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 @@ func (p *parser) paragraph(out *bytes.Buffer, data []byte) int { } // 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 @@ func (p *parser) paragraph(out *bytes.Buffer, data []byte) int { } // 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 @@ func (p *parser) paragraph(out *bytes.Buffer, data []byte) int { } // 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 || diff --git a/block_test.go b/block_test.go index b33c257..340e507 100644 --- a/block_test.go +++ b/block_test.go @@ -18,35 +18,27 @@ import ( "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 @@ func TestPrefixHeaderSpaceExtension(t *testing.T) { "\n", } - doTestsBlock(t, tests, EXTENSION_SPACE_HEADERS) + doTestsBlock(t, tests, SpaceHeaders) } func TestPrefixHeaderIdExtension(t *testing.T) { @@ -263,7 +255,7 @@ func TestPrefixHeaderIdExtension(t *testing.T) { "\n", } - doTestsBlock(t, tests, EXTENSION_HEADER_IDS) + doTestsBlock(t, tests, HeaderIDs) } func TestPrefixHeaderIdExtensionWithPrefixAndSuffix(t *testing.T) { @@ -311,7 +303,7 @@ func TestPrefixHeaderIdExtensionWithPrefixAndSuffix(t *testing.T) { 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 @@ func TestPrefixAutoHeaderIdExtension(t *testing.T) { "# Header\n\n# Header 1\n\n# Header\n\n# Header", "

Header

\n\n

Header 1

\n\n

Header

\n\n

Header

\n", } - doTestsBlock(t, tests, EXTENSION_AUTO_HEADER_IDS) + doTestsBlock(t, tests, AutoHeaderIDs) } func TestPrefixAutoHeaderIdExtensionWithPrefixAndSuffix(t *testing.T) { @@ -419,7 +411,7 @@ func TestPrefixAutoHeaderIdExtensionWithPrefixAndSuffix(t *testing.T) { 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 @@ func TestPrefixMultipleHeaderExtensions(t *testing.T) { "# Header\n\n# Header {#header}\n\n# Header 1", "

Header

\n\n

Header

\n\n

Header 1

\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 @@ func TestUnderlineHeadersAutoIDs(t *testing.T) { "Header 1\n========\n\nHeader 1\n========\n", "

Header 1

\n\n

Header 1

\n", } - doTestsBlock(t, tests, EXTENSION_AUTO_HEADER_IDS) + doTestsBlock(t, tests, AutoHeaderIDs) } func TestHorizontalRule(t *testing.T) { @@ -901,7 +893,7 @@ func TestDefinitionList(t *testing.T) { "\n" + "\n

Text 2

\n", } - doTestsBlock(t, tests, EXTENSION_DEFINITION_LISTS) + doTestsBlock(t, tests, DefinitionLists) } func TestPreformattedHtml(t *testing.T) { @@ -977,7 +969,7 @@ func TestPreformattedHtmlLax(t *testing.T) { "Paragraph\n\n
\nHow about here? >&<\n
\n\nAnd here?\n", "

Paragraph

\n\n
\nHow about here? >&<\n
\n\n

And here?

\n", } - doTestsBlock(t, tests, EXTENSION_LAX_HTML_BLOCKS) + doTestsBlock(t, tests, LaxHTMLBlocks) } func TestFencedCodeBlock(t *testing.T) { @@ -1063,7 +1055,7 @@ func TestFencedCodeBlock(t *testing.T) { "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", "

Some text before a fenced code block

\n\n
code blocks breakup paragraphs\n
\n\n

Some text in between

\n\n
multiple code blocks work okay\n
\n\n

And some text after a fenced code block

\n", } - doTestsBlock(t, tests, EXTENSION_FENCED_CODE) + doTestsBlock(t, tests, FencedCode) } func TestFencedCodeInsideBlockquotes(t *testing.T) { @@ -1175,7 +1167,7 @@ okay 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 @@ func TestTable(t *testing.T) { "a|b\\|c|d\n---|---|---\nf|g\\|h|i\n", "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
ab|cd
fg|hi
\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 @@ func TestUnorderedListWith_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) { "* List\n\n * sublist\n\n normal text\n\n * another sublist\n", "\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 @@ func TestOrderedList_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) { "1. numbers\n1. are ignored\n", "
    \n
  1. numbers
  2. \n
  3. are ignored
  4. \n
\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 @@ func TestFencedCodeBlock_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) { " ``` oz\nleading spaces\n ```\n", "
``` oz\n
\n\n

leading spaces

\n\n
```\n
\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 @@ func TestTitleBlock_EXTENSION_TITLEBLOCK(t *testing.T) { "Yep, more here too\n" + "", } - doTestsBlock(t, tests, EXTENSION_TITLEBLOCK) + doTestsBlock(t, tests, Titleblock) } func TestBlockComments(t *testing.T) { diff --git a/html.go b/html.go index 7d37183..d4c7efb 100644 --- a/html.go +++ b/html.go @@ -79,7 +79,7 @@ type HtmlRendererParameters struct { // // 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 @@ const ( // 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 @@ func entityEscapeWithSkip(out *bytes.Buffer, src []byte, skipRanges [][]int) { 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 s 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 @@ func (options *Html) Header(out *bytes.Buffer, text func() bool, level int, id s } // 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 @@ func (options *Html) Header(out *bytes.Buffer, text func() bool, level int, id s } 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) TableRow(out *bytes.Buffer, text []byte) { func (options *Html) TableHeaderCell(out *bytes.Buffer, text []byte, align int) { doubleSpace(out) switch align { - case TABLE_ALIGNMENT_LEFT: + case TableAlignmentLeft: out.WriteString("") - case TABLE_ALIGNMENT_RIGHT: + case TableAlignmentRight: out.WriteString("") - case TABLE_ALIGNMENT_CENTER: + case TableAlignmentCenter: out.WriteString("") default: out.WriteString("") @@ -331,11 +331,11 @@ func (options *Html) TableHeaderCell(out *bytes.Buffer, text []byte, align int) func (options *Html) TableCell(out *bytes.Buffer, text []byte, align int) { doubleSpace(out) switch align { - case TABLE_ALIGNMENT_LEFT: + case TableAlignmentLeft: out.WriteString("") - case TABLE_ALIGNMENT_RIGHT: + case TableAlignmentRight: out.WriteString("") - case TABLE_ALIGNMENT_CENTER: + case TableAlignmentCenter: out.WriteString("") default: out.WriteString("") @@ -348,12 +348,12 @@ func (options *Html) TableCell(out *bytes.Buffer, text []byte, align int) { func (options *Html) Footnotes(out *bytes.Buffer, text func() bool) { out.WriteString("
\n") options.HRule(out) - options.List(out, text, LIST_TYPE_ORDERED) + options.List(out, text, ListTypeOrdered) out.WriteString("
\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 @@ func (options *Html) FootnoteItem(out *bytes.Buffer, name, text []byte, flags in out.Write(slug) out.WriteString(`">`) out.Write(text) - if options.flags&HTML_FOOTNOTE_RETURN_LINKS != 0 { + if options.flags&FootnoteReturnLinks != 0 { out.WriteString(` \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("
") - } else if flags&LIST_TYPE_ORDERED != 0 { + } else if flags&ListTypeOrdered != 0 { out.WriteString("
    ") } else { out.WriteString("
      ") @@ -390,31 +390,31 @@ func (options *Html) List(out *bytes.Buffer, text func() bool, flags int) { out.Truncate(marker) return } - if flags&LIST_TYPE_DEFINITION != 0 { + if flags&ListTypeDefinition != 0 { out.WriteString("
\n") - } else if flags&LIST_TYPE_ORDERED != 0 { + } else if flags&ListTypeOrdered != 0 { out.WriteString("\n") } else { out.WriteString("\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("
") - } else if flags&LIST_TYPE_DEFINITION != 0 { + } else if flags&ListTypeDefinition != 0 { out.WriteString("
") } else { out.WriteString("
  • ") } out.Write(text) - if flags&LIST_TYPE_TERM != 0 { + if flags&ListTypeTerm != 0 { out.WriteString("\n") - } else if flags&LIST_TYPE_DEFINITION != 0 { + } else if flags&ListTypeDefinition != 0 { out.WriteString("
  • \n") } else { out.WriteString("\n") @@ -433,9 +433,9 @@ func (options *Html) Paragraph(out *bytes.Buffer, text func() bool) { out.WriteString("

    \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("") entityEscapeWithSkip(out, link, skipRanges) @@ -444,7 +444,7 @@ func (options *Html) AutoLink(out *bytes.Buffer, link []byte, kind int) { } out.WriteString("
    0 { @@ -464,7 +464,7 @@ func (options *Html) AutoLink(out *bytes.Buffer, link []byte, kind int) { } // 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) maybeWriteAbsolutePrefix(out *bytes.Buffer, link []byte) { } 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 @@ func (options *Html) LineBreak(out *bytes.Buffer) { } 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("") attrEscape(out, content) @@ -551,7 +551,7 @@ func (options *Html) Link(out *bytes.Buffer, link []byte, title []byte, content 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("") attrEscape(out, content) @@ -567,10 +567,10 @@ func (options *Html) Link(out *bytes.Buffer, link []byte, title []byte, content 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 @@ func (options *Html) Link(out *bytes.Buffer, link []byte, title []byte, content } // 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 @@ func (options *Html) Link(out *bytes.Buffer, link []byte, title []byte, content } 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 @@ func (options *Html) Entity(out *bytes.Buffer, entity []byte) { } 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) Smartypants(out *bytes.Buffer, text []byte) { } 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("\n") out.WriteString("\n") @@ -714,7 +714,7 @@ func (options *Html) DocumentHeader(out *bytes.Buffer) { 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 @@ func (options *Html) DocumentFooter(out *bytes.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 @@ func (options *Html) DocumentFooter(out *bytes.Buffer) { out.WriteString("\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\n") out.WriteString("\n") } diff --git a/inline.go b/inline.go index a28bb66..39947df 100644 --- a/inline.go +++ b/inline.go @@ -168,10 +168,10 @@ func lineBreak(p *parser, out *bytes.Buffer, data []byte, offset int) int { 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 @@ func link(p *parser, out *bytes.Buffer, data []byte, offset int) int { 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 @@ func (p *parser) inlineHtmlComment(out *bytes.Buffer, data []byte) int { // '<' 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 @@ func autoLink(p *parser, out *bytes.Buffer, data []byte, offset int) int { 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 @@ func isSafeLink(link []byte) bool { } // 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 @@ func tagLength(data []byte, autolink *int) int { } // 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 @@ func tagLength(data []byte, autolink *int) int { 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 @@ func tagLength(data []byte, autolink *int) int { } // 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 @@ func helperEmphasis(p *parser, out *bytes.Buffer, data []byte, c byte) int { 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 } diff --git a/inline_test.go b/inline_test.go index d793e01..ae16b34 100644 --- a/inline_test.go +++ b/inline_test.go @@ -20,11 +20,11 @@ import ( "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 @@ func doLinkTestsInline(t *testing.T, tests []string) { } 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 @@ func TestLineBreak(t *testing.T) { "

    this has an
    \nextra space

    \n", } doTestsInlineParam(t, tests, Options{ - Extensions: EXTENSION_BACKSLASH_LINE_BREAK}, + Extensions: BackslashLineBreak}, 0, HtmlRendererParameters{}) } @@ -566,7 +566,7 @@ func TestRelAttrLink(t *testing.T) { "[foo](../bar)\n", "

    foo

    \n", } - doTestsInlineParam(t, nofollowTests, Options{}, HTML_SAFELINK|HTML_NOFOLLOW_LINKS, + doTestsInlineParam(t, nofollowTests, Options{}, Safelink|NofollowLinks, HtmlRendererParameters{}) var noreferrerTests = []string{ @@ -576,7 +576,7 @@ func TestRelAttrLink(t *testing.T) { "[foo](/bar/)\n", "

    foo

    \n", } - doTestsInlineParam(t, noreferrerTests, Options{}, HTML_SAFELINK|HTML_NOREFERRER_LINKS, + doTestsInlineParam(t, noreferrerTests, Options{}, Safelink|NoreferrerLinks, HtmlRendererParameters{}) var nofollownoreferrerTests = []string{ @@ -586,7 +586,7 @@ func TestRelAttrLink(t *testing.T) { "[foo](/bar/)\n", "

    foo

    \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 @@ func TestHrefTargetBlank(t *testing.T) { "[foo](http://example.com)\n", "

    foo

    \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 @@ what happens here } 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 @@ func TestFootnotesWithParameters(t *testing.T) { 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 @@ func TestNestedFootnotes(t *testing.T) { `, } - doTestsInlineParam(t, tests, Options{Extensions: EXTENSION_FOOTNOTES}, 0, + doTestsInlineParam(t, tests, Options{Extensions: Footnotes}, 0, HtmlRendererParameters{}) } @@ -1069,7 +1069,7 @@ func TestInlineComments(t *testing.T) { "blahblah\n\nrhubarb\n", "

    blahblah\n\nrhubarb

    \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 @@ func TestSmartDoubleQuotes(t *testing.T) { "two pair of \"some\" quoted \"text\".\n", "

    two pair of “some” quoted “text”.

    \n"} - doTestsInlineParam(t, tests, Options{}, HTML_USE_SMARTYPANTS, HtmlRendererParameters{}) + doTestsInlineParam(t, tests, Options{}, UseSmartypants, HtmlRendererParameters{}) } func TestSmartAngledDoubleQuotes(t *testing.T) { @@ -1093,7 +1093,7 @@ func TestSmartAngledDoubleQuotes(t *testing.T) { "two pair of \"some\" quoted \"text\".\n", "

    two pair of «some» quoted «text».

    \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 @@ func TestSmartFractions(t *testing.T) { "1/2/2015, 1/4/2015, 3/4/2015; 2015/1/2, 2015/1/4, 2015/3/4.\n", "

    1/2/2015, 1/4/2015, 3/4/2015; 2015/1/2, 2015/1/4, 2015/3/4.

    \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 @@ func TestSmartFractions(t *testing.T) { "1/2/2015, 1/4/2015, 3/4/2015; 2015/1/2, 2015/1/4, 2015/3/4.\n", "

    1/2/2015, 1/4/2015, 3/4/2015; 2015/1/2, 2015/1/4, 2015/3/4.

    \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 @@ func TestDisableSmartDashes(t *testing.T) { "

    foo — bar

    \n", "foo --- bar\n", "

    foo —– bar

    \n", - }, Options{}, HTML_USE_SMARTYPANTS|HTML_SMARTYPANTS_DASHES, HtmlRendererParameters{}) + }, Options{}, UseSmartypants|SmartypantsDashes, HtmlRendererParameters{}) doTestsInlineParam(t, []string{ "foo - bar\n", "

    foo - bar

    \n", @@ -1138,7 +1138,7 @@ func TestDisableSmartDashes(t *testing.T) { "

    foo – bar

    \n", "foo --- bar\n", "

    foo — bar

    \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 @@ func TestDisableSmartDashes(t *testing.T) { "foo --- bar\n", "

    foo --- bar

    \n", }, Options{}, - HTML_USE_SMARTYPANTS|HTML_SMARTYPANTS_LATEX_DASHES, + UseSmartypants|SmartypantsLatexDashes, HtmlRendererParameters{}) } diff --git a/latex.go b/latex.go index 70705aa..5c334b0 100644 --- a/latex.go +++ b/latex.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 @@ func (options *Latex) List(out *bytes.Buffer, text func() bool, flags int) { 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, colum 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) diff --git a/markdown.go b/markdown.go index 33acf9e..439b577 100644 --- a/markdown.go +++ b/markdown.go @@ -165,19 +165,19 @@ type Renderer interface { 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 @@ type Renderer interface { 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 @@ type parser struct { 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 @@ type ReferenceOverrideFunc func(reference string) (ref *Reference, overridden bo // 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 @@ type Options struct { // 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 @@ func MarkdownCommon(input []byte) []byte { // // 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 @@ func MarkdownOptions(input []byte, renderer Renderer, opts Options) []byte { // 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 @@ func MarkdownOptions(input []byte, renderer Renderer, opts Options) []byte { 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 @@ func MarkdownOptions(input []byte, renderer Renderer, opts Options) []byte { // - 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 @@ func firstPass(p *parser, input []byte) []byte { 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 @@ func secondPass(p *parser, input []byte) []byte { 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 @@ func isReference(p *parser, data []byte, tabSize int) int { 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 @@ func isReference(p *parser, data []byte, tabSize int) int { 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 { diff --git a/ref_test.go b/ref_test.go index 770439c..6d4a628 100644 --- a/ref_test.go +++ b/ref_test.go @@ -19,12 +19,12 @@ import ( "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 @@ func TestReference_EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK(t *testing.T) { "Tabs", "Tidyness", } - doTestsReference(t, files, EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK) + doTestsReference(t, files, NoEmptyLineBeforeBlock) } diff --git a/smartypants.go b/smartypants.go index eeffa5e..64cf2c5 100644 --- a/smartypants.go +++ b/smartypants.go @@ -367,9 +367,9 @@ type smartCallback func(out *bytes.Buffer, smrt *smartypantsData, previousChar b 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 @@ func smartypants(flags int) *smartypantsRenderer { } 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 {