Skip to content

Commit

Permalink
Fixes #31
Browse files Browse the repository at this point in the history
  • Loading branch information
yuin committed Nov 19, 2019
1 parent c8c3b41 commit 9dec7e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 9 additions & 0 deletions _test/options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,12 @@
<h2 id="id_7" attr7="value &quot;7">Title7</h2>
<h2 id="id" class="className class1 class2" attrName="attrValue">Title8</h2>
//= = = = = = = = = = = = = = = = = = = = = = = =//

2
//- - - - - - - - -//
#
# FOO
//- - - - - - - - -//
<h1 id="heading"></h1>
<h1 id="foo">FOO</h1>
//= = = = = = = = = = = = = = = = = = = = = = = =//
10 changes: 8 additions & 2 deletions parser/atx_heading.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,21 @@ func (b *atxHeadingParser) CanAcceptIndentedLine() bool {
var attrAutoHeadingIDPrefix = []byte("heading")

func generateAutoHeadingID(node *ast.Heading, reader text.Reader, pc Context) {
var line []byte
lastIndex := node.Lines().Len() - 1
lastLine := node.Lines().At(lastIndex)
line := lastLine.Value(reader.Source())
if lastIndex > -1 {
lastLine := node.Lines().At(lastIndex)
line = lastLine.Value(reader.Source())
}
headingID := pc.IDs().Generate(line, attrAutoHeadingIDPrefix)
node.SetAttribute(attrNameID, headingID)
}

func parseLastLineAttributes(node ast.Node, reader text.Reader, pc Context) {
lastIndex := node.Lines().Len() - 1
if lastIndex < 0 { // empty headings
return
}
lastLine := node.Lines().At(lastIndex)
line := lastLine.Value(reader.Source())
lr := text.NewReader(line)
Expand Down

0 comments on commit 9dec7e9

Please sign in to comment.