@rbbtsn0w/wechat-markdown 1.2.0 → 1.4.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.
- package/README.md +121 -52
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +31 -5
- package/dist/engine.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/inliner/dom-patcher.d.ts.map +1 -1
- package/dist/inliner/dom-patcher.js +34 -3
- package/dist/inliner/dom-patcher.js.map +1 -1
- package/dist/inliner/inliner.d.ts.map +1 -1
- package/dist/inliner/inliner.js.map +1 -1
- package/dist/media/formula.d.ts.map +1 -1
- package/dist/media/formula.js +4 -1
- package/dist/media/formula.js.map +1 -1
- package/dist/media/mermaid.d.ts +11 -1
- package/dist/media/mermaid.d.ts.map +1 -1
- package/dist/media/mermaid.js +58 -9
- package/dist/media/mermaid.js.map +1 -1
- package/dist/plugins/alerts.d.ts.map +1 -1
- package/dist/plugins/alerts.js.map +1 -1
- package/dist/plugins/code-decorator.d.ts +4 -2
- package/dist/plugins/code-decorator.d.ts.map +1 -1
- package/dist/plugins/code-decorator.js +109 -6
- package/dist/plugins/code-decorator.js.map +1 -1
- package/dist/plugins/footnotes.d.ts.map +1 -1
- package/dist/plugins/footnotes.js +4 -0
- package/dist/plugins/footnotes.js.map +1 -1
- package/dist/plugins/highlighter.d.ts +40 -0
- package/dist/plugins/highlighter.d.ts.map +1 -0
- package/dist/plugins/highlighter.js +205 -0
- package/dist/plugins/highlighter.js.map +1 -0
- package/dist/plugins/image-figure.d.ts +9 -0
- package/dist/plugins/image-figure.d.ts.map +1 -0
- package/dist/plugins/image-figure.js +52 -0
- package/dist/plugins/image-figure.js.map +1 -0
- package/dist/plugins/task-list.d.ts +9 -0
- package/dist/plugins/task-list.d.ts.map +1 -0
- package/dist/plugins/task-list.js +59 -0
- package/dist/plugins/task-list.js.map +1 -0
- package/dist/themes/geek.d.ts +1 -1
- package/dist/themes/geek.d.ts.map +1 -1
- package/dist/themes/geek.js +17 -0
- package/dist/themes/geek.js.map +1 -1
- package/dist/themes/grace.d.ts +1 -1
- package/dist/themes/grace.d.ts.map +1 -1
- package/dist/themes/grace.js +17 -0
- package/dist/themes/grace.js.map +1 -1
- package/dist/themes/index.d.ts.map +1 -1
- package/dist/themes/index.js +1 -3
- package/dist/themes/index.js.map +1 -1
- package/dist/themes/tech.d.ts +1 -1
- package/dist/themes/tech.d.ts.map +1 -1
- package/dist/themes/tech.js +13 -4
- package/dist/themes/tech.js.map +1 -1
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +8 -2
package/dist/media/mermaid.js
CHANGED
|
@@ -10,35 +10,84 @@ const os_1 = __importDefault(require("os"));
|
|
|
10
10
|
const crypto_1 = __importDefault(require("crypto"));
|
|
11
11
|
const axios_1 = __importDefault(require("axios"));
|
|
12
12
|
const pako_1 = __importDefault(require("pako"));
|
|
13
|
+
const sharp_1 = __importDefault(require("sharp"));
|
|
13
14
|
class MermaidRenderer {
|
|
14
15
|
tempDir;
|
|
15
|
-
|
|
16
|
+
timeoutMs;
|
|
17
|
+
maxRetries;
|
|
18
|
+
constructor(tempDir, options) {
|
|
16
19
|
this.tempDir = tempDir || path_1.default.join(os_1.default.tmpdir(), 'wechat-markdown-mermaid');
|
|
20
|
+
this.timeoutMs = options?.timeoutMs ?? 30000;
|
|
21
|
+
this.maxRetries = options?.maxRetries ?? 3;
|
|
17
22
|
if (!fs_1.default.existsSync(this.tempDir)) {
|
|
18
23
|
fs_1.default.mkdirSync(this.tempDir, { recursive: true });
|
|
19
24
|
}
|
|
20
25
|
}
|
|
21
26
|
getHash(mermaidCode) {
|
|
22
|
-
|
|
27
|
+
const sanitized = this.sanitizeMermaid(mermaidCode.trim());
|
|
28
|
+
return crypto_1.default.createHash('md5').update(sanitized).digest('hex');
|
|
23
29
|
}
|
|
24
30
|
getTargetPath(hash) {
|
|
25
31
|
return path_1.default.join(this.tempDir, `${hash}.png`);
|
|
26
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Preprocesses mermaid code to quote unquoted node labels with special characters like &, ?, (, )
|
|
35
|
+
*/
|
|
36
|
+
sanitizeMermaid(code) {
|
|
37
|
+
return code
|
|
38
|
+
.replace(/\[([^\]"'\n]+[&?()][^\]"'\n]*)\]/g, '["$1"]')
|
|
39
|
+
.replace(/\{([^}"'\n]+[&?()][^}"'\n]*)\}/g, '{"$1"}');
|
|
40
|
+
}
|
|
27
41
|
async renderToImage(mermaidCode) {
|
|
28
|
-
const
|
|
42
|
+
const sanitized = this.sanitizeMermaid(mermaidCode.trim());
|
|
43
|
+
const hash = this.getHash(sanitized);
|
|
29
44
|
const targetPath = this.getTargetPath(hash);
|
|
30
45
|
if (fs_1.default.existsSync(targetPath)) {
|
|
31
46
|
return targetPath;
|
|
32
47
|
}
|
|
33
|
-
const data = Buffer.from(
|
|
48
|
+
const data = Buffer.from(sanitized, 'utf8');
|
|
34
49
|
const compressed = pako_1.default.deflate(data, { level: 9 });
|
|
35
|
-
const result = Buffer.from(compressed)
|
|
50
|
+
const result = Buffer.from(compressed)
|
|
51
|
+
.toString('base64')
|
|
36
52
|
.replace(/\+/g, '-')
|
|
37
53
|
.replace(/\//g, '_');
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
54
|
+
const urls = [
|
|
55
|
+
`https://kroki.io/mermaid/png/${result}`,
|
|
56
|
+
`https://kroki.io/mermaid/svg/${result}`,
|
|
57
|
+
];
|
|
58
|
+
let lastError = null;
|
|
59
|
+
for (const url of urls) {
|
|
60
|
+
for (let attempt = 1; attempt <= this.maxRetries; attempt++) {
|
|
61
|
+
try {
|
|
62
|
+
const isSvg = url.includes('/svg/');
|
|
63
|
+
const response = await axios_1.default.get(url, {
|
|
64
|
+
responseType: isSvg ? 'text' : 'arraybuffer',
|
|
65
|
+
timeout: this.timeoutMs,
|
|
66
|
+
});
|
|
67
|
+
if (isSvg) {
|
|
68
|
+
const svgBuffer = Buffer.from(response.data, 'utf8');
|
|
69
|
+
await (0, sharp_1.default)(svgBuffer).png({ quality: 95 }).toFile(targetPath);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
fs_1.default.writeFileSync(targetPath, Buffer.from(response.data));
|
|
73
|
+
}
|
|
74
|
+
return targetPath;
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
lastError = err;
|
|
78
|
+
const status = err?.response?.status;
|
|
79
|
+
// Fail fast on client errors (4xx) other than rate limiting (429)
|
|
80
|
+
if (status && status >= 400 && status < 500 && status !== 429) {
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
if (attempt < this.maxRetries) {
|
|
84
|
+
const backoffMs = Math.min(1000 * Math.pow(2, attempt - 1), 8000);
|
|
85
|
+
await new Promise((res) => setTimeout(res, backoffMs));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
throw new Error(`Failed to render Mermaid diagram after retries: ${lastError?.message || 'Unknown error'}`);
|
|
42
91
|
}
|
|
43
92
|
}
|
|
44
93
|
exports.MermaidRenderer = MermaidRenderer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mermaid.js","sourceRoot":"","sources":["../../src/media/mermaid.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,4CAAoB;AACpB,oDAA4B;AAC5B,kDAA0B;AAC1B,gDAAwB;
|
|
1
|
+
{"version":3,"file":"mermaid.js","sourceRoot":"","sources":["../../src/media/mermaid.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,4CAAoB;AACpB,oDAA4B;AAC5B,kDAA0B;AAC1B,gDAAwB;AACxB,kDAA0B;AAO1B,MAAa,eAAe;IAClB,OAAO,CAAS;IAChB,SAAS,CAAS;IAClB,UAAU,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CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,OAAc,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"alerts.d.ts","sourceRoot":"","sources":["../../src/plugins/alerts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,aAAa,wyBAqBzB,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,OAAc,GAAG,MAAM,CA+B9E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alerts.js","sourceRoot":"","sources":["../../src/plugins/alerts.ts"],"names":[],"mappings":";;;AAiDA,
|
|
1
|
+
{"version":3,"file":"alerts.js","sourceRoot":"","sources":["../../src/plugins/alerts.ts"],"names":[],"mappings":";;;AAiDA,4CA+BC;AAhFD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACU,QAAA,aAAa,GAAG;;;;;;;;;;;;;;;;;;;;;CAqB5B,CAAC;AAEF,SAAgB,gBAAgB,CAAC,IAAY,EAAE,UAAmB,IAAI;IACpE,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,UAAU,GAAoD;QAClE,IAAI,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE;QACnC,GAAG,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE;QACjC,SAAS,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE;QAC7C,OAAO,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE;QACzC,OAAO,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE;KAC1C,CAAC;IAEF,uDAAuD;IACvD,MAAM,eAAe,GACnB,yGAAyG,CAAC;IAE5G,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,EAAE;QACpF,MAAM,IAAI,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC;QACrC,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QAC/D,MAAM,UAAU,GAAG,uBAAuB,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;QAE/D,MAAM,OAAO,GAAG,MAAM,aAAa,OAAO,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC;QAE/D,OAAO;qBACU,UAAU;iCACE,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,KAAK;IACxD,OAAO;;CAEV,CAAC,IAAI,EAAE,CAAC;IACP,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Structural styling for the markup this plugin emits, in neutral colors.
|
|
3
3
|
* Ships with the capability so a theme only has to supply brand overrides.
|
|
4
|
-
* Must never use !important
|
|
4
|
+
* Must never use !important on brand properties, but layout-critical properties
|
|
5
|
+
* like white-space: pre and overflow-x: auto must use !important so they
|
|
6
|
+
* survive WeChat Webview's aggressive global typography resets.
|
|
5
7
|
*/
|
|
6
|
-
export declare const codeDecoratorBaseCss = "\n.mac-code-wrapper {\n margin: 1.2em 0;\n border-radius: 6px;\n overflow: hidden;\n background-color: #282c34;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n}\n\n.mac-code-header {\n display: flex;\n align-items: center;\n justify-content: space-between;\n padding: 8px 14px;\n background-color: #21252b;\n border-bottom: 1px solid #181a1f;\n}\n\n.mac-dots {\n display: flex;\n gap: 6px;\n}\n\n.mac-dot {\n width: 10px;\n height: 10px;\n border-radius: 50%;\n}\n\n.mac-dot-red { background-color: #ff5f56; }\n.mac-dot-yellow { background-color: #ffbd2e; }\n.mac-dot-green { background-color: #27c93f; }\n\n.mac-code-lang {\n font-size: 11px;\n color: #7f848e;\n text-transform: uppercase;\n font-family: Menlo, Monaco, Consolas, monospace;\n}\n";
|
|
8
|
+
export declare const codeDecoratorBaseCss = "\n.mac-code-wrapper {\n margin: 1.2em 0;\n border-radius: 6px;\n overflow: hidden;\n background-color: #282c34;\n box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);\n}\n\n.mac-code-header {\n display: flex;\n align-items: center;\n justify-content: space-between;\n padding: 8px 14px;\n background-color: #21252b;\n border-bottom: 1px solid #181a1f;\n}\n\n.mac-dots {\n display: flex;\n gap: 6px;\n}\n\n.mac-dot {\n width: 10px;\n height: 10px;\n border-radius: 50%;\n}\n\n.mac-dot-red { background-color: #ff5f56; }\n.mac-dot-yellow { background-color: #ffbd2e; }\n.mac-dot-green { background-color: #27c93f; }\n\n.mac-code-lang {\n font-size: 11px;\n color: #7f848e;\n text-transform: uppercase;\n font-family: Menlo, Monaco, Consolas, monospace;\n}\n\n.mac-code-wrapper pre {\n margin: 0 !important;\n padding: 14px 16px !important;\n background-color: #282c34;\n color: #abb2bf;\n font-family: Consolas, Monaco, Menlo, \"Courier New\", monospace !important;\n font-size: 13px !important;\n line-height: 1.6 !important;\n overflow-x: auto !important;\n white-space: pre !important;\n word-break: normal !important;\n word-wrap: normal !important;\n display: block !important;\n -webkit-overflow-scrolling: touch !important;\n}\n\n.mac-code-wrapper pre code {\n font-family: inherit !important;\n font-size: inherit !important;\n padding: 0 !important;\n border: none !important;\n border-radius: 0 !important;\n display: block !important;\n white-space: pre !important;\n word-break: normal !important;\n word-wrap: normal !important;\n}\n";
|
|
7
9
|
export declare function decorateCodeBlocks(html: string, enabled?: boolean): string;
|
|
8
10
|
//# sourceMappingURL=code-decorator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-decorator.d.ts","sourceRoot":"","sources":["../../src/plugins/code-decorator.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"code-decorator.d.ts","sourceRoot":"","sources":["../../src/plugins/code-decorator.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,8iDAmEhC,CAAC;AA8EF,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,OAAc,GAAG,MAAM,CA2BhF"}
|
|
@@ -5,7 +5,9 @@ exports.decorateCodeBlocks = decorateCodeBlocks;
|
|
|
5
5
|
/**
|
|
6
6
|
* Structural styling for the markup this plugin emits, in neutral colors.
|
|
7
7
|
* Ships with the capability so a theme only has to supply brand overrides.
|
|
8
|
-
* Must never use !important
|
|
8
|
+
* Must never use !important on brand properties, but layout-critical properties
|
|
9
|
+
* like white-space: pre and overflow-x: auto must use !important so they
|
|
10
|
+
* survive WeChat Webview's aggressive global typography resets.
|
|
9
11
|
*/
|
|
10
12
|
exports.codeDecoratorBaseCss = `
|
|
11
13
|
.mac-code-wrapper {
|
|
@@ -46,15 +48,116 @@ exports.codeDecoratorBaseCss = `
|
|
|
46
48
|
text-transform: uppercase;
|
|
47
49
|
font-family: Menlo, Monaco, Consolas, monospace;
|
|
48
50
|
}
|
|
51
|
+
|
|
52
|
+
.mac-code-wrapper pre {
|
|
53
|
+
margin: 0 !important;
|
|
54
|
+
padding: 14px 16px !important;
|
|
55
|
+
background-color: #282c34;
|
|
56
|
+
color: #abb2bf;
|
|
57
|
+
font-family: Consolas, Monaco, Menlo, "Courier New", monospace !important;
|
|
58
|
+
font-size: 13px !important;
|
|
59
|
+
line-height: 1.6 !important;
|
|
60
|
+
overflow-x: auto !important;
|
|
61
|
+
white-space: pre !important;
|
|
62
|
+
word-break: normal !important;
|
|
63
|
+
word-wrap: normal !important;
|
|
64
|
+
display: block !important;
|
|
65
|
+
-webkit-overflow-scrolling: touch !important;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.mac-code-wrapper pre code {
|
|
69
|
+
font-family: inherit !important;
|
|
70
|
+
font-size: inherit !important;
|
|
71
|
+
padding: 0 !important;
|
|
72
|
+
border: none !important;
|
|
73
|
+
border-radius: 0 !important;
|
|
74
|
+
display: block !important;
|
|
75
|
+
white-space: pre !important;
|
|
76
|
+
word-break: normal !important;
|
|
77
|
+
word-wrap: normal !important;
|
|
78
|
+
}
|
|
49
79
|
`;
|
|
80
|
+
const LANGUAGE_DISPLAY_NAMES = {
|
|
81
|
+
ts: 'TYPESCRIPT',
|
|
82
|
+
typescript: 'TYPESCRIPT',
|
|
83
|
+
js: 'JAVASCRIPT',
|
|
84
|
+
javascript: 'JAVASCRIPT',
|
|
85
|
+
jsx: 'JSX',
|
|
86
|
+
tsx: 'TSX',
|
|
87
|
+
swift: 'SWIFT',
|
|
88
|
+
py: 'PYTHON',
|
|
89
|
+
python: 'PYTHON',
|
|
90
|
+
rb: 'RUBY',
|
|
91
|
+
ruby: 'RUBY',
|
|
92
|
+
sh: 'SHELL',
|
|
93
|
+
bash: 'BASH',
|
|
94
|
+
zsh: 'ZSH',
|
|
95
|
+
shell: 'SHELL',
|
|
96
|
+
console: 'CONSOLE',
|
|
97
|
+
terminal: 'TERMINAL',
|
|
98
|
+
json: 'JSON',
|
|
99
|
+
yml: 'YAML',
|
|
100
|
+
yaml: 'YAML',
|
|
101
|
+
md: 'MARKDOWN',
|
|
102
|
+
markdown: 'MARKDOWN',
|
|
103
|
+
html: 'HTML',
|
|
104
|
+
xml: 'XML',
|
|
105
|
+
css: 'CSS',
|
|
106
|
+
scss: 'SCSS',
|
|
107
|
+
less: 'LESS',
|
|
108
|
+
sql: 'SQL',
|
|
109
|
+
c: 'C',
|
|
110
|
+
cpp: 'C++',
|
|
111
|
+
'c++': 'C++',
|
|
112
|
+
cs: 'C#',
|
|
113
|
+
csharp: 'C#',
|
|
114
|
+
go: 'GO',
|
|
115
|
+
golang: 'GO',
|
|
116
|
+
rs: 'RUST',
|
|
117
|
+
rust: 'RUST',
|
|
118
|
+
java: 'JAVA',
|
|
119
|
+
kt: 'KOTLIN',
|
|
120
|
+
kotlin: 'KOTLIN',
|
|
121
|
+
dart: 'DART',
|
|
122
|
+
diff: 'DIFF',
|
|
123
|
+
docker: 'DOCKERFILE',
|
|
124
|
+
dockerfile: 'DOCKERFILE',
|
|
125
|
+
graphql: 'GRAPHQL',
|
|
126
|
+
gql: 'GRAPHQL',
|
|
127
|
+
text: 'TEXT',
|
|
128
|
+
txt: 'TEXT',
|
|
129
|
+
plaintext: 'TEXT',
|
|
130
|
+
};
|
|
131
|
+
function formatDisplayLanguage(rawClass) {
|
|
132
|
+
if (!rawClass) {
|
|
133
|
+
return 'CODE';
|
|
134
|
+
}
|
|
135
|
+
// 1. Extract language identifier from class string like "language-typescript", "language-swift"
|
|
136
|
+
const langMatch = rawClass.match(/language-([a-zA-Z0-9_+#.-]+)/i);
|
|
137
|
+
if (langMatch) {
|
|
138
|
+
const rawLang = langMatch[1].toLowerCase();
|
|
139
|
+
if (LANGUAGE_DISPLAY_NAMES[rawLang]) {
|
|
140
|
+
return LANGUAGE_DISPLAY_NAMES[rawLang];
|
|
141
|
+
}
|
|
142
|
+
return rawLang.toUpperCase();
|
|
143
|
+
}
|
|
144
|
+
// 2. Check for standalone language token
|
|
145
|
+
const token = rawClass.trim().split(/\s+/)[0]?.toLowerCase();
|
|
146
|
+
if (token && LANGUAGE_DISPLAY_NAMES[token]) {
|
|
147
|
+
return LANGUAGE_DISPLAY_NAMES[token];
|
|
148
|
+
}
|
|
149
|
+
return 'CODE';
|
|
150
|
+
}
|
|
50
151
|
function decorateCodeBlocks(html, enabled = true) {
|
|
51
152
|
if (!enabled) {
|
|
52
153
|
return html;
|
|
53
154
|
}
|
|
54
|
-
// Regex to match <pre
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
155
|
+
// Regex to match <pre...><code...>...</code></pre> across multiple formatting variations
|
|
156
|
+
// (with or without language classes, titles, or custom attributes)
|
|
157
|
+
const preRegex = /<pre\b[^>]*><code(?:\s+[^>]*class=["']([^"']+)["'][^>]*|[^>]*)>([\s\S]*?)<\/code><\/pre>/gi;
|
|
158
|
+
return html.replace(preRegex, (match, rawClass, codeContent) => {
|
|
159
|
+
const displayLang = formatDisplayLanguage(rawClass);
|
|
160
|
+
const codeClassAttr = rawClass ? ` class="${rawClass}"` : '';
|
|
58
161
|
return `
|
|
59
162
|
<section class="mac-code-wrapper">
|
|
60
163
|
<section class="mac-code-header">
|
|
@@ -65,7 +168,7 @@ function decorateCodeBlocks(html, enabled = true) {
|
|
|
65
168
|
</section>
|
|
66
169
|
<span class="mac-code-lang">${displayLang}</span>
|
|
67
170
|
</section>
|
|
68
|
-
<pre><code>${codeContent}</code></pre>
|
|
171
|
+
<pre><code${codeClassAttr}>${codeContent}</code></pre>
|
|
69
172
|
</section>
|
|
70
173
|
`.trim();
|
|
71
174
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-decorator.js","sourceRoot":"","sources":["../../src/plugins/code-decorator.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"code-decorator.js","sourceRoot":"","sources":["../../src/plugins/code-decorator.ts"],"names":[],"mappings":";;;AAwJA,gDA2BC;AAnLD;;;;;;GAMG;AACU,QAAA,oBAAoB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmEnC,CAAC;AAEF,MAAM,sBAAsB,GAA2B;IACrD,EAAE,EAAE,YAAY;IAChB,UAAU,EAAE,YAAY;IACxB,EAAE,EAAE,YAAY;IAChB,UAAU,EAAE,YAAY;IACxB,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,KAAK,EAAE,OAAO;IACd,EAAE,EAAE,QAAQ;IACZ,MAAM,EAAE,QAAQ;IAChB,EAAE,EAAE,MAAM;IACV,IAAI,EAAE,MAAM;IACZ,EAAE,EAAE,OAAO;IACX,IAAI,EAAE,MAAM;IACZ,GAAG,EAAE,KAAK;IACV,KAAK,EA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3B;AAED,wBAAgB,wBAAwB,
|
|
1
|
+
{"version":3,"file":"footnotes.d.ts","sourceRoot":"","sources":["../../src/plugins/footnotes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,kjBAkC5B,CAAC;AAEF,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,YAAY,EAAE,CAAC;CAC3B;AAED,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,MAAM,GACf,sBAAsB,CAgDxB;AAED,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,YAAY,EAAE,GAAG,MAAM,CAiBrE"}
|
|
@@ -53,6 +53,10 @@ function processMarkdownFootnotes(markdown, siteUrl) {
|
|
|
53
53
|
if (url.startsWith('#') || url.startsWith('javascript:') || url.startsWith('mailto:')) {
|
|
54
54
|
return false;
|
|
55
55
|
}
|
|
56
|
+
// WeChat allows internal article links on mp.weixin.qq.com natively
|
|
57
|
+
if (/^https?:\/\/([a-zA-Z0-9-]+\.)*mp\.weixin\.qq\.com(\/|$)/i.test(url)) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
56
60
|
if (siteUrl && url.startsWith(siteUrl)) {
|
|
57
61
|
return false;
|
|
58
62
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"footnotes.js","sourceRoot":"","sources":["../../src/plugins/footnotes.ts"],"names":[],"mappings":";;;AAkDA,
|
|
1
|
+
{"version":3,"file":"footnotes.js","sourceRoot":"","sources":["../../src/plugins/footnotes.ts"],"names":[],"mappings":";;;AAkDA,4DAmDC;AAED,kDAiBC;AAtHD;;;;;;GAMG;AACU,QAAA,gBAAgB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkC/B,CAAC;AAOF,SAAgB,wBAAwB,CACtC,QAAgB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AC,GAAG,EAAE,KAAK,CAAC,CAAC;YACvB,SAAS,CAAC,IAAI,CAAC;gBACb,KAAK;gBACL,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE;gBAClB,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE;aAChB,CAAC,CAAC;QACL,CAAC;QAED,OAAO,GAAG,IAAI,8BAA8B,KAAK,SAAS,CAAC;IAC7D,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,QAAQ,EAAE,mBAAmB;QAC7B,SAAS;KACV,CAAC;AACJ,CAAC;AAED,SAAgB,mBAAmB,CAAC,SAAyB;IAC3D,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,SAAS,GAAG,SAAS;SACxB,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACZ,OAAO,qCAAqC,IAAI,CAAC,KAAK,cAAc,IAAI,CAAC,KAAK,gCAAgC,IAAI,CAAC,GAAG,aAAa,CAAC;IACtI,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,OAAO;;;IAGL,SAAS;;CAEZ,CAAC,IAAI,EAAE,CAAC;AACT,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Syntax Highlighting Plugin for WeChat Official Account Markdown Rendering.
|
|
3
|
+
*
|
|
4
|
+
* Inspired by and adapted from the open-source industry standard doocs/md:
|
|
5
|
+
* https://github.com/doocs/md (MIT License)
|
|
6
|
+
*
|
|
7
|
+
* Uses highlight.js for AST-level lexical highlighting, generating class-tagged
|
|
8
|
+
* spans that are subsequently inlined by Juice into safe, bulletproof WeChat inline styles.
|
|
9
|
+
*/
|
|
10
|
+
export type HighlightThemeName = 'atom-one-dark' | 'github-light' | 'monokai';
|
|
11
|
+
export declare const atomOneDarkCss = "\n.markdown-body pre code.hljs, .mac-code-wrapper pre code.hljs, code.hljs, .hljs { color: #abb2bf; background: #282c34; background-color: #282c34; }\n.hljs-comment, .hljs-quote { color: #5c6370; font-style: italic; }\n.hljs-doctag, .hljs-keyword, .hljs-formula { color: #c678dd; font-weight: bold; }\n.hljs-section, .hljs-name, .hljs-selector-tag, .hljs-deletion, .hljs-subst { color: #e06c75; }\n.hljs-literal { color: #56b6c2; }\n.hljs-string, .hljs-regexp, .hljs-addition, .hljs-attribute, .hljs-meta .hljs-string { color: #98c379; }\n.hljs-built_in, .hljs-title.class_, .hljs-class .hljs-title { color: #e5c07b; }\n.hljs-attr, .hljs-variable, .hljs-template-variable, .hljs-type, .hljs-selector-attr, .hljs-selector-pseudo, .hljs-number { color: #d19a66; }\n.hljs-symbol, .hljs-bullet, .hljs-link, .hljs-meta, .hljs-selector-id, .hljs-title, .hljs-title.function_ { color: #61aeee; }\n.hljs-emphasis { font-style: italic; }\n.hljs-strong { font-weight: bold; }\n";
|
|
12
|
+
export declare const githubLightCss = "\n.markdown-body pre code.hljs, .mac-code-wrapper pre code.hljs, code.hljs, .hljs { color: #24292e; background: #f6f8fa; background-color: #f6f8fa; }\n.hljs-comment, .hljs-quote { color: #6a737d; font-style: italic; }\n.hljs-doctag, .hljs-keyword, .hljs-formula { color: #d73a49; font-weight: bold; }\n.hljs-section, .hljs-name, .hljs-selector-tag, .hljs-deletion, .hljs-subst { color: #d73a49; }\n.hljs-literal { color: #005cc5; }\n.hljs-string, .hljs-regexp, .hljs-addition, .hljs-attribute, .hljs-meta .hljs-string { color: #032f62; }\n.hljs-built_in, .hljs-title.class_, .hljs-class .hljs-title { color: #6f42c1; }\n.hljs-attr, .hljs-variable, .hljs-template-variable, .hljs-type, .hljs-selector-attr, .hljs-selector-pseudo, .hljs-number { color: #e36209; }\n.hljs-symbol, .hljs-bullet, .hljs-link, .hljs-meta, .hljs-selector-id, .hljs-title, .hljs-title.function_ { color: #005cc5; }\n.hljs-emphasis { font-style: italic; }\n.hljs-strong { font-weight: bold; }\n";
|
|
13
|
+
export declare const monokaiCss = "\n.markdown-body pre code.hljs, .mac-code-wrapper pre code.hljs, code.hljs, .hljs { color: #f8f8f2; background: #272822; background-color: #272822; }\n.hljs-comment, .hljs-quote { color: #75715e; font-style: italic; }\n.hljs-doctag, .hljs-keyword, .hljs-formula { color: #f92672; font-weight: bold; }\n.hljs-section, .hljs-name, .hljs-selector-tag, .hljs-deletion, .hljs-subst { color: #f92672; }\n.hljs-literal { color: #ae81ff; }\n.hljs-string, .hljs-regexp, .hljs-addition, .hljs-attribute, .hljs-meta .hljs-string { color: #e6db74; }\n.hljs-built_in, .hljs-title.class_, .hljs-class .hljs-title { color: #a6e22e; }\n.hljs-attr, .hljs-variable, .hljs-template-variable, .hljs-type, .hljs-selector-attr, .hljs-selector-pseudo, .hljs-number { color: #fd971f; }\n.hljs-symbol, .hljs-bullet, .hljs-link, .hljs-meta, .hljs-selector-id, .hljs-title, .hljs-title.function_ { color: #66d9ef; }\n.hljs-emphasis { font-style: italic; }\n.hljs-strong { font-weight: bold; }\n";
|
|
14
|
+
export declare const highlightBaseCss = "\n.markdown-body pre code.hljs, .mac-code-wrapper pre code.hljs, code.hljs, .hljs { color: #abb2bf; background: #282c34; background-color: #282c34; }\n.hljs-comment, .hljs-quote { color: #5c6370; font-style: italic; }\n.hljs-doctag, .hljs-keyword, .hljs-formula { color: #c678dd; font-weight: bold; }\n.hljs-section, .hljs-name, .hljs-selector-tag, .hljs-deletion, .hljs-subst { color: #e06c75; }\n.hljs-literal { color: #56b6c2; }\n.hljs-string, .hljs-regexp, .hljs-addition, .hljs-attribute, .hljs-meta .hljs-string { color: #98c379; }\n.hljs-built_in, .hljs-title.class_, .hljs-class .hljs-title { color: #e5c07b; }\n.hljs-attr, .hljs-variable, .hljs-template-variable, .hljs-type, .hljs-selector-attr, .hljs-selector-pseudo, .hljs-number { color: #d19a66; }\n.hljs-symbol, .hljs-bullet, .hljs-link, .hljs-meta, .hljs-selector-id, .hljs-title, .hljs-title.function_ { color: #61aeee; }\n.hljs-emphasis { font-style: italic; }\n.hljs-strong { font-weight: bold; }\n";
|
|
15
|
+
export declare function getHighlightCss(themeName?: HighlightThemeName | string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Split highlighted HTML into lines while preserving open <span> context.
|
|
18
|
+
* Adapts doocs/md approach to ensure proper tag closures on every line.
|
|
19
|
+
*/
|
|
20
|
+
export declare function splitHighlightedHtmlByLines(html: string): string[];
|
|
21
|
+
/**
|
|
22
|
+
* Replaces tab indentation and leading/consecutive whitespace with ,
|
|
23
|
+
* ensuring indentation survives WeChat rich text sanitization while preserving
|
|
24
|
+
* standard single spaces between words for searchability.
|
|
25
|
+
*/
|
|
26
|
+
export declare function formatCodeLine(lineHtml: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* Formats highlighted HTML into WeChat-bulletproof markup with explicit line breaks (<br/>)
|
|
29
|
+
* and non-breaking indentation spaces ( ) wrapped in a single block element,
|
|
30
|
+
* with optional line numbers column.
|
|
31
|
+
*/
|
|
32
|
+
export declare function formatHighlightedCode(rawHtml: string, showLineNumber?: boolean): string;
|
|
33
|
+
/**
|
|
34
|
+
* Highlights code using highlight.js with safe fallback to escaped plain text.
|
|
35
|
+
*/
|
|
36
|
+
export declare function highlightCode(code: string, rawLang?: string, showLineNumber?: boolean): {
|
|
37
|
+
highlighted: string;
|
|
38
|
+
language: string;
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=highlighter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"highlighter.d.ts","sourceRoot":"","sources":["../../src/plugins/highlighter.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,MAAM,MAAM,kBAAkB,GAAG,eAAe,GAAG,cAAc,GAAG,SAAS,CAAC;AAE9E,eAAO,MAAM,cAAc,48BAY1B,CAAC;AAEF,eAAO,MAAM,cAAc,48BAY1B,CAAC;AAEF,eAAO,MAAM,UAAU,48BAYtB,CAAC;AAEF,eAAO,MAAM,gBAAgB,48BAAiB,CAAC;AAE/C,wBAAgB,eAAe,CAAC,SAAS,CAAC,EAAE,kBAAkB,GAAG,MAAM,GAAG,MAAM,CAU/E;AAWD;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAuClE;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAavD;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,cAAc,GAAE,OAAe,GAAG,MAAM,CAmB9F;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,EAChB,cAAc,GAAE,OAAe,GAC9B;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAwC3C"}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Syntax Highlighting Plugin for WeChat Official Account Markdown Rendering.
|
|
4
|
+
*
|
|
5
|
+
* Inspired by and adapted from the open-source industry standard doocs/md:
|
|
6
|
+
* https://github.com/doocs/md (MIT License)
|
|
7
|
+
*
|
|
8
|
+
* Uses highlight.js for AST-level lexical highlighting, generating class-tagged
|
|
9
|
+
* spans that are subsequently inlined by Juice into safe, bulletproof WeChat inline styles.
|
|
10
|
+
*/
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.highlightBaseCss = exports.monokaiCss = exports.githubLightCss = exports.atomOneDarkCss = void 0;
|
|
16
|
+
exports.getHighlightCss = getHighlightCss;
|
|
17
|
+
exports.splitHighlightedHtmlByLines = splitHighlightedHtmlByLines;
|
|
18
|
+
exports.formatCodeLine = formatCodeLine;
|
|
19
|
+
exports.formatHighlightedCode = formatHighlightedCode;
|
|
20
|
+
exports.highlightCode = highlightCode;
|
|
21
|
+
const highlight_js_1 = __importDefault(require("highlight.js"));
|
|
22
|
+
exports.atomOneDarkCss = `
|
|
23
|
+
.markdown-body pre code.hljs, .mac-code-wrapper pre code.hljs, code.hljs, .hljs { color: #abb2bf; background: #282c34; background-color: #282c34; }
|
|
24
|
+
.hljs-comment, .hljs-quote { color: #5c6370; font-style: italic; }
|
|
25
|
+
.hljs-doctag, .hljs-keyword, .hljs-formula { color: #c678dd; font-weight: bold; }
|
|
26
|
+
.hljs-section, .hljs-name, .hljs-selector-tag, .hljs-deletion, .hljs-subst { color: #e06c75; }
|
|
27
|
+
.hljs-literal { color: #56b6c2; }
|
|
28
|
+
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-attribute, .hljs-meta .hljs-string { color: #98c379; }
|
|
29
|
+
.hljs-built_in, .hljs-title.class_, .hljs-class .hljs-title { color: #e5c07b; }
|
|
30
|
+
.hljs-attr, .hljs-variable, .hljs-template-variable, .hljs-type, .hljs-selector-attr, .hljs-selector-pseudo, .hljs-number { color: #d19a66; }
|
|
31
|
+
.hljs-symbol, .hljs-bullet, .hljs-link, .hljs-meta, .hljs-selector-id, .hljs-title, .hljs-title.function_ { color: #61aeee; }
|
|
32
|
+
.hljs-emphasis { font-style: italic; }
|
|
33
|
+
.hljs-strong { font-weight: bold; }
|
|
34
|
+
`;
|
|
35
|
+
exports.githubLightCss = `
|
|
36
|
+
.markdown-body pre code.hljs, .mac-code-wrapper pre code.hljs, code.hljs, .hljs { color: #24292e; background: #f6f8fa; background-color: #f6f8fa; }
|
|
37
|
+
.hljs-comment, .hljs-quote { color: #6a737d; font-style: italic; }
|
|
38
|
+
.hljs-doctag, .hljs-keyword, .hljs-formula { color: #d73a49; font-weight: bold; }
|
|
39
|
+
.hljs-section, .hljs-name, .hljs-selector-tag, .hljs-deletion, .hljs-subst { color: #d73a49; }
|
|
40
|
+
.hljs-literal { color: #005cc5; }
|
|
41
|
+
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-attribute, .hljs-meta .hljs-string { color: #032f62; }
|
|
42
|
+
.hljs-built_in, .hljs-title.class_, .hljs-class .hljs-title { color: #6f42c1; }
|
|
43
|
+
.hljs-attr, .hljs-variable, .hljs-template-variable, .hljs-type, .hljs-selector-attr, .hljs-selector-pseudo, .hljs-number { color: #e36209; }
|
|
44
|
+
.hljs-symbol, .hljs-bullet, .hljs-link, .hljs-meta, .hljs-selector-id, .hljs-title, .hljs-title.function_ { color: #005cc5; }
|
|
45
|
+
.hljs-emphasis { font-style: italic; }
|
|
46
|
+
.hljs-strong { font-weight: bold; }
|
|
47
|
+
`;
|
|
48
|
+
exports.monokaiCss = `
|
|
49
|
+
.markdown-body pre code.hljs, .mac-code-wrapper pre code.hljs, code.hljs, .hljs { color: #f8f8f2; background: #272822; background-color: #272822; }
|
|
50
|
+
.hljs-comment, .hljs-quote { color: #75715e; font-style: italic; }
|
|
51
|
+
.hljs-doctag, .hljs-keyword, .hljs-formula { color: #f92672; font-weight: bold; }
|
|
52
|
+
.hljs-section, .hljs-name, .hljs-selector-tag, .hljs-deletion, .hljs-subst { color: #f92672; }
|
|
53
|
+
.hljs-literal { color: #ae81ff; }
|
|
54
|
+
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-attribute, .hljs-meta .hljs-string { color: #e6db74; }
|
|
55
|
+
.hljs-built_in, .hljs-title.class_, .hljs-class .hljs-title { color: #a6e22e; }
|
|
56
|
+
.hljs-attr, .hljs-variable, .hljs-template-variable, .hljs-type, .hljs-selector-attr, .hljs-selector-pseudo, .hljs-number { color: #fd971f; }
|
|
57
|
+
.hljs-symbol, .hljs-bullet, .hljs-link, .hljs-meta, .hljs-selector-id, .hljs-title, .hljs-title.function_ { color: #66d9ef; }
|
|
58
|
+
.hljs-emphasis { font-style: italic; }
|
|
59
|
+
.hljs-strong { font-weight: bold; }
|
|
60
|
+
`;
|
|
61
|
+
exports.highlightBaseCss = exports.atomOneDarkCss;
|
|
62
|
+
function getHighlightCss(themeName) {
|
|
63
|
+
switch (themeName) {
|
|
64
|
+
case 'github-light':
|
|
65
|
+
return exports.githubLightCss;
|
|
66
|
+
case 'monokai':
|
|
67
|
+
return exports.monokaiCss;
|
|
68
|
+
case 'atom-one-dark':
|
|
69
|
+
default:
|
|
70
|
+
return exports.atomOneDarkCss;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function escapeHtml(text) {
|
|
74
|
+
return text
|
|
75
|
+
.replace(/&/g, '&')
|
|
76
|
+
.replace(/</g, '<')
|
|
77
|
+
.replace(/>/g, '>')
|
|
78
|
+
.replace(/"/g, '"')
|
|
79
|
+
.replace(/\x27/g, ''');
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Split highlighted HTML into lines while preserving open <span> context.
|
|
83
|
+
* Adapts doocs/md approach to ensure proper tag closures on every line.
|
|
84
|
+
*/
|
|
85
|
+
function splitHighlightedHtmlByLines(html) {
|
|
86
|
+
const lines = [];
|
|
87
|
+
let currentLine = '';
|
|
88
|
+
const openTags = [];
|
|
89
|
+
let i = 0;
|
|
90
|
+
while (i < html.length) {
|
|
91
|
+
if (html[i] === '<') {
|
|
92
|
+
let tag = '<';
|
|
93
|
+
i++;
|
|
94
|
+
while (i < html.length && html[i] !== '>') {
|
|
95
|
+
tag += html[i];
|
|
96
|
+
i++;
|
|
97
|
+
}
|
|
98
|
+
if (i < html.length) {
|
|
99
|
+
tag += '>';
|
|
100
|
+
i++;
|
|
101
|
+
}
|
|
102
|
+
currentLine += tag;
|
|
103
|
+
if (tag.startsWith('</span')) {
|
|
104
|
+
openTags.pop();
|
|
105
|
+
}
|
|
106
|
+
else if (tag.startsWith('<span')) {
|
|
107
|
+
openTags.push(tag);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else if (html[i] === '\n') {
|
|
111
|
+
const closingTags = '</span>'.repeat(openTags.length);
|
|
112
|
+
lines.push(currentLine + closingTags);
|
|
113
|
+
currentLine = openTags.join('');
|
|
114
|
+
i++;
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
currentLine += html[i];
|
|
118
|
+
i++;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
lines.push(currentLine);
|
|
122
|
+
return lines;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Replaces tab indentation and leading/consecutive whitespace with ,
|
|
126
|
+
* ensuring indentation survives WeChat rich text sanitization while preserving
|
|
127
|
+
* standard single spaces between words for searchability.
|
|
128
|
+
*/
|
|
129
|
+
function formatCodeLine(lineHtml) {
|
|
130
|
+
let formatted = lineHtml.replace(/\t/g, ' ');
|
|
131
|
+
// Transform only the text content outside tags:
|
|
132
|
+
formatted = formatted.replace(/(<[^>]+>)|([^<]+)/g, (match, tag, text) => {
|
|
133
|
+
if (tag)
|
|
134
|
+
return tag;
|
|
135
|
+
return text.replace(/ {2,}/g, (m) => ' '.repeat(m.length));
|
|
136
|
+
});
|
|
137
|
+
// Match leading spaces, even if preceded by open tags like <span ...>
|
|
138
|
+
formatted = formatted.replace(/^((?:<[^>]+>)*)( +)/, (_, tags, spaces) => tags + ' '.repeat(spaces.length));
|
|
139
|
+
return formatted === '' ? ' ' : formatted;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Formats highlighted HTML into WeChat-bulletproof markup with explicit line breaks (<br/>)
|
|
143
|
+
* and non-breaking indentation spaces ( ) wrapped in a single block element,
|
|
144
|
+
* with optional line numbers column.
|
|
145
|
+
*/
|
|
146
|
+
function formatHighlightedCode(rawHtml, showLineNumber = false) {
|
|
147
|
+
const lines = splitHighlightedHtmlByLines(rawHtml).map(formatCodeLine);
|
|
148
|
+
if (showLineNumber && lines.length > 0) {
|
|
149
|
+
const lineNumbersHtml = lines
|
|
150
|
+
.map((_, idx) => `<span style="display: block; line-height: 1.6; padding: 0 8px 0 0; text-align: right;">${idx + 1}</span>`)
|
|
151
|
+
.join('');
|
|
152
|
+
const codeContentHtml = lines.join('<br/>');
|
|
153
|
+
return `
|
|
154
|
+
<span style="display: flex; align-items: flex-start; width: 100%; box-sizing: border-box;">
|
|
155
|
+
<span class="code-line-numbers" style="display: block; padding: 0 10px 0 0; border-right: 1px solid rgba(255, 255, 255, 0.1); user-select: none; color: #5c6370; font-size: inherit; font-family: inherit;">${lineNumbersHtml}</span>
|
|
156
|
+
<span class="code-scroll" style="display: block; flex: 1 1 auto; overflow-x: auto; padding-left: 12px; min-width: 0;">
|
|
157
|
+
<span class="code-block__inner" style="display: block;">${codeContentHtml}</span>
|
|
158
|
+
</span>
|
|
159
|
+
</span>`.trim();
|
|
160
|
+
}
|
|
161
|
+
return `<span class="code-block__inner" style="display: block;">${lines.join('<br/>')}</span>`;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Highlights code using highlight.js with safe fallback to escaped plain text.
|
|
165
|
+
*/
|
|
166
|
+
function highlightCode(code, rawLang, showLineNumber = false) {
|
|
167
|
+
const cleanLang = (rawLang || '')
|
|
168
|
+
.trim()
|
|
169
|
+
.toLowerCase()
|
|
170
|
+
.match(/^[a-zA-Z0-9_#+.-]+/)?.[0] || '';
|
|
171
|
+
const normalizedCode = code.replace(/\r\n?/g, '\n');
|
|
172
|
+
// Try explicit language match
|
|
173
|
+
if (cleanLang && highlight_js_1.default.getLanguage(cleanLang)) {
|
|
174
|
+
try {
|
|
175
|
+
const result = highlight_js_1.default.highlight(normalizedCode, { language: cleanLang, ignoreIllegals: true });
|
|
176
|
+
return {
|
|
177
|
+
highlighted: formatHighlightedCode(result.value, showLineNumber),
|
|
178
|
+
language: cleanLang,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
catch {
|
|
182
|
+
// Fallback
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
// Automatic language detection if code is reasonably sized
|
|
186
|
+
if (!cleanLang && normalizedCode.length > 10) {
|
|
187
|
+
try {
|
|
188
|
+
const auto = highlight_js_1.default.highlightAuto(normalizedCode);
|
|
189
|
+
if (auto.language && auto.relevance > 3) {
|
|
190
|
+
return {
|
|
191
|
+
highlighted: formatHighlightedCode(auto.value, showLineNumber),
|
|
192
|
+
language: auto.language,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
// Fallback
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
highlighted: formatHighlightedCode(escapeHtml(normalizedCode), showLineNumber),
|
|
202
|
+
language: cleanLang || 'plaintext',
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=highlighter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"highlighter.js","sourceRoot":"","sources":["../../src/plugins/highlighter.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;;;;;AAkDH,0CAUC;AAeD,kEAuCC;AAOD,wCAaC;AAOD,sDAmBC;AAKD,sCA4CC;AA/MD,gEAAgC;AAInB,QAAA,cAAc,GAAG;;;;;;;;;;;;CAY7B,CAAC;AAEW,QAAA,cAAc,GAAG;;;;;;;;;;;;CAY7B,CAAC;AAEW,QAAA,UAAU,GAAG;;;;;;;;;;;;CAYzB,CAAC;AAEW,QAAA,gBAAgB,GAAG,sBAAc,CAAC;AAE/C,SAAgB,eAAe,CAAC,SAAuC;IACrE,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,cAAc;YACjB,OAAO,sBAAc,CAAC;QACxB,KAAK,SAAS;YACZ,OAAO,kBAAU,CAAC;QACpB,KAAK,eAAe,CAAC;QACrB;YACE,OAAO,sBAAc,CAAC;IAC1B,CAAC;AACH,CAAC;AAED,SAAS,UAAU,CAAC,IAAY;IAC9B,OAAO,IAAI;SACR,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;SACtB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,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AAC;QAC7C,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,sBAAI,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC;YAChD,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,SAAS,GAAG,CAAC,EAAE,CAAC;gBACxC,OAAO;oBACL,WAAW,EAAE,qBAAqB,CAAC,IAAI,CAAC,KAAK,EAAE,cAAc,CAAC;oBAC9D,QAAQ,EAAE,IAAI,CAAC,QAAQ;iBACxB,CAAC;YACJ,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,WAAW;QACb,CAAC;IACH,CAAC;IAED,OAAO;QACL,WAAW,EAAE,qBAAqB,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE,cAAc,CAAC;QAC9E,QAAQ,EAAE,SAAS,IAAI,WAAW;KACnC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Image Figure and Caption Plugin for WeChat Official Accounts.
|
|
3
|
+
*
|
|
4
|
+
* Wraps Markdown images in dedicated figure containers and renders
|
|
5
|
+
* accessible, stylized captions from image title or alt attributes.
|
|
6
|
+
*/
|
|
7
|
+
export declare const imageFigureBaseCss = "\n.wm-image-figure {\n text-align: center !important;\n margin: 1.5em 0 !important;\n}\n\n.wm-image-figure img {\n max-width: 100%;\n height: auto;\n border-radius: 6px;\n display: block;\n margin: 0 auto;\n}\n\n.wm-image-caption {\n display: block !important;\n text-align: center !important;\n font-size: 13px !important;\n color: #888888 !important;\n margin-top: 6px !important;\n line-height: 1.5 !important;\n}\n";
|
|
8
|
+
export declare function processImageFigures(html: string, enabled?: boolean): string;
|
|
9
|
+
//# sourceMappingURL=image-figure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image-figure.d.ts","sourceRoot":"","sources":["../../src/plugins/image-figure.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,kBAAkB,obAsB9B,CAAC;AAEF,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,OAAc,GAAG,MAAM,CAsBjF"}
|