Skip to content

Commit 95313ad

Browse files
committed
Add new flag -mfont
1 parent 813584a commit 95313ad

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

md2html.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var (
4141
hlstyle = flag.String("hlstyle", "github", "highlight.js style")
4242
lang = flag.String("lang", "en", "HTML lang attribute")
4343
m = flag.Bool("m", false, "use MathJax")
44+
mfont = flag.String("mfont", "", "MathJax font")
4445
style = flag.String("style", "", "style sheet")
4546
title = flag.String("title", "", "document title")
4647
)
@@ -158,6 +159,15 @@ func convert(r io.Reader, w io.Writer) (err error) {
158159
}
159160
// MathJax
160161
if *m {
162+
if *mfont != "" {
163+
fmt.Fprintln(w, `<script>`)
164+
fmt.Fprintln(w, `MathJax = {`)
165+
fmt.Fprintln(w, ` output: {`)
166+
fmt.Fprintf(w, " font: \"%s\"\n", *mfont)
167+
fmt.Fprintln(w, ` }`)
168+
fmt.Fprintln(w, `};`)
169+
fmt.Fprintln(w, `</script>`)
170+
}
161171
fmt.Fprintf(w, "<script defer src=\"%s\"></script>\n", mathJax)
162172
}
163173
// Mermaid

md2html_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ var (
2929
saveHLStyle string
3030
saveLang string
3131
saveM bool
32+
saveMFont string
3233
saveStyle string
3334
saveTitle string
3435
)
@@ -42,6 +43,7 @@ func init() {
4243
saveHLStyle = *hlstyle
4344
saveLang = *lang
4445
saveM = *m
46+
saveMFont = *mfont
4547
saveStyle = *style
4648
saveTitle = *title
4749
}
@@ -236,6 +238,12 @@ func TestConvert(t *testing.T) {
236238
if err := try(src, "m.html"); err != nil {
237239
t.Error(err)
238240
}
241+
242+
*m = true
243+
*mfont = "mathjax-stix2"
244+
if err := try(src, "mfont-stix2.html"); err != nil {
245+
t.Error(err)
246+
}
239247
})
240248
}
241249

@@ -249,6 +257,7 @@ func try(src []byte, name string) error {
249257
*hlstyle = saveHLStyle
250258
*lang = saveLang
251259
*m = saveM
260+
*mfont = saveMFont
252261
*style = saveStyle
253262
*title = saveTitle
254263
}()

testdata/mfont-stix2.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>md2html</title>
6+
<link rel="stylesheet" href="${highlight.js}/styles/github.min.css">
7+
<script src="${highlight.js}/highlight.min.js"></script>
8+
<script>hljs.highlightAll();</script>
9+
<script>
10+
MathJax = {
11+
output: {
12+
font: "mathjax-stix2"
13+
}
14+
};
15+
</script>
16+
<script defer src="${MathJax}"></script>
17+
</head>
18+
<body>
19+
<article class="markdown">
20+
<h1 id="md2html">md2html</h1>
21+
<p>...</p>
22+
</article>
23+
</body>
24+
</html>

0 commit comments

Comments
 (0)