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.
@@ -0,0 +1,7 @@
1
+ {
2
+ "imports": {
3
+ "showdown-mathjax": "npm:showdown-mathjax@^1.0.3",
4
+ "showdown-prism": "npm:showdown-prism@^0.2.0",
5
+ "js-yaml": "npm:js-yaml@^4.1.0"
6
+ }
7
+ }
package/jsr.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "name": "@ptm/mm-mark",
3
+ "version": "0.2.0",
4
+ "exports": "./src/index.ts",
5
+ "publish": {
6
+ "include": [
7
+ "LICENSE",
8
+ "README.md",
9
+ "jsr.json",
10
+ "src/**/*.ts"
11
+ ]
12
+ }
13
+ }
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, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
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.0",
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
- "ptm-frontmatter": "^1.0.1",
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
@@ -14,6 +14,6 @@
14
14
  "skipLibCheck": true,
15
15
  "resolveJsonModule": true
16
16
  },
17
- "exclude": ["node_modules/**/*", "dist/**/*"],
17
+ "exclude": ["node_modules/**/*", "dist/**/*","lib/**/*"],
18
18
  "include": ["src/**/*"]
19
19
  }
package/tsup.config.ts CHANGED
@@ -6,8 +6,8 @@ export default defineConfig({
6
6
  outDir: "./dist",
7
7
  splitting: true,
8
8
  sourcemap: true,
9
- dts: true,
10
- format: "esm",
9
+ // dts: true,
10
+ format: "cjs",
11
11
  bundle: true,
12
12
  treeshake: true,
13
13
  minify: true,