mm-mark 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- package/.github/workflows/publish.yml +22 -0
- package/CHANGELOG.md +6 -0
- package/dist/index.d.mts +104 -5
- package/dist/index.js +111 -111
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +108 -108
- package/dist/index.mjs.map +1 -1
- package/import_map.json +7 -0
- package/jsr.json +13 -0
- package/lib/mathjax.ts +72 -0
- package/lib/style.ts +33 -0
- package/package.json +4 -2
- package/tsconfig.json +1 -1
- package/tsup.config.ts +2 -2
package/import_map.json
ADDED
package/jsr.json
ADDED
package/lib/mathjax.ts
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
import Showdown, { ShowdownExtension } from "showdown";
|
2
|
+
|
3
|
+
function mathjax(): ShowdownExtension[] {
|
4
|
+
const ext: ShowdownExtension[] = [
|
5
|
+
{
|
6
|
+
type: "lang",
|
7
|
+
filter: (text: string) => {
|
8
|
+
return text.replace(/\\\((.*?)\\\)/g, (match, p1) => {
|
9
|
+
return (
|
10
|
+
"<mathxxxjax>" +
|
11
|
+
encode("\\(" + escapehtml(p1) + "\\)") +
|
12
|
+
"</mathxxxjax>"
|
13
|
+
);
|
14
|
+
});
|
15
|
+
},
|
16
|
+
},
|
17
|
+
{
|
18
|
+
type: "lang",
|
19
|
+
filter: (text: string) => {
|
20
|
+
return text.replace(/\\\[([\s\S]*?)\\\]/g, (match, p1) => {
|
21
|
+
return (
|
22
|
+
"<mathxxxjax>" +
|
23
|
+
encode("\\[" + escapehtml(p1) + "\\]") +
|
24
|
+
"</mathxxxjax>"
|
25
|
+
);
|
26
|
+
});
|
27
|
+
},
|
28
|
+
},
|
29
|
+
{
|
30
|
+
type: "output",
|
31
|
+
filter: (text: string) => {
|
32
|
+
return text.replace(/<mathxxxjax>(.*?)<\/mathxxxjax>/g, (match, p1) => {
|
33
|
+
return decode(p1);
|
34
|
+
});
|
35
|
+
},
|
36
|
+
},
|
37
|
+
{
|
38
|
+
type: "output",
|
39
|
+
filter: (text: string) => {
|
40
|
+
const scriptTag = `
|
41
|
+
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
|
42
|
+
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
|
43
|
+
`;
|
44
|
+
return scriptTag + text;
|
45
|
+
},
|
46
|
+
},
|
47
|
+
];
|
48
|
+
return ext;
|
49
|
+
}
|
50
|
+
|
51
|
+
function escapehtml(str: string) {
|
52
|
+
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
53
|
+
}
|
54
|
+
|
55
|
+
function encode(text: string) {
|
56
|
+
if (typeof Buffer === "function") {
|
57
|
+
return Buffer.from(text).toString("base64");
|
58
|
+
} else {
|
59
|
+
return btoa(text);
|
60
|
+
}
|
61
|
+
}
|
62
|
+
function decode(text: string) {
|
63
|
+
if (typeof Buffer === "function") {
|
64
|
+
return Buffer.from(text, "base64").toString();
|
65
|
+
} else {
|
66
|
+
return atob(text);
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
Showdown.extensions.mathjax = mathjax();
|
71
|
+
|
72
|
+
export default mathjax;
|
package/lib/style.ts
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
import Showdown, { ShowdownExtension } from "showdown";
|
2
|
+
|
3
|
+
export const style: ShowdownExtension = {
|
4
|
+
type: "output",
|
5
|
+
filter: (text) => {
|
6
|
+
const styleTag = `
|
7
|
+
<style>
|
8
|
+
@import url("https://cdn.jsdelivr.net/gh/phothinmg/burmese-fonts@main/dist/028/index.css");
|
9
|
+
@import url("https://cdn.jsdelivr.net/gh/phothinmg/burmese-fonts@main/prism/prism.css");
|
10
|
+
@import url("https://cdn.jsdelivr.net/gh/PrismJS/prism-themes@master/themes/prism-holi-theme.css");
|
11
|
+
#mm-mark {
|
12
|
+
font-family: burmese-028 !important;
|
13
|
+
font-weight: 400;
|
14
|
+
}
|
15
|
+
</style>
|
16
|
+
`;
|
17
|
+
return styleTag + text;
|
18
|
+
},
|
19
|
+
};
|
20
|
+
|
21
|
+
export const script: ShowdownExtension = {
|
22
|
+
type: "output",
|
23
|
+
filter: (text) => {
|
24
|
+
const scriptTag = `
|
25
|
+
<script src="https://cdn.jsdelivr.net/gh/phothinmg/burmese-fonts@main/prism/prism.js"></script>
|
26
|
+
`;
|
27
|
+
return scriptTag + text;
|
28
|
+
},
|
29
|
+
};
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "mm-mark",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.1",
|
4
4
|
"description": "Markdown to Html Converter",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"module": "dist/index.mjs",
|
@@ -18,9 +18,11 @@
|
|
18
18
|
},
|
19
19
|
"devDependencies": {
|
20
20
|
"@changesets/cli": "^2.27.1",
|
21
|
+
"@types/js-yaml": "^4.0.9",
|
21
22
|
"@types/node": "^20.10.5",
|
22
23
|
"@types/showdown": "^2.0.6",
|
23
|
-
"
|
24
|
+
"js-yaml": "^4.1.0",
|
25
|
+
"jsr": "^0.12.2",
|
24
26
|
"showdown": "^2.1.0",
|
25
27
|
"tsup": "^8.0.2",
|
26
28
|
"typescript": "^5.3.3"
|
package/tsconfig.json
CHANGED