Skip to content
This repository has been archived by the owner on Nov 10, 2020. It is now read-only.

Commit

Permalink
Only check for TOML block at the start
Browse files Browse the repository at this point in the history
When we already outputted something, stop checking for the TOML block.
We take special care to check if the header is outputted already,
because that is the *only* element that does not need syntax to be
outputted.
  • Loading branch information
miekg committed May 14, 2016
1 parent 1554c5e commit 8560dc9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 10 additions & 7 deletions block.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ func (p *parser) block(out *bytes.Buffer, data []byte) {
if p.flags&EXTENSION_TITLEBLOCK_TOML != 0 && len(data) > 2 {
// only one % at the left
if data[0] == '%' && data[1] != '%' {
if i := p.titleBlock(out, data, true); i > 0 {
data = data[i:]
continue
if out.Len() <= p.headerLen {
if i := p.titleBlock(out, data, true); i > 0 {
data = data[i:]
continue
}
}
}
}
Expand All @@ -99,11 +101,12 @@ func (p *parser) block(out *bytes.Buffer, data []byte) {
// %%%
if p.flags&EXTENSION_TITLEBLOCK_TOML != 0 && len(data) > 3 {
if data[0] == '%' && data[1] == '%' && data[2] == '%' {
if i := p.titleBlockBlock(out, data, true); i > 0 {
data = data[i:]
continue
if out.Len() <= p.headerLen {
if i := p.titleBlockBlock(out, data, true); i > 0 {
data = data[i:]
continue
}
}

}
}

Expand Down
2 changes: 2 additions & 0 deletions markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ type parser struct {

appendix bool // have we seen a {backmatter}?
titleblock bool // have we seen a titleblock
headerLen int // if a header is written what is length

partCount int // TODO, keep track of part counts (-#)
chapterCount int // TODO, keep track of chapter count (#)
Expand Down Expand Up @@ -468,6 +469,7 @@ func secondPass(p *parser, input []byte, depth int) *bytes.Buffer {
var output bytes.Buffer

p.r.DocumentHeader(&output, depth == 0)
p.headerLen = output.Len()
p.block(&output, input)

if p.flags&EXTENSION_FOOTNOTES != 0 && len(p.notes) > 0 {
Expand Down

0 comments on commit 8560dc9

Please sign in to comment.