diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-01-04 11:28:19 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2020-01-04 19:46:01 +0100 |
commit | a82d2700fcc772aada15d65b8f76913ca23f7404 (patch) | |
tree | fa1c09eb1523d7cda303982b5c08661af9a194d6 /markup/goldmark/convert_test.go | |
parent | ae816452b171b6b6aabca6a7423ed28a653baaa2 (diff) |
markup/goldmark: Make auto IDs GitHub compatible
You can turn off this behaviour:
```toml
[markup]
[markup.goldmark]
[markup.goldmark.parser]
autoHeadingIDAsciiOnly = true
```
Note that the `anchorize` now adapts its behaviour depending on the default Markdown handler.
Fixes #6616
Diffstat (limited to 'markup/goldmark/convert_test.go')
-rw-r--r-- | markup/goldmark/convert_test.go | 54 |
1 files changed, 41 insertions, 13 deletions
diff --git a/markup/goldmark/convert_test.go b/markup/goldmark/convert_test.go index 2a9727606..b9bf01ef5 100644 --- a/markup/goldmark/convert_test.go +++ b/markup/goldmark/convert_test.go @@ -28,6 +28,23 @@ import ( qt "github.com/frankban/quicktest" ) +func convert(c *qt.C, mconf markup_config.Config, content string) converter.Result { + + p, err := Provider.New( + converter.ProviderConfig{ + MarkupConfig: mconf, + Logger: loggers.NewErrorLogger(), + }, + ) + c.Assert(err, qt.IsNil) + conv, err := p.New(converter.DocumentContext{DocumentID: "thedoc"}) + c.Assert(err, qt.IsNil) + b, err := conv.Convert(converter.RenderContext{RenderTOC: true, Src: []byte(content)}) + c.Assert(err, qt.IsNil) + + return b +} + func TestConvert(t *testing.T) { c := qt.New(t) @@ -92,29 +109,23 @@ description : the description for the content. +## 神真美好 + +## 神真美好 + +## 神真美好 + [^1]: And that's the footnote. ` // Code fences content = strings.Replace(content, "§§§", "```", -1) - mconf := markup_config.Default mconf.Highlight.NoClasses = false mconf.Goldmark.Renderer.Unsafe = true - p, err := Provider.New( - converter.ProviderConfig{ - MarkupConfig: mconf, - Logger: loggers.NewErrorLogger(), - }, - ) - c.Assert(err, qt.IsNil) - conv, err := p.New(converter.DocumentContext{DocumentID: "thedoc"}) - c.Assert(err, qt.IsNil) - b, err := conv.Convert(converter.RenderContext{RenderTOC: true, Src: []byte(content)}) - c.Assert(err, qt.IsNil) - + b := convert(c, mconf, content) got := string(b.Bytes()) // Links @@ -123,6 +134,9 @@ description // Header IDs c.Assert(got, qt.Contains, `<h2 id="custom">Custom ID</h2>`, qt.Commentf(got)) c.Assert(got, qt.Contains, `<h2 id="auto-id">Auto ID</h2>`, qt.Commentf(got)) + c.Assert(got, qt.Contains, `<h2 id="神真美好">神真美好</h2>`, qt.Commentf(got)) + c.Assert(got, qt.Contains, `<h2 id="神真美好-1">神真美好</h2>`, qt.Commentf(got)) + c.Assert(got, qt.Contains, `<h2 id="神真美好-2">神真美好</h2>`, qt.Commentf(got)) // Code fences c.Assert(got, qt.Contains, "<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-bash\" data-lang=\"bash\">LINE1\n</code></pre></div>") @@ -148,6 +162,20 @@ description } +func TestConvertAutoIDAsciiOnly(t *testing.T) { + c := qt.New(t) + + content := ` +## God is Good: 神真美好 +` + mconf := markup_config.Default + mconf.Goldmark.Parser.AutoHeadingIDAsciiOnly = true + b := convert(c, mconf, content) + got := string(b.Bytes()) + + c.Assert(got, qt.Contains, "<h2 id=\"god-is-good-\">") +} + func TestCodeFence(t *testing.T) { c := qt.New(t) |