@cobapen/markdown 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ import { Options } from "markdown-it/index.mjs";
2
+ import Renderer from "markdown-it/lib/renderer.mjs";
3
+ import Token from "markdown-it/lib/token.mjs";
4
+ interface Env {
5
+ showCodeTitleByDefault?: boolean;
6
+ }
7
+ export declare function fence_custom(tokens: Token[], idx: number, options: Options, env: Env, slf: Renderer): string;
8
+ export {};
@@ -0,0 +1,41 @@
1
+ import { escapeHtml, unescapeAll } from "markdown-it/lib/common/utils.mjs";
2
+ import { InfoString } from "./info-string.js";
3
+ export function fence_custom(tokens, idx, options, env, slf) {
4
+ const token = tokens[idx];
5
+ const info_str = token.info ? unescapeAll(token.info).trim() : "";
6
+ const info = new InfoString(info_str);
7
+ const langName = info.lang;
8
+ const langAttrs = info.attrs.join(" ");
9
+ let highlighted;
10
+ if (options.highlight) {
11
+ highlighted = options.highlight(token.content, langName, langAttrs) || escapeHtml(token.content);
12
+ }
13
+ else {
14
+ highlighted = escapeHtml(token.content);
15
+ }
16
+ if (highlighted.indexOf("<pre") === 0) {
17
+ return highlighted + "\n";
18
+ }
19
+ if (info.hasLang) {
20
+ const i = token.attrIndex("class");
21
+ const tmpAttrs = token.attrs ? token.attrs.slice() : [];
22
+ if (i < 0) {
23
+ tmpAttrs.push(["class", options.langPrefix + langName]);
24
+ }
25
+ else {
26
+ tmpAttrs[i] = tmpAttrs[i].slice();
27
+ tmpAttrs[i][1] += " " + options.langPrefix + langName;
28
+ }
29
+ const tmpToken = {
30
+ attrs: tmpAttrs
31
+ };
32
+ if (info.title.length > 0) {
33
+ const style = (env.showCodeTitleByDefault === true)
34
+ ? ""
35
+ : " style=\"visibility:hidden;\"";
36
+ return `<pre><code${slf.renderAttrs(tmpToken)}>${highlighted}</code><span class="title"${style}>${info.title}</span></pre>\n`;
37
+ }
38
+ return `<pre><code${slf.renderAttrs(tmpToken)}>${highlighted}</code></pre>\n`;
39
+ }
40
+ return `<pre><code${slf.renderAttrs(token)}>${highlighted}</code></pre>\n`;
41
+ }
@@ -0,0 +1,2 @@
1
+ import hljs from "highlight.js/lib/core";
2
+ export default hljs;
@@ -0,0 +1,179 @@
1
+ import hljs from "highlight.js/lib/core";
2
+ import langaccesslog from "highlight.js/lib/languages/accesslog";
3
+ import langarduino from "highlight.js/lib/languages/arduino";
4
+ import langarmasm from "highlight.js/lib/languages/armasm";
5
+ import langasciidoc from "highlight.js/lib/languages/asciidoc";
6
+ import langavrasm from "highlight.js/lib/languages/avrasm";
7
+ import langawk from "highlight.js/lib/languages/awk";
8
+ import langbash from "highlight.js/lib/languages/bash";
9
+ import langbasic from "highlight.js/lib/languages/basic";
10
+ import langbnf from "highlight.js/lib/languages/bnf";
11
+ import langc from "highlight.js/lib/languages/c";
12
+ import langclojure from "highlight.js/lib/languages/clojure";
13
+ import langcmake from "highlight.js/lib/languages/cmake";
14
+ import langcoffeescript from "highlight.js/lib/languages/coffeescript";
15
+ import langcpp from "highlight.js/lib/languages/cpp";
16
+ import langcsharp from "highlight.js/lib/languages/csharp";
17
+ import langcss from "highlight.js/lib/languages/css";
18
+ import langd from "highlight.js/lib/languages/d";
19
+ import langdart from "highlight.js/lib/languages/dart";
20
+ import langdelphi from "highlight.js/lib/languages/delphi";
21
+ import langdiff from "highlight.js/lib/languages/diff";
22
+ import langdjango from "highlight.js/lib/languages/django";
23
+ import langdns from "highlight.js/lib/languages/dns";
24
+ import langdockerfile from "highlight.js/lib/languages/dockerfile";
25
+ import langdos from "highlight.js/lib/languages/dos";
26
+ import langebnf from "highlight.js/lib/languages/ebnf";
27
+ import langelixir from "highlight.js/lib/languages/elixir";
28
+ import langelm from "highlight.js/lib/languages/elm";
29
+ import langerb from "highlight.js/lib/languages/erb";
30
+ import langerlang from "highlight.js/lib/languages/erlang";
31
+ import langexcel from "highlight.js/lib/languages/excel";
32
+ import langfortran from "highlight.js/lib/languages/fortran";
33
+ import langglsl from "highlight.js/lib/languages/glsl";
34
+ import langgo from "highlight.js/lib/languages/go";
35
+ import langgradle from "highlight.js/lib/languages/gradle";
36
+ import langgraphql from "highlight.js/lib/languages/graphql";
37
+ import langhandlebars from "highlight.js/lib/languages/handlebars";
38
+ import langhaskell from "highlight.js/lib/languages/haskell";
39
+ import langhttp from "highlight.js/lib/languages/http";
40
+ import langini from "highlight.js/lib/languages/ini";
41
+ import langjava from "highlight.js/lib/languages/java";
42
+ import langjavascript from "highlight.js/lib/languages/javascript";
43
+ import langjson from "highlight.js/lib/languages/json";
44
+ import langjulia from "highlight.js/lib/languages/julia";
45
+ import langkotlin from "highlight.js/lib/languages/kotlin";
46
+ import langlatex from "highlight.js/lib/languages/latex";
47
+ import langlisp from "highlight.js/lib/languages/lisp";
48
+ import langllvm from "highlight.js/lib/languages/llvm";
49
+ import langlua from "highlight.js/lib/languages/lua";
50
+ import langmakefile from "highlight.js/lib/languages/makefile";
51
+ import langmarkdown from "highlight.js/lib/languages/markdown";
52
+ import langmatlab from "highlight.js/lib/languages/matlab";
53
+ import langmipsasm from "highlight.js/lib/languages/mipsasm";
54
+ import langnginx from "highlight.js/lib/languages/nginx";
55
+ import langnim from "highlight.js/lib/languages/nim";
56
+ import langnode from "highlight.js/lib/languages/node-repl";
57
+ import langobjectivec from "highlight.js/lib/languages/objectivec";
58
+ import langocaml from "highlight.js/lib/languages/ocaml";
59
+ import langperl from "highlight.js/lib/languages/perl";
60
+ import langphp from "highlight.js/lib/languages/php";
61
+ import langplaintext from "highlight.js/lib/languages/plaintext";
62
+ import langpowershell from "highlight.js/lib/languages/powershell";
63
+ import langprocessing from "highlight.js/lib/languages/processing";
64
+ import langprotobuf from "highlight.js/lib/languages/protobuf";
65
+ import langpython from "highlight.js/lib/languages/python";
66
+ import langqml from "highlight.js/lib/languages/qml";
67
+ import langr from "highlight.js/lib/languages/r";
68
+ import langruby from "highlight.js/lib/languages/ruby";
69
+ import langrust from "highlight.js/lib/languages/rust";
70
+ import langscala from "highlight.js/lib/languages/scala";
71
+ import langscheme from "highlight.js/lib/languages/scheme";
72
+ import langscss from "highlight.js/lib/languages/scss";
73
+ import langshell from "highlight.js/lib/languages/shell";
74
+ import langsmalltalk from "highlight.js/lib/languages/smalltalk";
75
+ import langsql from "highlight.js/lib/languages/sql";
76
+ import langswift from "highlight.js/lib/languages/swift";
77
+ import langtwig from "highlight.js/lib/languages/twig";
78
+ import langtypescript from "highlight.js/lib/languages/typescript";
79
+ import langvbnet from "highlight.js/lib/languages/vbnet";
80
+ import langvbscript from "highlight.js/lib/languages/vbscript";
81
+ import langverilog from "highlight.js/lib/languages/verilog";
82
+ import langvhdl from "highlight.js/lib/languages/vhdl";
83
+ import langvim from "highlight.js/lib/languages/vim";
84
+ import langwasm from "highlight.js/lib/languages/wasm";
85
+ import langx86asm from "highlight.js/lib/languages/x86asm";
86
+ import langxml from "highlight.js/lib/languages/xml";
87
+ import langyaml from "highlight.js/lib/languages/yaml";
88
+ const languages = [
89
+ ["accesslog", langaccesslog],
90
+ ["arduino", langarduino],
91
+ ["armasm", langarmasm],
92
+ ["asciidoc", langasciidoc],
93
+ ["avrasm", langavrasm],
94
+ ["awk", langawk],
95
+ ["bash", langbash],
96
+ ["basic", langbasic],
97
+ ["bnf", langbnf],
98
+ ["c", langc],
99
+ ["clojure", langclojure],
100
+ ["cmake", langcmake],
101
+ ["coffeescript", langcoffeescript],
102
+ ["cpp", langcpp],
103
+ ["csharp", langcsharp],
104
+ ["css", langcss],
105
+ ["d", langd],
106
+ ["dart", langdart],
107
+ ["delphi", langdelphi],
108
+ ["diff", langdiff],
109
+ ["django", langdjango],
110
+ ["dns", langdns],
111
+ ["dockerfile", langdockerfile],
112
+ ["dos", langdos],
113
+ ["ebnf", langebnf],
114
+ ["elixir", langelixir],
115
+ ["elm", langelm],
116
+ ["erb", langerb],
117
+ ["erlang", langerlang],
118
+ ["excel", langexcel],
119
+ ["fortran", langfortran],
120
+ ["glsl", langglsl],
121
+ ["go", langgo],
122
+ ["gradle", langgradle],
123
+ ["graphql", langgraphql],
124
+ ["handlebars", langhandlebars],
125
+ ["haskell", langhaskell],
126
+ ["http", langhttp],
127
+ ["ini", langini],
128
+ ["java", langjava],
129
+ ["javascript", langjavascript],
130
+ ["json", langjson],
131
+ ["julia", langjulia],
132
+ ["kotlin", langkotlin],
133
+ ["latex", langlatex],
134
+ ["lisp", langlisp],
135
+ ["llvm", langllvm],
136
+ ["lua", langlua],
137
+ ["makefile", langmakefile],
138
+ ["markdown", langmarkdown],
139
+ ["matlab", langmatlab],
140
+ ["mipsasm", langmipsasm],
141
+ ["nginx", langnginx],
142
+ ["nim", langnim],
143
+ ["node-repl", langnode],
144
+ ["objectivec", langobjectivec],
145
+ ["ocaml", langocaml],
146
+ ["perl", langperl],
147
+ ["php", langphp],
148
+ ["plaintext", langplaintext],
149
+ ["powershell", langpowershell],
150
+ ["processing", langprocessing],
151
+ ["protobuf", langprotobuf],
152
+ ["python", langpython],
153
+ ["qml", langqml],
154
+ ["r", langr],
155
+ ["ruby", langruby],
156
+ ["rust", langrust],
157
+ ["scala", langscala],
158
+ ["scheme", langscheme],
159
+ ["scss", langscss],
160
+ ["shell", langshell],
161
+ ["smalltalk", langsmalltalk],
162
+ ["sql", langsql],
163
+ ["swift", langswift],
164
+ ["twig", langtwig],
165
+ ["typescript", langtypescript],
166
+ ["vbnet", langvbnet],
167
+ ["vbscript", langvbscript],
168
+ ["verilog", langverilog],
169
+ ["vhdl", langvhdl],
170
+ ["vim", langvim],
171
+ ["wasm", langwasm],
172
+ ["x86asm", langx86asm],
173
+ ["xml", langxml],
174
+ ["yaml", langyaml],
175
+ ];
176
+ for (const [name, language] of languages) {
177
+ hljs.registerLanguage(name, language);
178
+ }
179
+ export default hljs;
@@ -0,0 +1,2 @@
1
+ export declare function highlightWithLineNumber(code: string, lang: string, linestart?: number): string;
2
+ export declare function highlighterForMarkdownIt(str: string, lang: string, attrs: string): string;
@@ -0,0 +1,45 @@
1
+ import hljs from "./highlight-custom.js";
2
+ import { InfoString } from "./info-string.js";
3
+ function _debuglog(..._args) {
4
+ }
5
+ function numDigits(n) {
6
+ return Math.floor(n).toString().length;
7
+ }
8
+ function niceDec(n) {
9
+ return n.toFixed(3);
10
+ }
11
+ export function highlightWithLineNumber(code, lang, linestart) {
12
+ try {
13
+ if (lang && hljs.getLanguage(lang)) {
14
+ let htmlLines = hljs.highlight(code, { language: lang }).value;
15
+ if (linestart !== undefined) {
16
+ const lines = htmlLines.split("\n");
17
+ const elWidth = numDigits(linestart + lines.length) * 0.8;
18
+ const elStyle = "display:inline-block;" +
19
+ "user-select:none;" +
20
+ `width: ${niceDec(elWidth)}em;`;
21
+ lines.forEach((line, i, lines) => {
22
+ lines[i] =
23
+ "<div class=\"line\">" +
24
+ `<span class="line-no" style="${elStyle}">${linestart + i}</span>${line}` +
25
+ "</div>";
26
+ });
27
+ _debuglog(lines);
28
+ htmlLines = lines.join("");
29
+ }
30
+ return htmlLines;
31
+ }
32
+ else {
33
+ return "";
34
+ }
35
+ }
36
+ catch (_) {
37
+ return "";
38
+ }
39
+ }
40
+ export function highlighterForMarkdownIt(str, lang, attrs) {
41
+ _debuglog(lang ? lang : "(lang is empty or undefined)");
42
+ const info = new InfoString(lang + " " + attrs);
43
+ _debuglog(info);
44
+ return highlightWithLineNumber(str, info.lang, info.linestart);
45
+ }
@@ -0,0 +1,19 @@
1
+ export declare class InfoString {
2
+ private readonly _lang;
3
+ private readonly _attrs;
4
+ private readonly _title;
5
+ private readonly _linestart;
6
+ constructor(info: string);
7
+ get lang(): string;
8
+ get attrs(): string[];
9
+ get title(): string;
10
+ get linestart(): number | undefined;
11
+ get hasLang(): boolean;
12
+ static parseInfoString(info: string): string[];
13
+ static parseMetaNotation(text: string): {
14
+ filename: string;
15
+ line: number;
16
+ } | undefined;
17
+ static getTitle(attr: string[]): string;
18
+ static getLineStart(attr: string[]): number | undefined;
19
+ }
@@ -0,0 +1,100 @@
1
+ export class InfoString {
2
+ _lang;
3
+ _attrs;
4
+ _title;
5
+ _linestart;
6
+ constructor(info) {
7
+ if (info.length > 0) {
8
+ const arr = InfoString.parseInfoString(info);
9
+ this._lang = arr[0];
10
+ this._attrs = arr.slice(1);
11
+ this._title = InfoString.getTitle(this._attrs);
12
+ this._linestart = InfoString.getLineStart(this._attrs);
13
+ }
14
+ else {
15
+ this._lang = "";
16
+ this._attrs = [];
17
+ this._title = "";
18
+ this._linestart = undefined;
19
+ }
20
+ }
21
+ get lang() {
22
+ return this._lang;
23
+ }
24
+ get attrs() {
25
+ return this._attrs;
26
+ }
27
+ get title() {
28
+ return this._title;
29
+ }
30
+ get linestart() {
31
+ return this._linestart;
32
+ }
33
+ get hasLang() {
34
+ return this._lang.length > 0;
35
+ }
36
+ static parseInfoString(info) {
37
+ const dq = "[^\"\\\\]*(?:\\\\.|[^\"\\\\]*)*";
38
+ const sq = "[^\'\\\\]*(?:\\\\.|[^\'\\\\]*)*";
39
+ const ptn = `([^\\s]+=)?(?:"(${dq})"|'(${sq})'|([^\\s]+))`;
40
+ const regex = new RegExp(ptn, "g");
41
+ const result = [];
42
+ let match;
43
+ while ((match = regex.exec(info)) !== null) {
44
+ let text = (match[1] || "") + (match[2] || match[3] || match[4] || "");
45
+ text = unescape(text).trim();
46
+ result.push(text);
47
+ }
48
+ return result;
49
+ }
50
+ static parseMetaNotation(text) {
51
+ const match = text.match(/^\{\s*([^:]+):(\d+)\s*\}$/);
52
+ if (match) {
53
+ return {
54
+ filename: match[1],
55
+ line: parseInt(match[2], 10),
56
+ };
57
+ }
58
+ return undefined;
59
+ }
60
+ static getTitle(attr) {
61
+ const titleAttr = attr.find(x => x.startsWith("title=")) ?? "";
62
+ if (titleAttr.length > 0) {
63
+ const match = titleAttr.match(/^title=(.*)$/);
64
+ if (match) {
65
+ let value = match[1].trim();
66
+ if (value.startsWith("\"") && value.endsWith("\"")) {
67
+ value = value.slice(1, -1);
68
+ value = unescape(value).trim();
69
+ }
70
+ return value;
71
+ }
72
+ else {
73
+ throw new Error("Must not fail. Check impl.");
74
+ }
75
+ }
76
+ if (attr.length > 0) {
77
+ const meta = InfoString.parseMetaNotation(attr[0]);
78
+ if (meta && meta.filename.length > 0) {
79
+ return meta.filename;
80
+ }
81
+ }
82
+ return "";
83
+ }
84
+ static getLineStart(attr) {
85
+ const lineAttr = attr.find(x => x.startsWith("linestart=")) ?? "";
86
+ if (lineAttr.length > 0) {
87
+ return parseInt(lineAttr.split("=")[1].trim());
88
+ }
89
+ if (attr.length > 0) {
90
+ const meta = InfoString.parseMetaNotation(attr[0]);
91
+ if (meta && meta.line > 0) {
92
+ return meta.line;
93
+ }
94
+ }
95
+ return undefined;
96
+ }
97
+ }
98
+ function unescape(text) {
99
+ return text.replaceAll(/\\\"/g, "\"").replaceAll(/\\\'/g, "'");
100
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import markdownIt, { Options as MarkdownOptions } from "markdown-it";
2
+ import { Options as MathOptions } from "./math/mathjax.js";
3
+ export interface Config {
4
+ showCodeTitleByDefault: boolean;
5
+ markdown: Partial<MarkdownOptions>;
6
+ math: Partial<MathOptions>;
7
+ }
8
+ export type Options = Partial<Config>;
9
+ export declare class CMarkdown {
10
+ private readonly _config;
11
+ private readonly _mj;
12
+ private readonly _md;
13
+ constructor(option?: Options);
14
+ setup(md: markdownIt): void;
15
+ render(text: string): string;
16
+ mathcss(): string;
17
+ }
package/lib/index.js ADDED
@@ -0,0 +1,64 @@
1
+ import markdownIt from "markdown-it";
2
+ import advTable from "markdown-it-adv-table";
3
+ import anchor from "markdown-it-anchor";
4
+ import cjkbreaks from "markdown-it-cjk-breaks";
5
+ import deflist from "markdown-it-deflist";
6
+ import footnote from "markdown-it-footnote";
7
+ import toc from "markdown-it-table-of-contents";
8
+ import { fence_custom } from "./code/fence-custom.js";
9
+ import { highlighterForMarkdownIt } from "./code/highlight.js";
10
+ import { replacelink } from "./link/replacelink.js";
11
+ import { MathjaxEngine } from "./math/mathjax.js";
12
+ import { mdmath } from "./math/mdmath.js";
13
+ const defaultOptions = {
14
+ showCodeTitleByDefault: false,
15
+ markdown: {
16
+ html: true,
17
+ linkify: true,
18
+ highlight: highlighterForMarkdownIt,
19
+ },
20
+ math: {
21
+ output: {
22
+ font: "mathjax-newcm"
23
+ },
24
+ tex: {
25
+ macros: {
26
+ bm: ["\\boldsymbol{#1}", 1],
27
+ },
28
+ },
29
+ }
30
+ };
31
+ export class CMarkdown {
32
+ _config;
33
+ _mj;
34
+ _md;
35
+ constructor(option) {
36
+ const config = { ...defaultOptions, ...option };
37
+ const mj = new MathjaxEngine(config.math);
38
+ const md = markdownIt(config.markdown);
39
+ this._config = config;
40
+ this._mj = mj;
41
+ this._md = md;
42
+ this.setup(md);
43
+ }
44
+ setup(md) {
45
+ md.renderer.rules.fence = fence_custom;
46
+ md.use(anchor)
47
+ .use(cjkbreaks)
48
+ .use(footnote)
49
+ .use(deflist)
50
+ .use(replacelink)
51
+ .use(advTable)
52
+ .use(mdmath(this._mj))
53
+ .use(toc, {
54
+ includeLevel: [2, 3],
55
+ });
56
+ }
57
+ render(text) {
58
+ const env = { ...this._config };
59
+ return this._md.render(text, env);
60
+ }
61
+ mathcss() {
62
+ return this._mj.stylesheet();
63
+ }
64
+ }
@@ -0,0 +1,8 @@
1
+ import type { PluginWithOptions } from "markdown-it";
2
+ import type Token from "markdown-it/lib/token.mjs";
3
+ type ReplaceHandler = (link: string, env: any, token: Token) => string;
4
+ interface Options {
5
+ replace: ReplaceHandler;
6
+ }
7
+ export declare const replacelink: PluginWithOptions<Options>;
8
+ export default replacelink;
@@ -0,0 +1,39 @@
1
+ function defaultHandler(link, _env, _token) {
2
+ if (!link.startsWith("http") && link.endsWith(".md")) {
3
+ return link.replace(/\.md$/, ".html");
4
+ }
5
+ else {
6
+ return link;
7
+ }
8
+ }
9
+ function replaceAttr(token, attrName, handler, env) {
10
+ token.attrs?.forEach(attr => {
11
+ if (attr[0] === attrName) {
12
+ attr[1] = handler(attr[1], env, token);
13
+ }
14
+ });
15
+ }
16
+ function getHandler(option) {
17
+ const replaceFn = option?.replace || defaultHandler;
18
+ function handler(state) {
19
+ state.tokens.forEach(token => {
20
+ if (token.type === "inline" && token.children !== null) {
21
+ token.children.forEach(childToken => {
22
+ if (childToken.type == "link_open") {
23
+ replaceAttr(childToken, "href", replaceFn, state.env);
24
+ }
25
+ else if (childToken.type == "image") {
26
+ replaceAttr(childToken, "src", replaceFn, state.env);
27
+ }
28
+ });
29
+ }
30
+ });
31
+ }
32
+ ;
33
+ return handler;
34
+ }
35
+ export const replacelink = (md, option) => {
36
+ const handler = getHandler(option);
37
+ md.core.ruler.after("linkify", "replace_link", handler);
38
+ };
39
+ export default replacelink;
@@ -0,0 +1,145 @@
1
+ import { type LiteDocument } from "@mathjax/src/js/adaptors/lite/Document.js";
2
+ import { LiteElement } from "@mathjax/src/js/adaptors/lite/Element.js";
3
+ import { type LiteText } from "@mathjax/src/js/adaptors/lite/Text.js";
4
+ import { type LiteAdaptor } from "@mathjax/src/js/adaptors/liteAdaptor.js";
5
+ import { type MathDocument } from "@mathjax/src/js/core/MathDocument.js";
6
+ import { TeX } from "@mathjax/src/js/input/tex.js";
7
+ import { CHTML } from "@mathjax/src/js/output/chtml.js";
8
+ import { type DeepPartial } from "../utils/merge.js";
9
+ import "@mathjax/src/js/input/tex/base/BaseConfiguration.js";
10
+ import "@mathjax/src/js/input/tex/ams/AmsConfiguration.js";
11
+ import "@mathjax/src/js/input/tex/newcommand/NewcommandConfiguration.js";
12
+ import "@mathjax/src/js/input/tex/noundefined/NoUndefinedConfiguration.js";
13
+ import "@mathjax/src/js/input/tex/action/ActionConfiguration.js";
14
+ import "@mathjax/src/js/input/tex/ams/AmsConfiguration.js";
15
+ import "@mathjax/src/js/input/tex/amscd/AmsCdConfiguration.js";
16
+ import "@mathjax/src/js/input/tex/autoload/AutoloadConfiguration.js";
17
+ import "@mathjax/src/js/input/tex/base/BaseConfiguration.js";
18
+ import "@mathjax/src/js/input/tex/bbm/BbmConfiguration.js";
19
+ import "@mathjax/src/js/input/tex/bboldx/BboldxConfiguration.js";
20
+ import "@mathjax/src/js/input/tex/bbox/BboxConfiguration.js";
21
+ import "@mathjax/src/js/input/tex/begingroup/BegingroupConfiguration.js";
22
+ import "@mathjax/src/js/input/tex/boldsymbol/BoldsymbolConfiguration.js";
23
+ import "@mathjax/src/js/input/tex/braket/BraketConfiguration.js";
24
+ import "@mathjax/src/js/input/tex/bussproofs/BussproofsConfiguration.js";
25
+ import "@mathjax/src/js/input/tex/cancel/CancelConfiguration.js";
26
+ import "@mathjax/src/js/input/tex/cases/CasesConfiguration.js";
27
+ import "@mathjax/src/js/input/tex/centernot/CenternotConfiguration.js";
28
+ import "@mathjax/src/js/input/tex/color/ColorConfiguration.js";
29
+ import "@mathjax/src/js/input/tex/colortbl/ColortblConfiguration.js";
30
+ import "@mathjax/src/js/input/tex/colorv2/ColorV2Configuration.js";
31
+ import "@mathjax/src/js/input/tex/configmacros/ConfigMacrosConfiguration.js";
32
+ import "@mathjax/src/js/input/tex/dsfont/DsfontConfiguration.js";
33
+ import "@mathjax/src/js/input/tex/empheq/EmpheqConfiguration.js";
34
+ import "@mathjax/src/js/input/tex/enclose/EncloseConfiguration.js";
35
+ import "@mathjax/src/js/input/tex/extpfeil/ExtpfeilConfiguration.js";
36
+ import "@mathjax/src/js/input/tex/gensymb/GensymbConfiguration.js";
37
+ import "@mathjax/src/js/input/tex/html/HtmlConfiguration.js";
38
+ import "@mathjax/src/js/input/tex/mathtools/MathtoolsConfiguration.js";
39
+ import "@mathjax/src/js/input/tex/mhchem/MhchemConfiguration.js";
40
+ import "@mathjax/src/js/input/tex/newcommand/NewcommandConfiguration.js";
41
+ import "@mathjax/src/js/input/tex/noerrors/NoErrorsConfiguration.js";
42
+ import "@mathjax/src/js/input/tex/noundefined/NoUndefinedConfiguration.js";
43
+ import "@mathjax/src/js/input/tex/physics/PhysicsConfiguration.js";
44
+ import "@mathjax/src/js/input/tex/require/RequireConfiguration.js";
45
+ import "@mathjax/src/js/input/tex/setoptions/SetOptionsConfiguration.js";
46
+ import "@mathjax/src/js/input/tex/tagformat/TagFormatConfiguration.js";
47
+ import "@mathjax/src/js/input/tex/texhtml/TexHtmlConfiguration.js";
48
+ import "@mathjax/src/js/input/tex/textcomp/TextcompConfiguration.js";
49
+ import "@mathjax/src/js/input/tex/textmacros/TextMacrosConfiguration.js";
50
+ import "@mathjax/src/js/input/tex/unicode/UnicodeConfiguration.js";
51
+ import "@mathjax/src/js/input/tex/units/UnitsConfiguration.js";
52
+ import "@mathjax/src/js/input/tex/upgreek/UpgreekConfiguration.js";
53
+ import "@mathjax/src/js/input/tex/verb/VerbConfiguration.js";
54
+ type N = LiteElement;
55
+ type T = LiteText;
56
+ type D = LiteDocument;
57
+ declare const fontNames: readonly ["mathjax-newcm", "mathjax-stix2"];
58
+ type FontName = typeof fontNames[number];
59
+ interface AnyObject {
60
+ [x: string]: any;
61
+ }
62
+ export interface Options {
63
+ loader?: DeepPartial<LoaderOptions>;
64
+ tex?: DeepPartial<TexInputOptions>;
65
+ output?: DeepPartial<OutputOptions>;
66
+ chtml?: DeepPartial<CHTMLOptions>;
67
+ }
68
+ interface LoaderOptions {
69
+ load: string[];
70
+ paths: {
71
+ mathjax?: {
72
+ [x: string]: string;
73
+ };
74
+ fonts?: string;
75
+ };
76
+ }
77
+ interface TexInputOptions {
78
+ packages: string | [string] | AnyObject;
79
+ inlineMath: [[string, string]];
80
+ displayMath: [[string, string]];
81
+ processEscapes: boolean;
82
+ processEnvironments: boolean;
83
+ processRefs: boolean;
84
+ digits: RegExp;
85
+ tags: string;
86
+ tagSide: string;
87
+ tagIndent: string;
88
+ useLabelIds: boolean;
89
+ multlineWidth: string;
90
+ maxMacros: number;
91
+ maxBuffer: number;
92
+ baseURL: string;
93
+ formatError: (jax: object, err: Error) => void;
94
+ macros: AnyObject;
95
+ }
96
+ interface OutputOptions {
97
+ scale: number;
98
+ minScale: number;
99
+ matchFontHeight: boolean;
100
+ mtextInheritFont: boolean;
101
+ merrorInheritFont: boolean;
102
+ mtextFont: string;
103
+ merrorFont: string;
104
+ mathmlspacing: boolean;
105
+ skipAttributes: AnyObject;
106
+ exFactor: number;
107
+ displayAlign: string;
108
+ displayIndent: number | string;
109
+ linebreaks: {
110
+ inline: boolean;
111
+ width: number | string;
112
+ lineleading: number;
113
+ };
114
+ font: FontName;
115
+ fontPath: string;
116
+ fontExtensions: string[];
117
+ htmlHDW: "auto" | "use" | "force" | "ignore";
118
+ preFilters: string[];
119
+ postFilters: string[];
120
+ fontData: object;
121
+ [x: string]: any;
122
+ }
123
+ interface CHTMLOptions {
124
+ matchFontHeight: boolean;
125
+ fontURL: string;
126
+ dynamicPrefix: string;
127
+ adaptiveCSS: boolean;
128
+ }
129
+ export interface ConvertOptions {
130
+ inline: boolean;
131
+ em: number;
132
+ ex: number;
133
+ width: number;
134
+ }
135
+ export declare class MathjaxEngine {
136
+ option: Options;
137
+ adaptor: LiteAdaptor;
138
+ tex: TeX<N, T, D>;
139
+ chtml: CHTML<N, T, D>;
140
+ html: MathDocument<N, T, D>;
141
+ constructor(option?: Partial<Options>);
142
+ convert(tex: string, override?: Partial<ConvertOptions>): string;
143
+ stylesheet(): string;
144
+ }
145
+ export {};
@@ -0,0 +1,175 @@
1
+ import { MathJaxNewcmFont } from "@mathjax/mathjax-newcm-font/mjs/chtml.js";
2
+ import { MathJaxStix2Font } from "@mathjax/mathjax-stix2-font/mjs/chtml.js";
3
+ import { source as mjsource } from "@mathjax/src/components/mjs/source.js";
4
+ import { LiteElement } from "@mathjax/src/js/adaptors/lite/Element.js";
5
+ import { liteAdaptor } from "@mathjax/src/js/adaptors/liteAdaptor.js";
6
+ import { RegisterHTMLHandler } from "@mathjax/src/js/handlers/html.js";
7
+ import { TeX } from "@mathjax/src/js/input/tex.js";
8
+ import { mathjax } from "@mathjax/src/js/mathjax.js";
9
+ import { CHTML } from "@mathjax/src/js/output/chtml.js";
10
+ import { merge } from "../utils/merge.js";
11
+ import "@mathjax/src/js/input/tex/base/BaseConfiguration.js";
12
+ import "@mathjax/src/js/input/tex/ams/AmsConfiguration.js";
13
+ import "@mathjax/src/js/input/tex/newcommand/NewcommandConfiguration.js";
14
+ import "@mathjax/src/js/input/tex/noundefined/NoUndefinedConfiguration.js";
15
+ import "@mathjax/src/js/input/tex/action/ActionConfiguration.js";
16
+ import "@mathjax/src/js/input/tex/ams/AmsConfiguration.js";
17
+ import "@mathjax/src/js/input/tex/amscd/AmsCdConfiguration.js";
18
+ import "@mathjax/src/js/input/tex/autoload/AutoloadConfiguration.js";
19
+ import "@mathjax/src/js/input/tex/base/BaseConfiguration.js";
20
+ import "@mathjax/src/js/input/tex/bbm/BbmConfiguration.js";
21
+ import "@mathjax/src/js/input/tex/bboldx/BboldxConfiguration.js";
22
+ import "@mathjax/src/js/input/tex/bbox/BboxConfiguration.js";
23
+ import "@mathjax/src/js/input/tex/begingroup/BegingroupConfiguration.js";
24
+ import "@mathjax/src/js/input/tex/boldsymbol/BoldsymbolConfiguration.js";
25
+ import "@mathjax/src/js/input/tex/braket/BraketConfiguration.js";
26
+ import "@mathjax/src/js/input/tex/bussproofs/BussproofsConfiguration.js";
27
+ import "@mathjax/src/js/input/tex/cancel/CancelConfiguration.js";
28
+ import "@mathjax/src/js/input/tex/cases/CasesConfiguration.js";
29
+ import "@mathjax/src/js/input/tex/centernot/CenternotConfiguration.js";
30
+ import "@mathjax/src/js/input/tex/color/ColorConfiguration.js";
31
+ import "@mathjax/src/js/input/tex/colortbl/ColortblConfiguration.js";
32
+ import "@mathjax/src/js/input/tex/colorv2/ColorV2Configuration.js";
33
+ import "@mathjax/src/js/input/tex/configmacros/ConfigMacrosConfiguration.js";
34
+ import "@mathjax/src/js/input/tex/dsfont/DsfontConfiguration.js";
35
+ import "@mathjax/src/js/input/tex/empheq/EmpheqConfiguration.js";
36
+ import "@mathjax/src/js/input/tex/enclose/EncloseConfiguration.js";
37
+ import "@mathjax/src/js/input/tex/extpfeil/ExtpfeilConfiguration.js";
38
+ import "@mathjax/src/js/input/tex/gensymb/GensymbConfiguration.js";
39
+ import "@mathjax/src/js/input/tex/html/HtmlConfiguration.js";
40
+ import "@mathjax/src/js/input/tex/mathtools/MathtoolsConfiguration.js";
41
+ import "@mathjax/src/js/input/tex/mhchem/MhchemConfiguration.js";
42
+ import "@mathjax/src/js/input/tex/newcommand/NewcommandConfiguration.js";
43
+ import "@mathjax/src/js/input/tex/noerrors/NoErrorsConfiguration.js";
44
+ import "@mathjax/src/js/input/tex/noundefined/NoUndefinedConfiguration.js";
45
+ import "@mathjax/src/js/input/tex/physics/PhysicsConfiguration.js";
46
+ import "@mathjax/src/js/input/tex/require/RequireConfiguration.js";
47
+ import "@mathjax/src/js/input/tex/setoptions/SetOptionsConfiguration.js";
48
+ import "@mathjax/src/js/input/tex/tagformat/TagFormatConfiguration.js";
49
+ import "@mathjax/src/js/input/tex/texhtml/TexHtmlConfiguration.js";
50
+ import "@mathjax/src/js/input/tex/textcomp/TextcompConfiguration.js";
51
+ import "@mathjax/src/js/input/tex/textmacros/TextMacrosConfiguration.js";
52
+ import "@mathjax/src/js/input/tex/unicode/UnicodeConfiguration.js";
53
+ import "@mathjax/src/js/input/tex/units/UnitsConfiguration.js";
54
+ import "@mathjax/src/js/input/tex/upgreek/UpgreekConfiguration.js";
55
+ import "@mathjax/src/js/input/tex/verb/VerbConfiguration.js";
56
+ const fontNames = [
57
+ "mathjax-newcm",
58
+ "mathjax-stix2"
59
+ ];
60
+ function isFontName(name) {
61
+ return fontNames.includes(name);
62
+ }
63
+ const fontDataMap = {
64
+ "mathjax-newcm": MathJaxNewcmFont,
65
+ "mathjax-stix2": MathJaxStix2Font,
66
+ };
67
+ const texExtensions = Object.keys(mjsource)
68
+ .filter(name => name.substring(0, 6) === "[tex]/")
69
+ .map(name => name.substring(6))
70
+ .sort();
71
+ const packageList = [
72
+ "base",
73
+ "ams",
74
+ "newcommand",
75
+ "noundefined",
76
+ ].concat(texExtensions);
77
+ const MATHJAX_DEFAULT_FONT_URL = (name) => `https://cdn.jsdelivr.net/npm/@mathjax/${name}-font@4/chtml/woff2`;
78
+ const defaultMathOption = {
79
+ tex: {
80
+ packages: packageList,
81
+ },
82
+ output: {
83
+ scale: 1.21,
84
+ exFactor: 5,
85
+ font: "mathjax-newcm",
86
+ },
87
+ chtml: {
88
+ adaptiveCSS: true,
89
+ },
90
+ };
91
+ const defaultConvertOption = {
92
+ inline: false,
93
+ em: 16,
94
+ ex: 8,
95
+ width: 80 * 16,
96
+ };
97
+ export class MathjaxEngine {
98
+ option;
99
+ adaptor;
100
+ tex;
101
+ chtml;
102
+ html;
103
+ constructor(option) {
104
+ this.option = initOption(option);
105
+ this.adaptor = liteAdaptor();
106
+ RegisterHTMLHandler(this.adaptor);
107
+ const tex = new TeX(this.option.tex);
108
+ const chtml = new CHTML({
109
+ ...this.option.output,
110
+ ...this.option.chtml,
111
+ });
112
+ const html = mathjax.document("", {
113
+ InputJax: tex,
114
+ OutputJax: chtml,
115
+ });
116
+ html.addRenderAction("typeset", 155, renderDoc, renderMath);
117
+ this.tex = tex;
118
+ this.chtml = chtml;
119
+ this.html = html;
120
+ function renderDoc(_doc) { }
121
+ function renderMath(math, doc) {
122
+ const adaptor = doc.adaptor;
123
+ const text = adaptor.node("mjx-copytext", { "aria-hidden": true }, [
124
+ adaptor.text(math.math),
125
+ ]);
126
+ adaptor.setStyle(text, "position", "absolute");
127
+ adaptor.setStyle(text, "display", "none");
128
+ adaptor.setStyle(text, "width", "0");
129
+ adaptor.setStyle(math.typesetRoot, "position", "relative");
130
+ adaptor.append(math.typesetRoot, text);
131
+ }
132
+ }
133
+ convert(tex, override) {
134
+ const node = this.html.convert(tex, {
135
+ display: !(override?.inline ?? defaultConvertOption.inline),
136
+ em: override?.em ?? defaultConvertOption.em,
137
+ ex: override?.ex ?? defaultConvertOption.ex,
138
+ containerWidth: override?.width ?? defaultConvertOption.width,
139
+ scale: 1.0,
140
+ });
141
+ if (node instanceof LiteElement) {
142
+ return this.adaptor.outerHTML(node);
143
+ }
144
+ else {
145
+ return "ERROR";
146
+ }
147
+ }
148
+ stylesheet() {
149
+ return this.adaptor.textContent(this.chtml.styleSheet(this.html));
150
+ }
151
+ }
152
+ function initOption(opt) {
153
+ const option = merge(defaultMathOption, opt);
154
+ const packages = option?.tex?.packages;
155
+ if (typeof packages === "string") {
156
+ option.tex = option.tex ?? {};
157
+ option.tex.packages = packages.split(/\s*,\s*/);
158
+ }
159
+ if (option.output?.font !== undefined && typeof option.output.font === "string") {
160
+ let name = option.output.font.trim();
161
+ if (name === "default") {
162
+ name = "mathjax-newcm";
163
+ }
164
+ if (isFontName(name)) {
165
+ if (option.output.fontData === undefined) {
166
+ option.output.fontData = fontDataMap[name];
167
+ }
168
+ if (option.chtml?.fontURL === undefined) {
169
+ option.chtml = option.chtml ?? {};
170
+ option.chtml.fontURL = MATHJAX_DEFAULT_FONT_URL(name);
171
+ }
172
+ }
173
+ }
174
+ return option;
175
+ }
@@ -0,0 +1,3 @@
1
+ import type { PluginSimple } from "markdown-it";
2
+ import { MathjaxEngine } from "./mathjax.js";
3
+ export declare function mdmath(math: MathjaxEngine): PluginSimple;
@@ -0,0 +1,48 @@
1
+ import katex from "katex";
2
+ import { math_block, math_inline } from "./mdparser.js";
3
+ function getRenderers(mathjax) {
4
+ function renderInlineMath(tex) {
5
+ return katex.renderToString(tex, {
6
+ throwOnError: false,
7
+ strict: (code, _msg, _token) => {
8
+ switch (code) {
9
+ case "unicodeTextInMathMode":
10
+ return "ignore";
11
+ default:
12
+ return "warn";
13
+ }
14
+ },
15
+ });
16
+ }
17
+ function renderBlockMath(tex) {
18
+ try {
19
+ const math = mathjax.convert(tex);
20
+ return "<p>" + math + "</p>";
21
+ }
22
+ catch (err) {
23
+ console.error(err);
24
+ return tex;
25
+ }
26
+ }
27
+ function inlineRenderer(tokens, index) {
28
+ return renderInlineMath(tokens[index].content);
29
+ }
30
+ function blockRenderer(tokens, index) {
31
+ return renderBlockMath(tokens[index].content + "\n");
32
+ }
33
+ return {
34
+ inlineRenderer,
35
+ blockRenderer,
36
+ };
37
+ }
38
+ export function mdmath(math) {
39
+ const renderer = getRenderers(math);
40
+ return (md) => {
41
+ md.inline.ruler.after("escape", "math_inline", math_inline);
42
+ md.block.ruler.after("blockquote", "math_block", math_block, {
43
+ alt: ["paragraph", "reference", "blockquote", "list"],
44
+ });
45
+ md.renderer.rules.math_inline = renderer.inlineRenderer;
46
+ md.renderer.rules.math_block = renderer.blockRenderer;
47
+ };
48
+ }
@@ -0,0 +1,4 @@
1
+ import type StateBlock from "markdown-it/lib/rules_block/state_block.mjs";
2
+ import type StateInline from "markdown-it/lib/rules_inline/state_inline.mjs";
3
+ export declare function math_inline(state: StateInline, silent: boolean): boolean;
4
+ export declare function math_block(state: StateBlock, start: number, end: number, silent: boolean): boolean;
@@ -0,0 +1,124 @@
1
+ function isValidDelim(state, pos) {
2
+ const max = state.posMax;
3
+ let can_open = true;
4
+ let can_close = true;
5
+ const prevChar = pos > 0 ? state.src.charCodeAt(pos - 1) : -1;
6
+ const nextChar = pos + 1 <= max ? state.src.charCodeAt(pos + 1) : -1;
7
+ if (prevChar === 0x20 ||
8
+ prevChar === 0x09 ||
9
+ (nextChar >= 0x30 && nextChar <= 0x39)) {
10
+ can_close = false;
11
+ }
12
+ if (nextChar === 0x20 || nextChar === 0x09) {
13
+ can_open = false;
14
+ }
15
+ return {
16
+ can_open: can_open,
17
+ can_close: can_close,
18
+ };
19
+ }
20
+ export function math_inline(state, silent) {
21
+ let match, token, res, pos;
22
+ if (state.src[state.pos] !== "$") {
23
+ return false;
24
+ }
25
+ res = isValidDelim(state, state.pos);
26
+ if (!res.can_open) {
27
+ if (!silent) {
28
+ state.pending += "$";
29
+ }
30
+ state.pos += 1;
31
+ return true;
32
+ }
33
+ const start = state.pos + 1;
34
+ match = start;
35
+ while ((match = state.src.indexOf("$", match)) !== -1) {
36
+ pos = match - 1;
37
+ while (state.src[pos] === "\\") {
38
+ pos -= 1;
39
+ }
40
+ if ((match - pos) % 2 == 1) {
41
+ break;
42
+ }
43
+ match += 1;
44
+ }
45
+ if (match === -1) {
46
+ if (!silent) {
47
+ state.pending += "$";
48
+ }
49
+ state.pos = start;
50
+ return true;
51
+ }
52
+ if (match - start === 0) {
53
+ if (!silent) {
54
+ state.pending += "$$";
55
+ }
56
+ state.pos = start + 1;
57
+ return true;
58
+ }
59
+ res = isValidDelim(state, match);
60
+ if (!res.can_close) {
61
+ if (!silent) {
62
+ state.pending += "$";
63
+ }
64
+ state.pos = start;
65
+ return true;
66
+ }
67
+ if (!silent) {
68
+ token = state.push("math_inline", "math", 0);
69
+ token.markup = "$";
70
+ token.content = state.src.slice(start, match);
71
+ }
72
+ state.pos = match + 1;
73
+ return true;
74
+ }
75
+ export function math_block(state, start, end, silent) {
76
+ let firstLine;
77
+ let lastLine;
78
+ let next;
79
+ let lastPos;
80
+ let found = false;
81
+ let pos = state.bMarks[start] + state.tShift[start];
82
+ let max = state.eMarks[start];
83
+ if (pos + 2 > max) {
84
+ return false;
85
+ }
86
+ if (state.src.slice(pos, pos + 2) !== "$$") {
87
+ return false;
88
+ }
89
+ pos += 2;
90
+ firstLine = state.src.slice(pos, max);
91
+ if (silent) {
92
+ return true;
93
+ }
94
+ if (firstLine.trim().slice(-2) === "$$") {
95
+ firstLine = firstLine.trim().slice(0, -2);
96
+ found = true;
97
+ }
98
+ for (next = start; !found;) {
99
+ next++;
100
+ if (next >= end) {
101
+ break;
102
+ }
103
+ pos = state.bMarks[next] + state.tShift[next];
104
+ max = state.eMarks[next];
105
+ if (pos < max && state.tShift[next] < state.blkIndent) {
106
+ break;
107
+ }
108
+ if (state.src.slice(pos, max).trim().slice(-2) === "$$") {
109
+ lastPos = state.src.slice(0, max).lastIndexOf("$$");
110
+ lastLine = state.src.slice(pos, lastPos);
111
+ found = true;
112
+ }
113
+ }
114
+ state.line = next + 1;
115
+ const token = state.push("math_block", "math", 0);
116
+ token.block = true;
117
+ token.content =
118
+ (firstLine && firstLine.trim() ? firstLine + "\n" : "") +
119
+ state.getLines(start + 1, next, state.tShift[start], true) +
120
+ (lastLine && lastLine.trim() ? lastLine : "");
121
+ token.map = [start, state.line];
122
+ token.markup = "$$";
123
+ return true;
124
+ }
@@ -0,0 +1,12 @@
1
+ type Primitive = string | number | boolean | symbol | BigInt | null | undefined;
2
+ export type DeepPartial<T> = {
3
+ [P in keyof T]?: T[P] extends Array<infer U> ? Array<DeepPartial<U>> : T[P] extends object ? T[P] extends Function ? T[P] : DeepPartial<T[P]> : T[P];
4
+ };
5
+ type IsPlainObject<T> = T extends object ? T extends Function ? false : T extends any[] ? false : true : false;
6
+ type DeepMerged<T, U> = {
7
+ [K in keyof T | keyof U]: K extends keyof T ? K extends keyof U ? U[K] extends undefined ? T[K] : IsPlainObject<T[K]> extends true ? IsPlainObject<U[K]> extends true ? DeepMerged<T[K], U[K]> : U[K] : U[K] : T[K] : never;
8
+ };
9
+ export declare function isPrimitive(value: unknown): value is Primitive;
10
+ export declare function isFunction(value: unknown): value is Function;
11
+ export declare function merge<T, U>(target: Partial<T>, source?: Partial<U>): DeepMerged<T, U>;
12
+ export {};
@@ -0,0 +1,50 @@
1
+ export function isPrimitive(value) {
2
+ return (value === null
3
+ || typeof value === "string"
4
+ || typeof value === "number"
5
+ || typeof value === "boolean"
6
+ || typeof value === "symbol"
7
+ || typeof value === "bigint"
8
+ || typeof value === "undefined");
9
+ }
10
+ export function isFunction(value) {
11
+ return typeof value === "function";
12
+ }
13
+ export function merge(target, source) {
14
+ const seen = new WeakMap();
15
+ function _merge(target, source) {
16
+ if (seen.has(source)) {
17
+ return seen.get(source);
18
+ }
19
+ else if (isPrimitive(source) || isFunction(source)) {
20
+ return source;
21
+ }
22
+ else if (Array.isArray(source)) {
23
+ const result = source.map(item => _merge(undefined, item));
24
+ seen.set(source, result);
25
+ return result;
26
+ }
27
+ else if (typeof source === "object") {
28
+ const result = { ...target };
29
+ seen.set(source, result);
30
+ for (const key of Object.keys(source)) {
31
+ if (key === "__proto__" || key === "constructor" || key === "prototype") {
32
+ continue;
33
+ }
34
+ const value = source[key];
35
+ const merged = _merge(result[key], value);
36
+ if (merged !== undefined) {
37
+ result[key] = merged;
38
+ }
39
+ }
40
+ return result;
41
+ }
42
+ else {
43
+ return undefined;
44
+ }
45
+ }
46
+ const merged = _merge(target, source);
47
+ return merged === undefined
48
+ ? target
49
+ : merged;
50
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cobapen/markdown",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "A markdown converter for cobapen website",
5
5
  "keywords": [
6
6
  "markdown"
@@ -8,8 +8,8 @@
8
8
  "license": "MIT",
9
9
  "author": "yamavol",
10
10
  "type": "module",
11
- "main": "dist/index.js",
12
- "types": "dist/index.d.ts",
11
+ "main": "lib/index.js",
12
+ "types": "lib/index.d.ts",
13
13
  "homepage": "https://github.com/cobapen/markdown#readme",
14
14
  "bugs": {
15
15
  "url": "https://github.com/cobapen/markdown/issues"
@@ -19,8 +19,8 @@
19
19
  "url": "git+https://github.com/cobapen/markdown.git"
20
20
  },
21
21
  "files": [
22
- "dist/**/*.js",
23
- "dist/**/*.d.ts"
22
+ "lib/**/*.js",
23
+ "lib/**/*.d.ts"
24
24
  ],
25
25
  "engines": {
26
26
  "node": ">=20.11.0 <21 || >=21.2.0"
@@ -35,29 +35,28 @@
35
35
  "lint:fix": "eslint src --fix"
36
36
  },
37
37
  "dependencies": {
38
+ "@mathjax/mathjax-stix2-font": "^4.1.0",
39
+ "@mathjax/src": "^4.1.0",
38
40
  "highlight.js": "^11.11.1",
39
- "katex": "^0.16.22",
40
- "lodash-es": "^4.17.21",
41
+ "katex": "^0.16.27",
41
42
  "markdown-it": "^14.1.0",
42
- "markdown-it-adv-table": "^0.1.1",
43
+ "markdown-it-adv-table": "^0.1.2",
43
44
  "markdown-it-anchor": "^9.2.0",
44
- "markdown-it-cjk-breaks": "^2.0.0",
45
+ "markdown-it-cjk-breaks": "file:src/cjk-break",
45
46
  "markdown-it-deflist": "^3.0.0",
46
47
  "markdown-it-footnote": "^4.0.0",
47
- "markdown-it-table-of-contents": "^0.9.0",
48
- "mathjax-full": "^3.2.2"
48
+ "markdown-it-table-of-contents": "^1.1.0"
49
49
  },
50
50
  "devDependencies": {
51
- "@cobapen/eslint-config": "^0.4.0",
52
- "@types/katex": "^0.16.7",
53
- "@types/lodash-es": "^4.17.12",
51
+ "@cobapen/eslint-config": "^0.5.0",
52
+ "@types/katex": "^0.16.8",
54
53
  "@types/markdown-it": "^14.1.2",
55
- "@types/mustache": "^4.2.5",
56
- "@types/node": "^22.14.1",
57
- "@vitest/coverage-v8": "^3.1.1",
58
- "eslint": "^9.24.0",
54
+ "@types/mustache": "^4.2.6",
55
+ "@types/node": "^25.0.10",
56
+ "@vitest/coverage-v8": "^4.0.17",
57
+ "eslint": "^9.39.2",
59
58
  "mustache": "^4.2.0",
60
- "typescript": "^5.8.3",
61
- "vitest": "^3.1.1"
59
+ "typescript": "^5.9.3",
60
+ "vitest": "^4.0.17"
62
61
  }
63
62
  }