
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
github.com/litao91/goldmark-mathjax
Advanced tools
goldmark-mathjax is an extension for the goldmark that adds both block math and inline math support
It translate inline math equation quoted by $ and display math block quoted by $$ into MathJax compatible format.
hyphen _ won't break LaTeX render within a math element any more.
$$
\left[ \begin{array}{a} a^l_1 \\ â‹® \\ a^l_{d_l} \end{array}\right]
= \sigma(
\left[ \begin{matrix}
w^l_{1,1} & ⋯ & w^l_{1,d_{l-1}} \\
⋮ & ⋱ & ⋮ \\
w^l_{d_l,1} & ⋯ & w^l_{d_l,d_{l-1}} \\
\end{matrix}\right] ·
\left[ \begin{array}{x} a^{l-1}_1 \\ â‹® \\ â‹® \\ a^{l-1}_{d_{l-1}} \end{array}\right] +
\left[ \begin{array}{b} b^l_1 \\ â‹® \\ b^l_{d_l} \end{array}\right])
$$
Borrow the idea from pandoc and this blackfriday PR
The implementation is heavily inspired by the Fenced Code Block and CodeSpan of goldmark
go get github.com/litao91/goldmark-mathjax
package main
import (
"bytes"
"fmt"
mathjax "github.com/litao91/goldmark-mathjax"
"github.com/yuin/goldmark"
"github.com/yuin/goldmark/parser"
"github.com/yuin/goldmark/renderer/html"
)
func main() {
md := goldmark.New(
goldmark.WithExtensions(mathjax.MathJax),
goldmark.WithParserOptions(
parser.WithAutoHeadingID(),
),
goldmark.WithRendererOptions(
html.WithHardWraps(),
html.WithXHTML(),
),
)
// todo more control on the parsing process
var html bytes.Buffer
mdContent := []byte(`
$$
\mathbb{E}(X) = \int x d F(x) = \left\{ \begin{aligned} \sum_x x f(x) \; & \text{ if } X \text{ is discrete}
\\ \int x f(x) dx \; & \text{ if } X \text{ is continuous }
\end{aligned} \right.
$$
Inline math $\frac{1}{2}$
`)
if err := md.Convert(mdContent, &html); err != nil {
fmt.Println(err)
}
fmt.Println(html.String())
}
MIT
FAQs
Unknown package
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.