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

Accept ... as frontmatter terminator (pandoc syntax) #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,24 @@ func NewParser() parser.BlockParser {
return defaultParser
}

func isSeparator(line []byte) bool {
line = util.TrimRightSpace(util.TrimLeftSpace(line))
func isStartSeparator(line []byte) bool {
line = util.TrimRightSpace(line)
for i := 0; i < len(line); i++ {
if line[i] != '-' {
return false
}
}
return true
return len(line) >= 3
}

func isEndSeparator(line []byte) bool {
line = util.TrimRightSpace(line)
for i := 0; i < len(line); i++ {
if line[i] != '-' && line[i] != '.' {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to accept -.- or ..- ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if line[0] != '-' || line[0] != '.' { return false }
for i := 1 ... {
    if line[i] != line[0] { return false }
}

return false
}
}
return len(line) >= 3
}

func (b *metaParser) Trigger() []byte {
Expand All @@ -112,15 +122,15 @@ func (b *metaParser) Open(parent gast.Node, reader text.Reader, pc parser.Contex
return nil, parser.NoChildren
}
line, _ := reader.PeekLine()
if isSeparator(line) {
if isStartSeparator(line) {
return gast.NewTextBlock(), parser.NoChildren
}
return nil, parser.NoChildren
}

func (b *metaParser) Continue(node gast.Node, reader text.Reader, pc parser.Context) parser.State {
line, segment := reader.PeekLine()
if isSeparator(line) && !util.IsBlank(line) {
if isEndSeparator(line) && !util.IsBlank(line) {
reader.Advance(segment.Len())
return parser.Close
}
Expand Down