Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 146 #161

Merged
merged 2 commits into from May 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 14 additions & 35 deletions block.go
Expand Up @@ -196,11 +196,8 @@ func (p *parser) prefixHeader(out *bytes.Buffer, data []byte) int {
for level < 6 && data[level] == '#' {
level++
}
i, end := 0, 0
for i = level; data[i] == ' '; i++ {
}
for end = i; data[end] != '\n'; end++ {
}
i := skipChar(data, level, ' ')
end := skipUntilChar(data, i, '\n')
skip := end
id := ""
if p.flags&EXTENSION_HEADER_IDS != 0 {
Expand All @@ -221,6 +218,9 @@ func (p *parser) prefixHeader(out *bytes.Buffer, data []byte) int {
}
}
for end > 0 && data[end-1] == '#' {
if isBackslashEscaped(data, end-1) {
break
}
end--
}
for end > 0 && data[end-1] == ' ' {
Expand All @@ -242,13 +242,8 @@ func (p *parser) prefixHeader(out *bytes.Buffer, data []byte) int {
func (p *parser) isUnderlinedHeader(data []byte) int {
// test of level 1 header
if data[0] == '=' {
i := 1
for data[i] == '=' {
i++
}
for data[i] == ' ' {
i++
}
i := skipChar(data, 1, '=')
i = skipChar(data, i, ' ')
if data[i] == '\n' {
return 1
} else {
Expand All @@ -258,13 +253,8 @@ func (p *parser) isUnderlinedHeader(data []byte) int {

// test of level 2 header
if data[0] == '-' {
i := 1
for data[i] == '-' {
i++
}
for data[i] == ' ' {
i++
}
i := skipChar(data, 1, '-')
i = skipChar(data, i, ' ')
if data[i] == '\n' {
return 2
} else {
Expand Down Expand Up @@ -593,10 +583,7 @@ func (p *parser) isFencedCode(data []byte, syntax **string, oldmarker string) (s

if syntax != nil {
syn := 0

for i < len(data) && data[i] == ' ' {
i++
}
i = skipChar(data, i, ' ')

if i >= len(data) {
return
Expand Down Expand Up @@ -640,9 +627,7 @@ func (p *parser) isFencedCode(data []byte, syntax **string, oldmarker string) (s
*syntax = &language
}

for i < len(data) && data[i] == ' ' {
i++
}
i = skipChar(data, i, ' ')
if i >= len(data) || data[i] != '\n' {
return
}
Expand Down Expand Up @@ -671,11 +656,7 @@ func (p *parser) fencedCode(out *bytes.Buffer, data []byte, doRender bool) int {
}

// copy the current line
end := beg
for end < len(data) && data[end] != '\n' {
end++
}
end++
end := skipUntilChar(data, beg, '\n') + 1

// did we reach the end of the buffer without a closing marker?
if end >= len(data) {
Expand Down Expand Up @@ -733,7 +714,7 @@ func (p *parser) table(out *bytes.Buffer, data []byte) int {
return i
}

// check if the specified position is preceeded by an odd number of backslashes
// check if the specified position is preceded by an odd number of backslashes
func isBackslashEscaped(data []byte, i int) bool {
backslashes := 0
for i-backslashes-1 >= 0 && data[i-backslashes-1] == '\\' {
Expand Down Expand Up @@ -778,9 +759,7 @@ func (p *parser) tableHeader(out *bytes.Buffer, data []byte) (size int, columns
if data[i] == '|' && !isBackslashEscaped(data, i) {
i++
}
for data[i] == ' ' {
i++
}
i = skipChar(data, i, ' ')

// each column header is of form: / *:?-+:? *|/ with # dashes + # colons >= 3
// and trailing | optional on last column
Expand Down
9 changes: 9 additions & 0 deletions block_test.go
Expand Up @@ -132,6 +132,15 @@ func TestPrefixHeaderNoExtensions(t *testing.T) {
"* 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",

"#Header 1 \\#\n",
"<h1>Header 1 #</h1>\n",

"#Header 1 \\# foo\n",
"<h1>Header 1 # foo</h1>\n",

"#Header 1 #\\##\n",
"<h1>Header 1 ##</h1>\n",
}
doTestsBlock(t, tests, 0)
}
Expand Down
8 changes: 8 additions & 0 deletions html.go
Expand Up @@ -867,6 +867,14 @@ func skipSpace(tag []byte, i int) int {
return i
}

func skipChar(data []byte, start int, char byte) int {
i := start
for i < len(data) && data[i] == char {
i++
}
return i
}

func doubleSpace(out *bytes.Buffer) {
if out.Len() > 0 {
out.WriteByte('\n')
Expand Down