all repos — grayfriday @ 539b27a6242239ab88f86e8756318cfc9b28ee74

blackfriday fork with a few changes

Add titleblock support
Brian Goff cpuguy83@gmail.com
Fri, 01 Aug 2014 22:54:21 -0400
commit

539b27a6242239ab88f86e8756318cfc9b28ee74

parent

8b4c144eda8ddf733c630ccfab254dbc5d672b3f

5 files changed, 66 insertions(+), 5 deletions(-)

jump to
M block.goblock.go

@@ -13,9 +13,7 @@ //

package blackfriday -import ( - "bytes" -) +import "bytes" // Parse block-level data. // Note: this function and many that it calls assume that

@@ -53,6 +51,20 @@ if data[0] == '<' {

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

@@ -190,13 +202,13 @@ id := ""

if p.flags&EXTENSION_HEADER_IDS != 0 { j, k := 0, 0 // find start/end of header id - for j = i; j < end - 1 && (data[j] != '{' || data[j+1] != '#'); j++ { + for j = i; j < end-1 && (data[j] != '{' || data[j+1] != '#'); j++ { } for k = j + 1; k < end && data[k] != '}'; k++ { } // extract header id iff found if j < end && k < end { - id = string(data[j+2:k]) + id = string(data[j+2 : k]) end = j skip = k + 1 for end > 0 && data[end-1] == ' ' {

@@ -254,6 +266,25 @@ }

} return 0 +} + +func (p *parser) titleBlock(out *bytes.Buffer, data []byte, doRender bool) int { + if data[0] != '%' { + return 0 + } + splitData := bytes.Split(data, []byte("\n")) + var i int + for idx, b := range splitData { + if !bytes.HasPrefix(b, []byte("%")) { + i = idx // - 1 + break + } + } + + data = bytes.Join(splitData[0:i], []byte("\n")) + p.r.TitleBlock(out, data) + + return len(data) } func (p *parser) html(out *bytes.Buffer, data []byte, doRender bool) int {
M block_test.goblock_test.go

@@ -1045,3 +1045,19 @@ "<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) } + +func TestTitleBlock_EXTENSION_TITLEBLOCK(t *testing.T) { + var tests = []string{ + "% Some title\n" + + "% Another title line\n" + + "% Yep, more here too\n", + "<h1 class=\"title\">" + + "Some title\n" + + "Another title line\n" + + "Yep, more here too\n" + + "</h1>", + } + + doTestsBlock(t, tests, EXTENSION_TITLEBLOCK) + +}
M html.gohtml.go

@@ -180,6 +180,14 @@ func (options *Html) GetFlags() int {

return options.flags } +func (options *Html) TitleBlock(out *bytes.Buffer, text []byte) { + text = bytes.TrimPrefix(text, []byte("% ")) + text = bytes.Replace(text, []byte("\n% "), []byte("\n"), -1) + out.WriteString("<h1 class=\"title\">") + out.Write(text) + out.WriteString("\n</h1>") +} + func (options *Html) Header(out *bytes.Buffer, text func() bool, level int, id string) { marker := out.Len() doubleSpace(out)
M latex.golatex.go

@@ -55,6 +55,10 @@ out.WriteString("\n\\end{lstlisting}\n")

} } +func (options *Latex) TitleBlock(out *bytes.Buffer, text []byte) { + +} + func (options *Latex) BlockQuote(out *bytes.Buffer, text []byte) { out.WriteString("\n\\begin{quotation}\n") out.Write(text)
M markdown.gomarkdown.go

@@ -40,6 +40,7 @@ EXTENSION_TAB_SIZE_EIGHT // expand tabs to eight spaces instead of four

EXTENSION_FOOTNOTES // Pandoc-style footnotes EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK // No need to insert an empty line to start a (code, quote, order list, unorder list)block EXTENSION_HEADER_IDS // specify header IDs with {#id} + EXTENSION_TITLEBLOCK // Titleblock ala pandoc ) // These are the possible flag values for the link renderer.

@@ -145,6 +146,7 @@ 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) + TitleBlock(out *bytes.Buffer, text []byte) // Span-level callbacks AutoLink(out *bytes.Buffer, link []byte, kind int)