This commit is contained in:
yuin 2019-11-20 01:10:18 +09:00
parent c8c3b41fe0
commit 9dec7e9e8b
2 changed files with 17 additions and 2 deletions

View file

@ -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>
//= = = = = = = = = = = = = = = = = = = = = = = =//

View file

@ -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)