markup: Add typographic chars from goldmark to toc
authorDaniel Tang <tangd@google.com>
Tue, 10 Dec 2019 20:37:52 +0000 (12:37 -0800)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 10 Dec 2019 22:48:44 +0000 (23:48 +0100)
Fixes #6592

markup/goldmark/toc.go
markup/goldmark/toc_test.go

index 897f0098b6d44e5ff9a61eb2a80af08201e3fb75..1753ede1bceedb7d0fe91f43a37f59c6ed0a8d07 100644 (file)
@@ -79,9 +79,8 @@ func (t *tocTransformer) Transform(n *ast.Document, reader text.Reader, pc parse
                        if found {
                                header.ID = string(id.([]byte))
                        }
-               case ast.KindText:
-                       textNode := n.(*ast.Text)
-                       headingText.Write(textNode.Text(reader.Source()))
+               case ast.KindText, ast.KindString:
+                       headingText.Write(n.Text(reader.Source()))
                }
 
                return s, nil
index f2e15f593899a9f6c8c7e6921098ea66d19eed6e..d3a1613cf0be6ecd7b8f7a7fac8d02cffbe231f0 100644 (file)
@@ -32,7 +32,7 @@ func TestToc(t *testing.T) {
        content := `
 # Header 1
 
-## First h2
+## First h2---now with typography!
 
 Some text.
 
@@ -61,7 +61,7 @@ And then some.
        got := b.(converter.TableOfContentsProvider).TableOfContents().ToHTML(2, 3)
        c.Assert(got, qt.Equals, `<nav id="TableOfContents">
   <ul>
-    <li><a href="#first-h2">First h2</a>
+    <li><a href="#first-h2---now-with-typography">First h2&mdash;now with typography!</a>
       <ul>
         <li><a href="#h3">H3</a></li>
       </ul>