diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 32ff044973a..7701b08bee3 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,6 +33,9 @@ jobs: run: | pip install docutils rst2html.py --version + - name: Install pygments + run: | + pip install pygments - if: matrix.os == 'ubuntu-latest' name: Install pandoc on Linux run: | diff --git a/docs/content/en/content-management/formats.md b/docs/content/en/content-management/formats.md index 1ae20ba5833..4ff8115e771 100644 --- a/docs/content/en/content-management/formats.md +++ b/docs/content/en/content-management/formats.md @@ -50,7 +50,7 @@ tool on your machine to be able to use these formats. Hugo passes reasonable default arguments to these external helpers by default: - `asciidoctor`: `--no-header-footer -` -- `rst2html`: `--leave-comments --initial-header-level=2` +- `rst2html`: `--leave-comments --initial-header-level=2 --syntax-highlight=short --math-output "MathJax https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js"` - `pandoc`: `--mathjax` {{% warning "Performance of External Helpers" %}} diff --git a/markup/rst/convert.go b/markup/rst/convert.go index b86b35f1b77..eeebaf388fa 100644 --- a/markup/rst/convert.go +++ b/markup/rst/convert.go @@ -82,10 +82,14 @@ func (c *rstConverter) getRstContent(src []byte, ctx converter.DocumentContext) // handle Windows manually because it doesn't do shebangs if runtime.GOOS == "windows" { pythonBinary, _ := internal.GetPythonBinaryAndExecPath() - args := []string{binaryPath, "--leave-comments", "--initial-header-level=2"} + args := []string{binaryPath, + "--leave-comments", "--initial-header-level=2", "--syntax-highlight=short", + "--math-output", "MathJax https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js"} result, err = internal.ExternallyRenderContent(c.cfg, ctx, src, pythonBinary, args) } else { - args := []string{"--leave-comments", "--initial-header-level=2"} + args := []string{ + "--leave-comments", "--initial-header-level=2", "--syntax-highlight=short", + "--math-output", "MathJax https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js"} result, err = internal.ExternallyRenderContent(c.cfg, ctx, src, binaryName, args) } diff --git a/markup/rst/convert_test.go b/markup/rst/convert_test.go index 5d2882de15b..9063bb4c543 100644 --- a/markup/rst/convert_test.go +++ b/markup/rst/convert_test.go @@ -45,3 +45,33 @@ func TestConvert(t *testing.T) { c.Assert(err, qt.IsNil) c.Assert(string(b.Bytes()), qt.Equals, "
\n\n\n

testContent

\n
") } + +func TestConvertMathJax(t *testing.T) { + if !Supports() { + t.Skip("rst not installed") + } + c := qt.New(t) + p, err := Provider.New(converter.ProviderConfig{Logger: loggers.NewErrorLogger()}) + c.Assert(err, qt.IsNil) + conv, err := p.New(converter.DocumentContext{}) + c.Assert(err, qt.IsNil) + b, err := conv.Convert(converter.RenderContext{Src: []byte(":math:`ax^2 + bx + c = 0`")}) + c.Assert(err, qt.IsNil) + c.Assert(string(b.Bytes()), qt.Equals, + "
\n\n\n

\\(ax^2 + bx + c = 0\\)

\n
") +} + +func TestConvertCodeFormatting(t *testing.T) { + if !Supports() { + t.Skip("rst not installed") + } + c := qt.New(t) + p, err := Provider.New(converter.ProviderConfig{Logger: loggers.NewErrorLogger()}) + c.Assert(err, qt.IsNil) + conv, err := p.New(converter.DocumentContext{}) + c.Assert(err, qt.IsNil) + b, err := conv.Convert(converter.RenderContext{Src: []byte(".. code:: c\n\n int i = 0;")}) + c.Assert(err, qt.IsNil) + c.Assert(string(b.Bytes()), qt.Equals, + "
\n\n\n
\nint i = 0;\n
\n
") +}