Also support header IDs in ## headers ##
Dave Johnston johnsto@gmail.com
Sun, 06 Apr 2014 10:30:40 +0100
2 files changed,
12 insertions(+),
1 deletions(-)
M
block.go
→
block.go
@@ -189,14 +189,19 @@ skip := end
id := "" if p.flags&EXTENSION_HEADER_IDS != 0 { j, k := 0, 0 - for j = i; j < end - 1 && data[j] != '{' && data[j+1] != '#'; j++ { + // find start/end of header id + 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]) end = j skip = k + 1 + for end > 0 && data[end-1] == ' ' { + end-- + } } } for end > 0 && data[end-1] == '#' {
M
block_test.go
→
block_test.go
@@ -215,6 +215,12 @@
"####### Header 7 {#someid}\n", "<h6 id=\"someid\"># Header 7</h6>\n", + "# Header 1 # {#someid}\n", + "<h1 id=\"someid\">Header 1</h1>\n", + + "## Header 2 ## {#someid}\n", + "<h2 id=\"someid\">Header 2</h2>\n", + "Hello\n# Header 1\nGoodbye\n", "<p>Hello</p>\n\n<h1>Header 1</h1>\n\n<p>Goodbye</p>\n",