@rbbtsn0w/wechat-markdown 1.1.1

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.
Files changed (66) hide show
  1. package/README.md +176 -0
  2. package/dist/engine.d.ts +33 -0
  3. package/dist/engine.d.ts.map +1 -0
  4. package/dist/engine.js +289 -0
  5. package/dist/engine.js.map +1 -0
  6. package/dist/index.d.ts +13 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +29 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/inliner/dom-patcher.d.ts +4 -0
  11. package/dist/inliner/dom-patcher.d.ts.map +1 -0
  12. package/dist/inliner/dom-patcher.js +46 -0
  13. package/dist/inliner/dom-patcher.js.map +1 -0
  14. package/dist/inliner/inliner.d.ts +14 -0
  15. package/dist/inliner/inliner.d.ts.map +1 -0
  16. package/dist/inliner/inliner.js +35 -0
  17. package/dist/inliner/inliner.js.map +1 -0
  18. package/dist/media/formula.d.ts +8 -0
  19. package/dist/media/formula.d.ts.map +1 -0
  20. package/dist/media/formula.js +54 -0
  21. package/dist/media/formula.js.map +1 -0
  22. package/dist/media/mermaid.d.ts +8 -0
  23. package/dist/media/mermaid.d.ts.map +1 -0
  24. package/dist/media/mermaid.js +45 -0
  25. package/dist/media/mermaid.js.map +1 -0
  26. package/dist/media/styles.d.ts +17 -0
  27. package/dist/media/styles.d.ts.map +1 -0
  28. package/dist/media/styles.js +47 -0
  29. package/dist/media/styles.js.map +1 -0
  30. package/dist/plugins/alerts.d.ts +29 -0
  31. package/dist/plugins/alerts.d.ts.map +1 -0
  32. package/dist/plugins/alerts.js +79 -0
  33. package/dist/plugins/alerts.js.map +1 -0
  34. package/dist/plugins/code-decorator.d.ts +8 -0
  35. package/dist/plugins/code-decorator.d.ts.map +1 -0
  36. package/dist/plugins/code-decorator.js +73 -0
  37. package/dist/plugins/code-decorator.js.map +1 -0
  38. package/dist/plugins/footnotes.d.ts +16 -0
  39. package/dist/plugins/footnotes.d.ts.map +1 -0
  40. package/dist/plugins/footnotes.js +103 -0
  41. package/dist/plugins/footnotes.js.map +1 -0
  42. package/dist/plugins/table-scroller.d.ts +7 -0
  43. package/dist/plugins/table-scroller.d.ts.map +1 -0
  44. package/dist/plugins/table-scroller.js +24 -0
  45. package/dist/plugins/table-scroller.js.map +1 -0
  46. package/dist/themes/geek.d.ts +2 -0
  47. package/dist/themes/geek.d.ts.map +1 -0
  48. package/dist/themes/geek.js +147 -0
  49. package/dist/themes/geek.js.map +1 -0
  50. package/dist/themes/grace.d.ts +2 -0
  51. package/dist/themes/grace.d.ts.map +1 -0
  52. package/dist/themes/grace.js +148 -0
  53. package/dist/themes/grace.js.map +1 -0
  54. package/dist/themes/index.d.ts +12 -0
  55. package/dist/themes/index.d.ts.map +1 -0
  56. package/dist/themes/index.js +48 -0
  57. package/dist/themes/index.js.map +1 -0
  58. package/dist/themes/tech.d.ts +2 -0
  59. package/dist/themes/tech.d.ts.map +1 -0
  60. package/dist/themes/tech.js +253 -0
  61. package/dist/themes/tech.js.map +1 -0
  62. package/dist/types/index.d.ts +75 -0
  63. package/dist/types/index.d.ts.map +1 -0
  64. package/dist/types/index.js +3 -0
  65. package/dist/types/index.js.map +1 -0
  66. package/package.json +75 -0
package/README.md ADDED
@@ -0,0 +1,176 @@
1
+ # @rbbtsn0w/wechat-markdown
2
+
3
+ > High-fidelity Markdown to WeChat Official Account HTML converter SDK & middleware.
4
+
5
+ An extensible, headless TypeScript SDK designed to convert Markdown into pixel-perfect, WeChat Official Account compatible HTML with inlined CSS styles, footnotes, math rendering, and mobile-friendly layouts.
6
+
7
+ ## 🌟 Highlights
8
+
9
+ - 🎨 **Multi-Theme System**: Built-in `tech` (Modern Blue), `grace` (Morandi Green), and `geek` (High Contrast Orange/Dark) themes with custom CSS support.
10
+ - 📱 **WeChat Quirks Fixed**:
11
+ - Eliminates Phantom Bullets by stripping `\n` whitespace around `<li>` tags.
12
+ - Sanitizes forbidden IDs and classes while preserving computed inline `style` attributes.
13
+ - 🔗 **Automatic Footnotes**: Converts external links `[Text](URL)` into `Text[1]` and automatically appends a formatted reference list at the bottom.
14
+ - 💻 **Mac-Style Code Blocks**: Elegant terminal headers with red, yellow, and green dots, language badges, and horizontal scroll containers.
15
+ - 📊 **Responsive Tables**: Wraps Markdown tables in `-webkit-overflow-scrolling: touch` containers to avoid narrow screen distortion on mobile.
16
+ - 🧮 **LaTeX & Mermaid**: Renders inline `$...$` and block `$$...$$` MathJax formulas, and Mermaid diagrams (with fallback degradation).
17
+ - 🔌 **Async Image Resolver Hook**: Allows injecting custom image uploading/CDN routing pipelines before final HTML generation.
18
+
19
+ ## 📦 Installation
20
+
21
+ ```bash
22
+ npm install @rbbtsn0w/wechat-markdown
23
+ ```
24
+
25
+ ## Releasing
26
+
27
+ Releases from `main` publish to npm using trusted publishing. A package that has never been published to npm must be bootstrapped manually because it has no npm settings page yet:
28
+
29
+ ```bash
30
+ npm login
31
+ npm whoami
32
+ npm publish --dry-run --access public
33
+ npm publish --access public
34
+ ```
35
+
36
+ After that first publish succeeds, configure the package's trusted publisher on npmjs.com with:
37
+
38
+ - GitHub user: `RbBtSn0w`
39
+ - Repository: `wechat-markdown`
40
+ - Workflow: `release.yml`
41
+ - Allowed action: `npm publish`
42
+
43
+ The workflow uses GitHub Actions OIDC and requires no npm publish token. Future releases from this public repository automatically create npm provenance attestations.
44
+
45
+ ## 🚀 Quick Start
46
+
47
+ ### Functional API
48
+
49
+ ```typescript
50
+ import { renderMarkdownToWechat } from '@rbbtsn0w/wechat-markdown';
51
+
52
+ const markdown = `---
53
+ title: "Getting Started"
54
+ ---
55
+
56
+ # Hello WeChat!
57
+
58
+ Here is an external link to [Google](https://google.com) and a code block:
59
+
60
+ \`\`\`typescript
61
+ const greeting = "Hello, world!";
62
+ console.log(greeting);
63
+ \`\`\`
64
+ `;
65
+
66
+ const result = await renderMarkdownToWechat(markdown, {
67
+ theme: 'tech', // 'tech' | 'grace' | 'geek' | ThemeConfig
68
+ footnoteLinks: true, // Convert external links to footnotes
69
+ macCodeBlock: true, // Add Mac styling to code blocks
70
+ tableScroller: true, // Responsive table wrappers
71
+ resolveImage: async (src, alt) => {
72
+ // Optional: upload local image to CDN and return remote URL
73
+ return src;
74
+ },
75
+ });
76
+
77
+ console.log(result.html); // WeChat-ready inline HTML
78
+ console.log(result.title); // "Getting Started"
79
+ console.log(result.footnotes); // Footnote items
80
+ ```
81
+
82
+ ### Class-based Engine
83
+
84
+ ```typescript
85
+ import { WechatMarkdownEngine } from '@rbbtsn0w/wechat-markdown';
86
+
87
+ const engine = new WechatMarkdownEngine();
88
+ const result = await engine.render(markdown, { theme: 'grace' });
89
+ ```
90
+
91
+ ## 🎨 Theming: two layers
92
+
93
+ Styling is applied in two layers, concatenated in this order before `juice`
94
+ inlines them:
95
+
96
+ | Layer | Content | Owner |
97
+ | --- | --- | --- |
98
+ | **Capability base CSS** | Structural rules for the markup each enabled capability emits (`.mac-code-wrapper`, `.gfm-alert*`, `.table-scroller`, `.footnote*`, `.wm-formula-*`, `.wm-mermaid`), in neutral colors | Ships with the capability |
99
+ | **Theme (+ `customCss`)** | Brand appearance — colors, type scale, spacing | You |
100
+
101
+ A theme therefore only has to declare what it wants to *change*. A 20-line
102
+ brand sheet that styles nothing but `.markdown-body` typography still renders
103
+ Mac code chrome and GFM alerts correctly, because the base layer supplies them.
104
+
105
+ Two rules when writing a theme or your own base CSS:
106
+
107
+ - **Base CSS must never use `!important`.** The theme is layered after it, and
108
+ `!important` in the base layer would beat every brand override.
109
+ - **Beware element-scoped theme rules.** `.markdown-body img { ... }` and
110
+ `.markdown-body blockquote { ... }` have specificity (0,1,1) and outrank a
111
+ bare `.wm-formula-inline` or `.gfm-alert-note` (0,1,0) regardless of order.
112
+ The affected base rules are therefore scoped one level higher —
113
+ `.markdown-body img.wm-formula-inline` and
114
+ `.markdown-body blockquote.gfm-alert-note` (0,2,1). To override them, match
115
+ that specificity (all three built-in themes do) or use `!important`.
116
+
117
+ Each capability's base CSS is exported (`codeDecoratorBaseCss`,
118
+ `alertsBaseCss`, `tableScrollerBaseCss`, `footnotesBaseCss`, `formulaBaseCss`,
119
+ `mermaidBaseCss`) if you want to read the baseline you are overriding.
120
+
121
+ ### Passing a theme without touching the global registry
122
+
123
+ `registerTheme(name, css)` mutates a process-global registry, so two consumers
124
+ in one process overwrite each other. Prefer passing the config inline:
125
+
126
+ ```typescript
127
+ import { renderMarkdownToWechat, ThemeConfig } from '@rbbtsn0w/wechat-markdown';
128
+
129
+ const brand: ThemeConfig = { name: 'brand', css: '.markdown-body { color: #222; }' };
130
+ const result = await renderMarkdownToWechat(markdown, { theme: brand });
131
+ ```
132
+
133
+ Unknown theme names fall back to `tech` rather than throwing.
134
+
135
+ ## 🔌 Injecting render services
136
+
137
+ The engine owns the *orchestration* of formulas and diagrams (finding them,
138
+ substituting an `<img>`, counting, emitting diagnostics). It does not need to
139
+ own the *asset lifecycle*. If your app renders, hashes, caches and uploads its
140
+ own images, inject a service instead of disabling the capability:
141
+
142
+ ```typescript
143
+ const result = await renderMarkdownToWechat(markdown, {
144
+ renderMath: true,
145
+ services: {
146
+ formulaRenderer: {
147
+ async renderToImage(expression, display) {
148
+ const png = await myRenderer.render(expression, display);
149
+ return await myCdn.upload(png); // returns a final URL
150
+ },
151
+ },
152
+ },
153
+ });
154
+ ```
155
+
156
+ The string a service returns is **substituted into `src` verbatim** — a local
157
+ path, a `data:` URI, and an already-uploaded CDN URL are all valid. Omit
158
+ `services` to use the built-in MathJax and Kroki renderers.
159
+
160
+ For plain (non-generated) images, use the `resolveImage` hook instead.
161
+
162
+ ## 🧪 Testing
163
+
164
+ ```bash
165
+ npm test
166
+ ```
167
+
168
+ ## 🛠️ Build
169
+
170
+ ```bash
171
+ npm run build
172
+ ```
173
+
174
+ ## 📄 License
175
+
176
+ ISC © [RbBtSn0w](https://github.com/RbBtSn0w)
@@ -0,0 +1,33 @@
1
+ import { RenderOptions, RenderResult } from './types';
2
+ export declare class WechatMarkdownEngine {
3
+ private formulaRenderer?;
4
+ private mermaidRenderer?;
5
+ /**
6
+ * Built-in renderers are constructed lazily: they create temp directories on
7
+ * construction, which is wasted work when the host injects its own services
8
+ * or disables the capability outright.
9
+ */
10
+ private getFormulaRenderer;
11
+ private getMermaidRenderer;
12
+ /**
13
+ * Parse Front-matter and extract YAML metadata if present
14
+ */
15
+ private extractFrontmatter;
16
+ /**
17
+ * Process and render LaTeX formulas in Markdown to images
18
+ */
19
+ private processFormulas;
20
+ /**
21
+ * Process Mermaid code blocks to images with degradation support
22
+ */
23
+ private processMermaid;
24
+ /**
25
+ * Main render method: converts Markdown string into WeChat-ready HTML
26
+ */
27
+ render(markdownInput: string, options?: RenderOptions): Promise<RenderResult>;
28
+ }
29
+ /**
30
+ * Functional entrypoint to render Markdown to WeChat-ready HTML
31
+ */
32
+ export declare function renderMarkdownToWechat(markdown: string, options?: RenderOptions): Promise<RenderResult>;
33
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,aAAa,EACb,YAAY,EAKb,MAAM,SAAS,CAAC;AA2BjB,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,eAAe,CAAC,CAAuB;IAC/C,OAAO,CAAC,eAAe,CAAC,CAAuB;IAE/C;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IAO1B,OAAO,CAAC,kBAAkB;IAO1B;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAoB1B;;OAEG;YACW,eAAe;IA6D7B;;OAEG;YACW,cAAc;IAkC5B;;OAEG;IACG,MAAM,CAAC,aAAa,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,YAAY,CAAC;CAqKxF;AAED;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,YAAY,CAAC,CAGvB"}
package/dist/engine.js ADDED
@@ -0,0 +1,289 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.WechatMarkdownEngine = void 0;
7
+ exports.renderMarkdownToWechat = renderMarkdownToWechat;
8
+ const marked_1 = require("marked");
9
+ const yaml_1 = __importDefault(require("yaml"));
10
+ const footnotes_1 = require("./plugins/footnotes");
11
+ const code_decorator_1 = require("./plugins/code-decorator");
12
+ const table_scroller_1 = require("./plugins/table-scroller");
13
+ const alerts_1 = require("./plugins/alerts");
14
+ const formula_1 = require("./media/formula");
15
+ const mermaid_1 = require("./media/mermaid");
16
+ const styles_1 = require("./media/styles");
17
+ const inliner_1 = require("./inliner/inliner");
18
+ /**
19
+ * Escapes HTML attribute metacharacters. Render services are host-injectable
20
+ * (FormulaRenderService/MermaidRenderService), so their output is untrusted
21
+ * before it's embedded into an `src="..."` attribute.
22
+ */
23
+ function escapeHtmlAttribute(value) {
24
+ return value
25
+ .replace(/&/g, '&amp;')
26
+ .replace(/"/g, '&quot;')
27
+ .replace(/</g, '&lt;')
28
+ .replace(/>/g, '&gt;');
29
+ }
30
+ class WechatMarkdownEngine {
31
+ formulaRenderer;
32
+ mermaidRenderer;
33
+ /**
34
+ * Built-in renderers are constructed lazily: they create temp directories on
35
+ * construction, which is wasted work when the host injects its own services
36
+ * or disables the capability outright.
37
+ */
38
+ getFormulaRenderer(injected) {
39
+ if (injected) {
40
+ return injected;
41
+ }
42
+ return (this.formulaRenderer ??= new formula_1.FormulaRenderer());
43
+ }
44
+ getMermaidRenderer(injected) {
45
+ if (injected) {
46
+ return injected;
47
+ }
48
+ return (this.mermaidRenderer ??= new mermaid_1.MermaidRenderer());
49
+ }
50
+ /**
51
+ * Parse Front-matter and extract YAML metadata if present
52
+ */
53
+ extractFrontmatter(content) {
54
+ const frontmatterRegex = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/;
55
+ const match = content.match(frontmatterRegex);
56
+ if (match) {
57
+ try {
58
+ const parsed = yaml_1.default.parse(match[1]) || {};
59
+ return {
60
+ metadata: parsed,
61
+ markdown: match[2],
62
+ };
63
+ }
64
+ catch {
65
+ // Return original if parsing fails
66
+ return { metadata: {}, markdown: content };
67
+ }
68
+ }
69
+ return { metadata: {}, markdown: content };
70
+ }
71
+ /**
72
+ * Process and render LaTeX formulas in Markdown to images
73
+ */
74
+ async processFormulas(markdown, diagnostics, renderer) {
75
+ let count = 0;
76
+ let processed = markdown;
77
+ // 1. Block formulas: $$...$$
78
+ const blockFormulaRegex = /\$\$([\s\S]+?)\$\$/g;
79
+ const blockMatches = [...processed.matchAll(blockFormulaRegex)];
80
+ for (const match of blockMatches) {
81
+ const fullMatch = match[0];
82
+ const expr = match[1].trim();
83
+ try {
84
+ const imagePath = await renderer.renderToImage(expr, true);
85
+ count++;
86
+ processed = processed.replace(fullMatch, `\n\n<p class="wm-figure"><img src="${escapeHtmlAttribute(imagePath)}" alt="formula" class="wm-formula-block" /></p>\n\n`);
87
+ }
88
+ catch (err) {
89
+ diagnostics.push({
90
+ code: 'FORMULA_RENDER_FAILED',
91
+ severity: 'warning',
92
+ message: `Failed to render block formula: ${err.message}`,
93
+ });
94
+ }
95
+ }
96
+ // 2. Inline formulas: $...$ (avoid escaping currency $10)
97
+ const inlineFormulaRegex = /(?<!\$)\$(?!\$)([^\n$]+?)(?<!\$)\$(?!\$)/g;
98
+ const inlineMatches = [...processed.matchAll(inlineFormulaRegex)];
99
+ for (const match of inlineMatches) {
100
+ const fullMatch = match[0];
101
+ const expr = match[1].trim();
102
+ // Skip simple price formats like $10 or $20.50
103
+ if (/^\d+(\.\d+)?$/.test(expr)) {
104
+ continue;
105
+ }
106
+ try {
107
+ const imagePath = await renderer.renderToImage(expr, false);
108
+ count++;
109
+ processed = processed.replace(fullMatch, `<img src="${escapeHtmlAttribute(imagePath)}" alt="formula" class="wm-formula-inline" />`);
110
+ }
111
+ catch (err) {
112
+ diagnostics.push({
113
+ code: 'FORMULA_RENDER_FAILED',
114
+ severity: 'warning',
115
+ message: `Failed to render inline formula: ${err.message}`,
116
+ });
117
+ }
118
+ }
119
+ return { markdown: processed, count };
120
+ }
121
+ /**
122
+ * Process Mermaid code blocks to images with degradation support
123
+ */
124
+ async processMermaid(markdown, diagnostics, renderer) {
125
+ let count = 0;
126
+ let processed = markdown;
127
+ const mermaidRegex = /```mermaid\r?\n([\s\S]*?)```/g;
128
+ const matches = [...processed.matchAll(mermaidRegex)];
129
+ for (const match of matches) {
130
+ const fullMatch = match[0];
131
+ const code = match[1];
132
+ try {
133
+ const imagePath = await renderer.renderToImage(code);
134
+ count++;
135
+ processed = processed.replace(fullMatch, `\n\n<p class="wm-figure"><img src="${escapeHtmlAttribute(imagePath)}" alt="mermaid-diagram" class="wm-mermaid" /></p>\n\n`);
136
+ }
137
+ catch (err) {
138
+ diagnostics.push({
139
+ code: 'MERMAID_RENDER_FAILED',
140
+ severity: 'warning',
141
+ message: `Failed to render Mermaid diagram, falling back to code block: ${err.message}`,
142
+ });
143
+ // Degrade to standard code block
144
+ processed = processed.replace(fullMatch, `\`\`\`text\n${code}\n\`\`\``);
145
+ }
146
+ }
147
+ return { markdown: processed, count };
148
+ }
149
+ /**
150
+ * Main render method: converts Markdown string into WeChat-ready HTML
151
+ */
152
+ async render(markdownInput, options = {}) {
153
+ const diagnostics = [];
154
+ const images = [];
155
+ const { theme = 'tech', customCss, siteUrl, footnoteLinks = true, macCodeBlock = true, tableScroller = true, gfmAlerts = true, renderMath = true, renderMermaid = true, resolveImage, services, } = options;
156
+ // Structural CSS for the markup each enabled capability emits. Layered
157
+ // under the theme so a theme that styles nothing still renders correctly,
158
+ // and a theme that styles everything keeps full control.
159
+ const baseCss = [];
160
+ // 1. Extract Frontmatter
161
+ const { metadata, markdown } = this.extractFrontmatter(markdownInput);
162
+ let workingMarkdown = markdown;
163
+ // 2. Extract and extract Title / Digest
164
+ let title = metadata.title || '';
165
+ if (!title) {
166
+ const titleMatch = workingMarkdown.match(/^#\s+(.+)$/m);
167
+ if (titleMatch) {
168
+ title = titleMatch[1].trim();
169
+ }
170
+ }
171
+ let digest = metadata.description || metadata.digest || '';
172
+ if (!digest) {
173
+ // Find first non-empty paragraph
174
+ const cleanPara = workingMarkdown
175
+ .replace(/^#+.*$/gm, '')
176
+ .replace(/!\[.*?\]\(.*?\)/g, '')
177
+ .replace(/\[.*?\]\(.*?\)/g, '$1')
178
+ .trim();
179
+ const firstPara = cleanPara.split('\n\n')[0] || '';
180
+ digest = firstPara.replace(/\s+/g, ' ').slice(0, 120);
181
+ }
182
+ // 3. Process Footnotes & External Links
183
+ let footnotes = [];
184
+ if (footnoteLinks) {
185
+ baseCss.push(footnotes_1.footnotesBaseCss);
186
+ const footnoteResult = (0, footnotes_1.processMarkdownFootnotes)(workingMarkdown, siteUrl);
187
+ workingMarkdown = footnoteResult.markdown;
188
+ footnotes = footnoteResult.footnotes;
189
+ }
190
+ // 4. Process LaTeX Math
191
+ let formulaCount = 0;
192
+ if (renderMath) {
193
+ baseCss.push(styles_1.formulaBaseCss);
194
+ const formulaResult = await this.processFormulas(workingMarkdown, diagnostics, this.getFormulaRenderer(services?.formulaRenderer));
195
+ workingMarkdown = formulaResult.markdown;
196
+ formulaCount = formulaResult.count;
197
+ }
198
+ // 5. Process Mermaid Diagrams
199
+ let mermaidCount = 0;
200
+ if (renderMermaid) {
201
+ baseCss.push(styles_1.mermaidBaseCss);
202
+ const mermaidResult = await this.processMermaid(workingMarkdown, diagnostics, this.getMermaidRenderer(services?.mermaidRenderer));
203
+ workingMarkdown = mermaidResult.markdown;
204
+ mermaidCount = mermaidResult.count;
205
+ }
206
+ // 6. Parse Markdown to HTML via marked
207
+ let rawHtml = await marked_1.marked.parse(workingMarkdown, {
208
+ gfm: true,
209
+ breaks: false,
210
+ });
211
+ // 7. Process GFM Alerts
212
+ if (gfmAlerts) {
213
+ baseCss.push(alerts_1.alertsBaseCss);
214
+ rawHtml = (0, alerts_1.processGfmAlerts)(rawHtml, true);
215
+ }
216
+ // 8. Decorate Code Blocks (Mac Style)
217
+ if (macCodeBlock) {
218
+ baseCss.push(code_decorator_1.codeDecoratorBaseCss);
219
+ rawHtml = (0, code_decorator_1.decorateCodeBlocks)(rawHtml, true);
220
+ }
221
+ // 9. Wrap Tables in Scroller
222
+ if (tableScroller) {
223
+ baseCss.push(table_scroller_1.tableScrollerBaseCss);
224
+ rawHtml = (0, table_scroller_1.wrapTablesWithScroller)(rawHtml, true);
225
+ }
226
+ // 10. Append Footnotes HTML
227
+ if (footnotes.length > 0) {
228
+ rawHtml += '\n' + (0, footnotes_1.renderFootnotesHtml)(footnotes);
229
+ }
230
+ // 11. Async Image Resolver Hook & Collect Images
231
+ const imgRegex = /<img\s+[^>]*src="([^"]+)"[^>]*>/g;
232
+ let match;
233
+ while ((match = imgRegex.exec(rawHtml)) !== null) {
234
+ images.push(match[1]);
235
+ }
236
+ if (resolveImage) {
237
+ const replacements = [];
238
+ for (const src of images) {
239
+ try {
240
+ const resolved = await resolveImage(src);
241
+ if (resolved && resolved !== src) {
242
+ replacements.push([src, resolved]);
243
+ }
244
+ }
245
+ catch (err) {
246
+ diagnostics.push({
247
+ code: 'IMAGE_RESOLVE_FAILED',
248
+ severity: 'warning',
249
+ message: `Failed to resolve image ${src}: ${err.message}`,
250
+ });
251
+ }
252
+ }
253
+ for (const [original, target] of replacements) {
254
+ rawHtml = rawHtml.split(original).join(target);
255
+ }
256
+ }
257
+ // 12. Inline CSS & WeChat DOM Patching
258
+ const finalHtml = (0, inliner_1.inlineWechatCss)(rawHtml, {
259
+ theme,
260
+ customCss,
261
+ siteUrl,
262
+ baseCss,
263
+ });
264
+ return {
265
+ html: finalHtml,
266
+ title,
267
+ digest,
268
+ metadata,
269
+ footnotes,
270
+ images,
271
+ diagnostics,
272
+ stats: {
273
+ images: images.length,
274
+ formulas: formulaCount,
275
+ mermaid: mermaidCount,
276
+ footnotes: footnotes.length,
277
+ },
278
+ };
279
+ }
280
+ }
281
+ exports.WechatMarkdownEngine = WechatMarkdownEngine;
282
+ /**
283
+ * Functional entrypoint to render Markdown to WeChat-ready HTML
284
+ */
285
+ async function renderMarkdownToWechat(markdown, options) {
286
+ const engine = new WechatMarkdownEngine();
287
+ return engine.render(markdown, options);
288
+ }
289
+ //# sourceMappingURL=engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":";;;;;;AAoWA,wDAMC;AA1WD,mCAAgC;AAChC,gDAAwB;AASxB,mDAI6B;AAC7B,6DAAoF;AACpF,6DAAwF;AACxF,6CAAmE;AACnE,6CAAkD;AAClD,6CAAkD;AAClD,2CAAgE;AAChE,+CAAoD;AAEpD;;;;GAIG;AACH,SAAS,mBAAmB,CAAC,KAAa;IACxC,OAAO,KAAK;SACT,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;SACtB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;SACvB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;SACrB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAC3B,CAAC;AAED,MAAa,oBAAoB;IACvB,eAAe,CAAwB;IACvC,eAAe,CAAwB;IAE/C;;;;OAIG;IACK,kBAAkB,CAAC,QAA+B;QACxD,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,eAAe,KAAK,IAAI,yBAAe,EAAE,CAAC,CAAC;IAC1D,CAAC;IAEO,kBAAkB,CAAC,QAA+B;QACxD,IAAI,QAAQ,EAAE,CAAC;YACb,OAAO,QAAQ,CAAC;QAClB,CAAC;QACD,OAAO,CAAC,IAAI,CAAC,eAAe,KAAK,IAAI,yBAAe,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED;;OAEG;IACK,kBAAkB,CAA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C,IAAI,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC;oBACrC,CAAC;gBACH,CAAC;gBAAC,OAAO,GAAQ,EAAE,CAAC;oBAClB,WAAW,CAAC,IAAI,CAAC;wBACf,IAAI,EAAE,sBAAsB;wBAC5B,QAAQ,EAAE,SAAS;wBACnB,OAAO,EAAE,2BAA2B,GAAG,KAAK,GAAG,CAAC,OAAO,EAAE;qBAC1D,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YAED,KAAK,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,YAAY,EAAE,CAAC;gBAC9C,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACjD,CAAC;QACH,CAAC;QAED,uCAAuC;QACvC,MAAM,SAAS,GAAG,IAAA,yBAAe,EAAC,OAAO,EAAE;YACzC,KAAK;YACL,SAAS;YACT,OAAO;YACP,OAAO;SACR,CAAC,CAAC;QAEH,OAAO;YACL,IAAI,EAAE,SAAS;YACf,KAAK;YACL,MAAM;YACN,QAAQ;YACR,SAAS;YACT,MAAM;YACN,WAAW;YACX,KAAK,EAAE;gBACL,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,QAAQ,EAAE,YAAY;gBACtB,OAAO,EAAE,YAAY;gBACrB,SAAS,EAAE,SAAS,CAAC,MAAM;aAC5B;SACF,CAAC;IACJ,CAAC;CACF;AA3TD,oDA2TC;AAED;;GAEG;AACI,KAAK,UAAU,sBAAsB,CAC1C,QAAgB,EAChB,OAAuB;IAEvB,MAAM,MAAM,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC1C,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AAC1C,CAAC"}
@@ -0,0 +1,13 @@
1
+ export * from './types';
2
+ export * from './engine';
3
+ export * from './themes';
4
+ export * from './plugins/footnotes';
5
+ export * from './plugins/code-decorator';
6
+ export * from './plugins/table-scroller';
7
+ export * from './plugins/alerts';
8
+ export * from './media/formula';
9
+ export * from './media/mermaid';
10
+ export * from './media/styles';
11
+ export * from './inliner/inliner';
12
+ export * from './inliner/dom-patcher';
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./types"), exports);
18
+ __exportStar(require("./engine"), exports);
19
+ __exportStar(require("./themes"), exports);
20
+ __exportStar(require("./plugins/footnotes"), exports);
21
+ __exportStar(require("./plugins/code-decorator"), exports);
22
+ __exportStar(require("./plugins/table-scroller"), exports);
23
+ __exportStar(require("./plugins/alerts"), exports);
24
+ __exportStar(require("./media/formula"), exports);
25
+ __exportStar(require("./media/mermaid"), exports);
26
+ __exportStar(require("./media/styles"), exports);
27
+ __exportStar(require("./inliner/inliner"), exports);
28
+ __exportStar(require("./inliner/dom-patcher"), exports);
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,2CAAyB;AACzB,2CAAyB;AACzB,sDAAoC;AACpC,2DAAyC;AACzC,2DAAyC;AACzC,mDAAiC;AACjC,kDAAgC;AAChC,kDAAgC;AAChC,iDAA+B;AAC/B,oDAAkC;AAClC,wDAAsC"}
@@ -0,0 +1,4 @@
1
+ export declare function sanitizeWechatHtml(html: string): string;
2
+ export declare function patchWechatListBullets(html: string): string;
3
+ export declare function cleanWechatAttributes(html: string): string;
4
+ //# sourceMappingURL=dom-patcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dom-patcher.d.ts","sourceRoot":"","sources":["../../src/inliner/dom-patcher.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAiBvD;AAED,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAU3D;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAM1D"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.sanitizeWechatHtml = sanitizeWechatHtml;
7
+ exports.patchWechatListBullets = patchWechatListBullets;
8
+ exports.cleanWechatAttributes = cleanWechatAttributes;
9
+ const sanitize_html_1 = __importDefault(require("sanitize-html"));
10
+ function sanitizeWechatHtml(html) {
11
+ return (0, sanitize_html_1.default)(html, {
12
+ allowedTags: [
13
+ 'p', 'br', 'strong', 'b', 'em', 'i', 'del', 's', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
14
+ 'blockquote', 'pre', 'code', 'ul', 'ol', 'li', 'table', 'thead', 'tbody', 'tr', 'th', 'td',
15
+ 'hr', 'img', 'a', 'span', 'div', 'section', 'sup', 'sub',
16
+ ],
17
+ allowedAttributes: {
18
+ '*': ['style', 'class', 'id', 'colspan', 'rowspan', 'align'],
19
+ a: ['href', 'title', 'target'],
20
+ img: ['src', 'alt', 'title', 'width', 'height', 'data-src'],
21
+ },
22
+ allowedSchemes: ['http', 'https', 'data', 'file'],
23
+ allowedSchemesByTag: {
24
+ img: ['http', 'https', 'data', 'file'],
25
+ },
26
+ });
27
+ }
28
+ function patchWechatListBullets(html) {
29
+ // Strip newlines and spaces around list items to prevent WeChat editor from inserting empty bullets
30
+ return html
31
+ .replace(/<ul([^>]*)>\s+/g, '<ul$1>')
32
+ .replace(/<ol([^>]*)>\s+/g, '<ol$1>')
33
+ .replace(/<\/li>\s+/g, '</li>')
34
+ .replace(/\s+<\/ul>/g, '</ul>')
35
+ .replace(/\s+<\/ol>/g, '</ol>')
36
+ .replace(/<li>\s+/g, '<li>')
37
+ .replace(/\s+<\/li>/g, '</li>');
38
+ }
39
+ function cleanWechatAttributes(html) {
40
+ return html
41
+ .replace(/\s+id="[^"]*"/g, '')
42
+ .replace(/\s+class="[^"]*"/g, '')
43
+ .replace(/\n\s*\n\s*\n/g, '\n\n')
44
+ .trim();
45
+ }
46
+ //# sourceMappingURL=dom-patcher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dom-patcher.js","sourceRoot":"","sources":["../../src/inliner/dom-patcher.ts"],"names":[],"mappings":";;;;;AAEA,gDAiBC;AAED,wDAUC;AAED,sDAMC;AAvCD,kEAAyC;AAEzC,SAAgB,kBAAkB,CAAC,IAAY;IAC7C,OAA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;SAC9B,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC;SAC3B,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;AACpC,CAAC;AAED,SAAgB,qBAAqB,CAAC,IAAY;IAChD,OAAO,IAAI;SACR,OAAO,CAAC,gBAAgB,EAAE,EAAE,CAAC;SAC7B,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC;SAChC,OAAO,CAAC,eAAe,EAAE,MAAM,CAAC;SAChC,IAAI,EAAE,CAAC;AACZ,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { ThemeConfig } from '../types';
2
+ export interface InlineOptions {
3
+ theme?: string | ThemeConfig;
4
+ customCss?: string;
5
+ siteUrl?: string;
6
+ /**
7
+ * Structural CSS contributed by the enabled capabilities. Concatenated
8
+ * ahead of the theme so the theme wins on any property it redeclares while
9
+ * base-only properties survive. Base CSS must not use !important.
10
+ */
11
+ baseCss?: string[];
12
+ }
13
+ export declare function inlineWechatCss(html: string, options?: InlineOptions): string;
14
+ //# sourceMappingURL=inliner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inliner.d.ts","sourceRoot":"","sources":["../../src/inliner/inliner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAEvC,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,MAAM,GAAG,WAAW,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CA8BjF"}