orz-markdown 1.2.2 → 1.3.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.
- package/README.md +30 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/plugins/chart.d.ts +2 -0
- package/dist/plugins/chart.d.ts.map +1 -0
- package/dist/plugins/chart.js +137 -0
- package/dist/plugins/chart.js.map +1 -0
- package/dist/preview-frame.d.ts +59 -0
- package/dist/preview-frame.d.ts.map +1 -0
- package/dist/preview-frame.js +88 -0
- package/dist/preview-frame.js.map +1 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +70 -6
- package/dist/runtime.js.map +1 -1
- package/orz-markdown-skills/SKILL.md +16 -9
- package/orz-markdown-skills/assets/template.html +23 -3
- package/orz-markdown-skills/references/css-classes.md +16 -9
- package/orz-markdown-skills/references/embedding.md +196 -0
- package/orz-markdown-skills/references/syntax.md +5 -3
- package/orz-markdown-skills/references/themes.md +4 -3
- package/package.json +4 -1
- package/themes/README.md +43 -0
- package/themes/beige-decent-1.css +27 -2
- package/themes/beige-decent-2.css +23 -3
- package/themes/dark-elegant-1.css +11 -0
- package/themes/dark-elegant-2.css +17 -9
- package/themes/dark-elegant-3.css +297 -0
- package/themes/light-academic-1.css +49 -1
- package/themes/light-academic-2.css +25 -1
- package/themes/light-neat-1.css +23 -9
- package/themes/light-neat-2.css +8 -5
- package/themes/light-neat-3.css +383 -0
package/README.md
CHANGED
|
@@ -55,7 +55,7 @@ Once the runtime is loaded, selecting rendered content and copying it (Cmd/Ctrl-
|
|
|
55
55
|
|
|
56
56
|
It only transforms selections inside an element with class `markdown-body` (wrap your rendered output in one, e.g. `<article class="markdown-body">…</article>`, or mark a container with `data-orz-copy`), and never touches selections inside `<input>`, `<textarea>`, or `contenteditable` regions.
|
|
57
57
|
|
|
58
|
-
Generated constructs that lose their source after client-side rendering — `mermaid`, `smiles`, `qrcode`, `youtube` — carry a `data-md` attribute that the walker emits verbatim. As a result a copied table of contents yields its heading links (not `{{toc 2,3}}`) and a copied QR code yields `{{qr ...}}` (not its SVG). **Do not strip `data-md` attributes** if you post-process the HTML.
|
|
58
|
+
Generated constructs that lose their source after client-side rendering — `mermaid`, `smiles`, `qrcode`, `youtube`, `chart` — carry a `data-md` attribute that the walker emits verbatim. As a result a copied table of contents yields its heading links (not `{{toc 2,3}}`) and a copied QR code yields `{{qr ...}}` (not its SVG). **Do not strip `data-md` attributes** if you post-process the HTML.
|
|
59
59
|
|
|
60
60
|
You can also convert a node programmatically:
|
|
61
61
|
|
|
@@ -87,6 +87,25 @@ The bundled themes cover the parser's custom output, including:
|
|
|
87
87
|
|
|
88
88
|
For a full list of provided themes and the underlying CSS class reference for theme authors, please read the [Themes Documentation](themes/README.md).
|
|
89
89
|
|
|
90
|
+
### Embedding with your own CSS
|
|
91
|
+
|
|
92
|
+
Building a host app that renders with `md.render()` but supplies its **own**
|
|
93
|
+
stylesheet and page shell — a slide engine, a document viewer, an editor? Read
|
|
94
|
+
the **[embedding guide](orz-markdown-skills/references/embedding.md)**. It gathers
|
|
95
|
+
the full integration contract in one checklist: the CSS classes you must style
|
|
96
|
+
(and the gotcha where a host CSS reset, e.g. reveal.js, strips `strong`/`em`/
|
|
97
|
+
`sub`/`sup`), the JavaScript you must wire (the browser runtime for tabs/QR/copy,
|
|
98
|
+
plus loading and drawing mermaid/smiles/Chart.js yourself), and exactly what
|
|
99
|
+
copy-as-Markdown needs (the runtime, `.markdown-body`, and preserved `data-md`
|
|
100
|
+
breadcrumbs and plugin classes).
|
|
101
|
+
|
|
102
|
+
If your host mounts the rendered output in an `<iframe>`, the
|
|
103
|
+
`orz-markdown/preview-frame` export gives you a one-call helper —
|
|
104
|
+
`getPreviewFrameAssets()` returns the pinned CDN URLs, the browser runtime,
|
|
105
|
+
`headLinks(scheme)` / `bodyScripts()` strings, and a `window.__orzEnhance()` that
|
|
106
|
+
highlights code and draws Mermaid / SMILES / charts — so every host wires the
|
|
107
|
+
preview identically instead of re-deriving it.
|
|
108
|
+
|
|
90
109
|
## Packaging
|
|
91
110
|
|
|
92
111
|
To rebuild distributable assets locally:
|
|
@@ -111,6 +130,14 @@ node_modules/orz-markdown/orz-markdown-skills/SKILL.md
|
|
|
111
130
|
|
|
112
131
|
with supporting files under `orz-markdown-skills/references/` and `orz-markdown-skills/assets/`. Point your agent tooling at that directory (e.g. copy or symlink it into your agent's skills folder).
|
|
113
132
|
|
|
133
|
+
Or hand your agent the skill straight from the CDN — no install needed:
|
|
134
|
+
|
|
135
|
+
```
|
|
136
|
+
https://cdn.jsdelivr.net/npm/orz-markdown/orz-markdown-skills/SKILL.md
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
See **[markdown.orz.how/agents.html](https://markdown.orz.how/agents.html)** for every install route (Claude Code, Claude.ai upload, or point-at-URL for any agent).
|
|
140
|
+
|
|
114
141
|
## Official Plugins Bundled
|
|
115
142
|
|
|
116
143
|
This project builds upon `markdown-it` and pre-configures a curated selection of official and popular community plugins.
|
|
@@ -140,12 +167,13 @@ We utilize a generalized and uniform `{{plugin_name ...}}` syntax for all custom
|
|
|
140
167
|
| **Attributes** | N/A | `# Header {{attrs[id="my-id"]}}`| Injects continuous HTML attributes (classes, IDs, config properties) to the immediately preceding element. |
|
|
141
168
|
| **Emoji** | `em` | `{{emoji smile}}` / `{{em tada}}` | Renders the specific text alias directly into the corresponding Unicode emoji natively. |
|
|
142
169
|
| **Table of Content** | N/A | `{{toc}}` or `{{toc 2,3}}` | Autogenerates a Table of Contents based on document headings. Allows specifying bound heading ranges. |
|
|
143
|
-
| **Space** | N/A | `{{space 4}}` | Inserts inline horizontal whitespace
|
|
170
|
+
| **Space** | N/A | `{{space 4}}` | Inserts inline horizontal whitespace — an empty `inline-block` span sized in `rem` (`{{space 4}}` → 4rem wide). |
|
|
144
171
|
| **YouTube** | `yt` | `{{youtube dQw4w9WgXcQ}}` | Embedded block element containing a responsive YouTube video iframe matching the ID. |
|
|
145
172
|
| **Markdown Source**| `md` | `{{md path/to/file.md}}` | Securely embeds the complete content of an external markdown file directly into the parsed structure. |
|
|
146
173
|
| **QR Code** | `qr` | `{{qr https://example.com}}` | Transforms text inline implicitly into an internally generated SVG QR Code natively. |
|
|
147
174
|
| **Mermaid** | `mm` | `{{mermaid\ngraph LR\nA-->B\n}}` | Compiles logic into a specific preconfigured payload targeted for Mermaid client-side rendering. |
|
|
148
175
|
| **SMILES Chemistry**| `sm` | `{{smiles C1=CC=CC=C1}}` | Embeds SMILES chemical formulas parsed specifically for `smilesDrawer` visualization. |
|
|
176
|
+
| **Chart** | N/A | `{{chart\ntype: bar\nlabels: A, B\ndata: 1, 2\n}}` | Declarative bar/line/pie/doughnut charts from a small line-based config (`type`, `labels`, `series: Name = …` or `data: …`, optional `title`). Rendered client-side with Chart.js. |
|
|
149
177
|
| **YAML Objects** | `yml` | `{{yaml\ntitle: Doc\n}}` | Embeds the multiline YAML configuration blindly into an invisible `<script type="application/yaml">` block. |
|
|
150
178
|
| **NYML Parser** | N/A | `{{nyml\nkey: value\n}}` | NYML-specific parser logic. Evaluates and injects the resulting properties as an invisible `<script type="application/json">` block. |
|
|
151
179
|
| **Test** | N/A | `{{test-block}}` | Reserved testing elements for structural plugin resolution constraints. |
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,UAAU,MAAM,aAAa,CAAC;AAkBrC,OAAO,mBAAmB,CAAC;AAC3B,OAAO,oBAAoB,CAAC;AAC5B,OAAO,oBAAoB,CAAC;AAC5B,OAAO,sBAAsB,CAAC;AAC9B,OAAO,sBAAsB,CAAC;AAC9B,OAAO,qBAAqB,CAAC;AAC7B,OAAO,qBAAqB,CAAC;AAC7B,OAAO,mBAAmB,CAAC;AAC3B,OAAO,mBAAmB,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,QAAA,MAAM,EAAE,YAMN,CAAC;AAsIH,eAAe,EAAE,CAAC;AAClB,OAAO,EAAE,EAAE,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAC9B,OAAO,UAAU,MAAM,aAAa,CAAC;AAkBrC,OAAO,mBAAmB,CAAC;AAC3B,OAAO,oBAAoB,CAAC;AAC5B,OAAO,oBAAoB,CAAC;AAC5B,OAAO,sBAAsB,CAAC;AAC9B,OAAO,sBAAsB,CAAC;AAC9B,OAAO,qBAAqB,CAAC;AAC7B,OAAO,oBAAoB,CAAC;AAC5B,OAAO,qBAAqB,CAAC;AAC7B,OAAO,mBAAmB,CAAC;AAC3B,OAAO,mBAAmB,CAAC;AAE3B,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,QAAA,MAAM,EAAE,YAMN,CAAC;AAsIH,eAAe,EAAE,CAAC;AAClB,OAAO,EAAE,EAAE,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -29,6 +29,7 @@ require("./plugins/space.js");
|
|
|
29
29
|
require("./plugins/youtube.js");
|
|
30
30
|
require("./plugins/mermaid.js");
|
|
31
31
|
require("./plugins/smiles.js");
|
|
32
|
+
require("./plugins/chart.js");
|
|
32
33
|
require("./plugins/qrcode.js");
|
|
33
34
|
require("./plugins/yaml.js");
|
|
34
35
|
require("./plugins/nyml.js");
|
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W,EACH,EAAE;IACV,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1B,MAAM,GAAG,GAAG,IAAA,2BAAa,EAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACtC,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,CAAC;IACpB,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,EAAE,IAAI,IAAI,IAAI,CAAC;IACtC,OAAO,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,IAAI,IAAI,EAAE,GAAG,CAAC,CAAC;AACtD,CAAC,CAAC;AAEF,kBAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart.d.ts","sourceRoot":"","sources":["../../src/plugins/chart.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const registry_js_1 = require("../registry.js");
|
|
4
|
+
/*
|
|
5
|
+
* {{chart …}} — declarative chart blocks.
|
|
6
|
+
*
|
|
7
|
+
* The plugin parses a tiny, line-based config into a Chart.js-style config
|
|
8
|
+
* object and emits a single <canvas class="orz-chart"> carrying that config as
|
|
9
|
+
* HTML-escaped JSON in `data-chart`. It does NOT draw anything: the host's
|
|
10
|
+
* client runtime is expected to read `data-chart` and call Chart.js, exactly
|
|
11
|
+
* like smiles canvases are painted by smiles-drawer. A `data-md` breadcrumb
|
|
12
|
+
* carries the original {{chart …}} source so copy-as-markdown can recover it.
|
|
13
|
+
*
|
|
14
|
+
* Syntax (one directive per line, `key: value`):
|
|
15
|
+
*
|
|
16
|
+
* type: bar # bar | line | pie | doughnut | ... (default: bar)
|
|
17
|
+
* title: My Chart # optional chart title
|
|
18
|
+
* labels: Q1, Q2, Q3 # comma-separated x-axis / slice labels
|
|
19
|
+
* series: Revenue = 10, 14, 9, 17 # a named dataset (repeatable)
|
|
20
|
+
* series: Cost = 6, 7, 8, 9
|
|
21
|
+
*
|
|
22
|
+
* Single-series shorthand (no name needed):
|
|
23
|
+
*
|
|
24
|
+
* type: pie
|
|
25
|
+
* labels: A, B, C
|
|
26
|
+
* data: 30, 50, 20
|
|
27
|
+
*
|
|
28
|
+
* Unknown keys are ignored. Numbers parse with parseFloat; non-numeric values
|
|
29
|
+
* become null (a gap). On any parse failure the plugin degrades gracefully and
|
|
30
|
+
* emits an empty canvas carrying an `data-chart-error` attribute rather than
|
|
31
|
+
* throwing.
|
|
32
|
+
*/
|
|
33
|
+
// Encode a value for a double-quoted HTML attribute, preserving newlines (as
|
|
34
|
+
// ) so multi-line source survives in `data-md`.
|
|
35
|
+
function escapeAttr(str) {
|
|
36
|
+
return str
|
|
37
|
+
.replace(/&/g, '&')
|
|
38
|
+
.replace(/"/g, '"')
|
|
39
|
+
.replace(/</g, '<')
|
|
40
|
+
.replace(/>/g, '>')
|
|
41
|
+
.replace(/\n/g, ' ');
|
|
42
|
+
}
|
|
43
|
+
function parseNumberList(value) {
|
|
44
|
+
return value
|
|
45
|
+
.split(',')
|
|
46
|
+
.map((part) => part.trim())
|
|
47
|
+
.filter((part) => part.length > 0)
|
|
48
|
+
.map((part) => {
|
|
49
|
+
const n = Number.parseFloat(part);
|
|
50
|
+
return Number.isNaN(n) ? null : n;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function parseList(value) {
|
|
54
|
+
return value
|
|
55
|
+
.split(',')
|
|
56
|
+
.map((part) => part.trim())
|
|
57
|
+
.filter((part) => part.length > 0);
|
|
58
|
+
}
|
|
59
|
+
function parseChart(body) {
|
|
60
|
+
let type = 'bar';
|
|
61
|
+
let title = '';
|
|
62
|
+
let labels = [];
|
|
63
|
+
const datasets = [];
|
|
64
|
+
for (const rawLine of body.split('\n')) {
|
|
65
|
+
const line = rawLine.trim();
|
|
66
|
+
if (!line)
|
|
67
|
+
continue;
|
|
68
|
+
const colon = line.indexOf(':');
|
|
69
|
+
if (colon === -1)
|
|
70
|
+
continue;
|
|
71
|
+
const key = line.slice(0, colon).trim().toLowerCase();
|
|
72
|
+
const value = line.slice(colon + 1).trim();
|
|
73
|
+
switch (key) {
|
|
74
|
+
case 'type':
|
|
75
|
+
if (value)
|
|
76
|
+
type = value.toLowerCase();
|
|
77
|
+
break;
|
|
78
|
+
case 'title':
|
|
79
|
+
title = value;
|
|
80
|
+
break;
|
|
81
|
+
case 'labels':
|
|
82
|
+
labels = parseList(value);
|
|
83
|
+
break;
|
|
84
|
+
case 'data':
|
|
85
|
+
// single-series shorthand
|
|
86
|
+
datasets.push({ data: parseNumberList(value) });
|
|
87
|
+
break;
|
|
88
|
+
case 'series': {
|
|
89
|
+
const eq = value.indexOf('=');
|
|
90
|
+
if (eq === -1) {
|
|
91
|
+
datasets.push({ data: parseNumberList(value) });
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
const name = value.slice(0, eq).trim();
|
|
95
|
+
const nums = parseNumberList(value.slice(eq + 1));
|
|
96
|
+
datasets.push({ label: name || undefined, data: nums });
|
|
97
|
+
}
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
default:
|
|
101
|
+
// ignore unknown keys
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const config = {
|
|
106
|
+
type,
|
|
107
|
+
data: { labels, datasets },
|
|
108
|
+
};
|
|
109
|
+
if (title) {
|
|
110
|
+
config.options = {
|
|
111
|
+
plugins: { title: { display: true, text: title } },
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
return config;
|
|
115
|
+
}
|
|
116
|
+
(0, registry_js_1.register)({
|
|
117
|
+
type: 'block',
|
|
118
|
+
aliases: ['chart'],
|
|
119
|
+
render(_args, body, _env) {
|
|
120
|
+
const source = body?.trim() ?? '';
|
|
121
|
+
// `data-md` lets copy-as-markdown recover the source after the client
|
|
122
|
+
// runtime paints the <canvas> (which has no recoverable text content).
|
|
123
|
+
const directive = `{{chart\n${source}\n}}`;
|
|
124
|
+
const md = escapeAttr(directive);
|
|
125
|
+
let config;
|
|
126
|
+
try {
|
|
127
|
+
config = parseChart(source);
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
// Degrade gracefully: emit an empty, erroring canvas rather than throwing.
|
|
131
|
+
return `<canvas class="orz-chart" data-chart-error="parse error" data-md="${md}" width="600" height="400"></canvas>\n`;
|
|
132
|
+
}
|
|
133
|
+
const json = escapeAttr(JSON.stringify(config));
|
|
134
|
+
return `<canvas class="orz-chart" data-chart="${json}" data-md="${md}" width="600" height="400"></canvas>\n`;
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
//# sourceMappingURL=chart.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chart.js","sourceRoot":"","sources":["../../src/plugins/chart.ts"],"names":[],"mappings":";;AAAA,gDAA0C;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,6EAA6E;AAC7E,qDAAqD;AACrD,SAAS,UAAU,CAAC,GAAW;IAC7B,OAAO,GAAG;SACP,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;SACrB,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AAC7B,CAAC;AAWD,SAAS,eAAe,CAAC,KAAa;IACpC,OAAO,KAAK;SACT,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;SAC1B,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;SACjC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACZ,MAAM,CAAC,GAAG,MAAM,CAAC,UAAU,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AAC;AAChB,CAAC;AAED,IAAA,sBAAQ,EAAC;IACP,IAAI,EAAE,OAAO;IACb,OAAO,EAAE,CAAC,OAAO,CAAC;IAClB,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,IAAI;QACtB,MAAM,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QAClC,sEAAsE;QACtE,uEAAuE;QACvE,MAAM,SAAS,GAAG,YAAY,MAAM,MAAM,CAAC;QAC3C,MAAM,EAAE,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;QAEjC,IAAI,MAAmB,CAAC;QACxB,IAAI,CAAC;YACH,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;QAC9B,CAAC;QAAC,MAAM,CAAC;YACP,2EAA2E;YAC3E,OAAO,qEAAqE,EAAE,wCAAwC,CAAC;QACzH,CAAC;QAED,MAAM,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;QAChD,OAAO,yCAAyC,IAAI,cAAc,EAAE,wCAAwC,CAAC;IAC/G,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preview-frame assets — one place that wires the orz-markdown preview the way
|
|
3
|
+
* `references/embedding.md` prescribes, so every host app (mdhtml, slides, paged,
|
|
4
|
+
* the editor) loads identical, tested CDN versions and runs the same
|
|
5
|
+
* highlight / mermaid / SMILES / chart / runtime steps instead of each
|
|
6
|
+
* re-deriving them (and drifting).
|
|
7
|
+
*
|
|
8
|
+
* Usage in a host that mounts rendered HTML in an <iframe>:
|
|
9
|
+
*
|
|
10
|
+
* import { getPreviewFrameAssets } from 'orz-markdown/preview-frame';
|
|
11
|
+
* const pa = getPreviewFrameAssets();
|
|
12
|
+
* const html =
|
|
13
|
+
* '<!doctype html><html><head><meta charset=utf8>' +
|
|
14
|
+
* '<link rel=stylesheet href="' + myThemeHref + '">' +
|
|
15
|
+
* pa.headLinks(scheme) + // KaTeX + highlight.js CSS
|
|
16
|
+
* '</head><body><article class="markdown-body" id="doc"></article>' +
|
|
17
|
+
* pa.bodyScripts() + // libs + runtime + __orzEnhance
|
|
18
|
+
* '</body></html>';
|
|
19
|
+
* // mount html in the iframe, then on every render:
|
|
20
|
+
* iframeWindow.__orzSmilesTheme = scheme; // 'dark' on dark themes
|
|
21
|
+
* doc.querySelector('.markdown-body').innerHTML = md.render(src);
|
|
22
|
+
* iframeWindow.__orzEnhance();
|
|
23
|
+
* // on theme change, swap the highlight.js stylesheet:
|
|
24
|
+
* doc.getElementById('orz-hljs').href = pa.hljsCss(scheme);
|
|
25
|
+
*/
|
|
26
|
+
export type ColorScheme = 'light' | 'dark';
|
|
27
|
+
/** Pinned CDN URLs for the preview-iframe assets (one source of truth). */
|
|
28
|
+
export declare const PREVIEW_CDN: {
|
|
29
|
+
readonly katexCss: "https://cdn.jsdelivr.net/npm/katex@0.16.35/dist/katex.min.css";
|
|
30
|
+
readonly hljsJs: "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js";
|
|
31
|
+
readonly hljsLightCss: "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.min.css";
|
|
32
|
+
readonly hljsDarkCss: "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/atom-one-dark.min.css";
|
|
33
|
+
readonly mermaidJs: "https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.min.js";
|
|
34
|
+
readonly smilesJs: "https://unpkg.com/smiles-drawer@1.0.10/dist/smiles-drawer.min.js";
|
|
35
|
+
readonly chartJs: "https://cdn.jsdelivr.net/npm/chart.js@4/dist/chart.umd.min.js";
|
|
36
|
+
};
|
|
37
|
+
export interface PreviewFrameAssets {
|
|
38
|
+
/** Pinned CDN URLs. */
|
|
39
|
+
cdn: typeof PREVIEW_CDN;
|
|
40
|
+
/** The orz browser runtime source (copy-as-Markdown + tabs + QR expand). */
|
|
41
|
+
runtimeScript: string;
|
|
42
|
+
/** highlight.js stylesheet URL for a scheme (swap `#orz-hljs`.href on theme change). */
|
|
43
|
+
hljsCss(scheme?: ColorScheme): string;
|
|
44
|
+
/** `<link>` tags for the iframe `<head>`: KaTeX + highlight.js CSS for the scheme.
|
|
45
|
+
* The highlight.js link carries `id="orz-hljs"` for swapping. */
|
|
46
|
+
headLinks(scheme?: ColorScheme): string;
|
|
47
|
+
/** `<script>` tags for the iframe `<body>`: load the libs + the runtime and
|
|
48
|
+
* define `window.__orzEnhance()`. Call `__orzEnhance()` after each render
|
|
49
|
+
* (set `window.__orzSmilesTheme='dark'` first on dark themes). */
|
|
50
|
+
bodyScripts(): string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Everything a host app needs to wire the orz-markdown preview iframe the way the
|
|
54
|
+
* bundled themes and tested apps do: the copy-as-Markdown runtime, code
|
|
55
|
+
* highlighting, mermaid / SMILES / chart drawing, tabs, and QR expand.
|
|
56
|
+
* See `references/embedding.md`.
|
|
57
|
+
*/
|
|
58
|
+
export declare function getPreviewFrameAssets(): PreviewFrameAssets;
|
|
59
|
+
//# sourceMappingURL=preview-frame.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview-frame.d.ts","sourceRoot":"","sources":["../src/preview-frame.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAIH,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,MAAM,CAAC;AAE3C,2EAA2E;AAC3E,eAAO,MAAM,WAAW;;;;;;;;CAQd,CAAC;AAoBX,MAAM,WAAW,kBAAkB;IACjC,uBAAuB;IACvB,GAAG,EAAE,OAAO,WAAW,CAAC;IACxB,4EAA4E;IAC5E,aAAa,EAAE,MAAM,CAAC;IACtB,wFAAwF;IACxF,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC;IACtC;sEACkE;IAClE,SAAS,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,MAAM,CAAC;IACxC;;uEAEmE;IACnE,WAAW,IAAI,MAAM,CAAC;CACvB;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,IAAI,kBAAkB,CA6B1D"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Preview-frame assets — one place that wires the orz-markdown preview the way
|
|
4
|
+
* `references/embedding.md` prescribes, so every host app (mdhtml, slides, paged,
|
|
5
|
+
* the editor) loads identical, tested CDN versions and runs the same
|
|
6
|
+
* highlight / mermaid / SMILES / chart / runtime steps instead of each
|
|
7
|
+
* re-deriving them (and drifting).
|
|
8
|
+
*
|
|
9
|
+
* Usage in a host that mounts rendered HTML in an <iframe>:
|
|
10
|
+
*
|
|
11
|
+
* import { getPreviewFrameAssets } from 'orz-markdown/preview-frame';
|
|
12
|
+
* const pa = getPreviewFrameAssets();
|
|
13
|
+
* const html =
|
|
14
|
+
* '<!doctype html><html><head><meta charset=utf8>' +
|
|
15
|
+
* '<link rel=stylesheet href="' + myThemeHref + '">' +
|
|
16
|
+
* pa.headLinks(scheme) + // KaTeX + highlight.js CSS
|
|
17
|
+
* '</head><body><article class="markdown-body" id="doc"></article>' +
|
|
18
|
+
* pa.bodyScripts() + // libs + runtime + __orzEnhance
|
|
19
|
+
* '</body></html>';
|
|
20
|
+
* // mount html in the iframe, then on every render:
|
|
21
|
+
* iframeWindow.__orzSmilesTheme = scheme; // 'dark' on dark themes
|
|
22
|
+
* doc.querySelector('.markdown-body').innerHTML = md.render(src);
|
|
23
|
+
* iframeWindow.__orzEnhance();
|
|
24
|
+
* // on theme change, swap the highlight.js stylesheet:
|
|
25
|
+
* doc.getElementById('orz-hljs').href = pa.hljsCss(scheme);
|
|
26
|
+
*/
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.PREVIEW_CDN = void 0;
|
|
29
|
+
exports.getPreviewFrameAssets = getPreviewFrameAssets;
|
|
30
|
+
const runtime_js_1 = require("./runtime.js");
|
|
31
|
+
/** Pinned CDN URLs for the preview-iframe assets (one source of truth). */
|
|
32
|
+
exports.PREVIEW_CDN = {
|
|
33
|
+
katexCss: 'https://cdn.jsdelivr.net/npm/katex@0.16.35/dist/katex.min.css',
|
|
34
|
+
hljsJs: 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js',
|
|
35
|
+
hljsLightCss: 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.min.css',
|
|
36
|
+
hljsDarkCss: 'https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/atom-one-dark.min.css',
|
|
37
|
+
mermaidJs: 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.min.js',
|
|
38
|
+
smilesJs: 'https://unpkg.com/smiles-drawer@1.0.10/dist/smiles-drawer.min.js',
|
|
39
|
+
chartJs: 'https://cdn.jsdelivr.net/npm/chart.js@4/dist/chart.umd.min.js',
|
|
40
|
+
};
|
|
41
|
+
/** Guard inline <script> content against premature `</script>` termination. */
|
|
42
|
+
function guard(js) {
|
|
43
|
+
return js.replace(/<\/(script)/gi, '<\\/$1');
|
|
44
|
+
}
|
|
45
|
+
/* Body of window.__orzEnhance(). Scoped to .markdown-body so it works whatever
|
|
46
|
+
* id/wrapper the host gives the rendered region. Idempotent: highlight/tabs/QR
|
|
47
|
+
* skip already-processed nodes, SMILES/chart track a JS flag. SMILES honors
|
|
48
|
+
* window.__orzSmilesTheme ('dark' → light bonds); reset its flag and re-run to
|
|
49
|
+
* redraw after a theme switch. */
|
|
50
|
+
const ENHANCE_BODY = "var R='.markdown-body ';" +
|
|
51
|
+
"try{if(window.hljs)document.querySelectorAll(R+'pre code:not(.hljs)').forEach(function(b){window.hljs.highlightElement(b)})}catch(e){}" +
|
|
52
|
+
"try{if(window.mermaid)window.mermaid.run({nodes:document.querySelectorAll(R+'.mermaid:not([data-processed])')})}catch(e){}" +
|
|
53
|
+
"try{if(window.SmilesDrawer)document.querySelectorAll(R+'canvas[data-smiles]').forEach(function(v){if(v.__d)return;v.__d=1;if(v.__ow===undefined){v.__ow=v.width;v.__oh=v.height}v.width=v.__ow;v.height=v.__oh;var d=new window.SmilesDrawer.Drawer({width:v.__ow,height:v.__oh});window.SmilesDrawer.parse(v.getAttribute('data-smiles'),function(t){try{d.draw(t,v,window.__orzSmilesTheme||'light',false)}catch(e){}})})}catch(e){}" +
|
|
54
|
+
"try{if(window.Chart)document.querySelectorAll(R+'canvas.orz-chart[data-chart]').forEach(function(v){if(v.__d)return;v.__d=1;var w=v.ownerDocument.createElement('div');w.style.cssText='position:relative;width:100%;max-width:440px;margin:.4em auto';v.parentNode.insertBefore(w,v);w.appendChild(v);v.removeAttribute('width');v.removeAttribute('height');try{var g=JSON.parse(v.getAttribute('data-chart')||'{}');g.options=Object.assign({responsive:true,maintainAspectRatio:true,animation:false},g.options||{});new window.Chart(v,g)}catch(e){}})}catch(e){}" +
|
|
55
|
+
"try{if(window.OrzMarkdownRuntime)window.OrzMarkdownRuntime.init(document)}catch(e){}";
|
|
56
|
+
/**
|
|
57
|
+
* Everything a host app needs to wire the orz-markdown preview iframe the way the
|
|
58
|
+
* bundled themes and tested apps do: the copy-as-Markdown runtime, code
|
|
59
|
+
* highlighting, mermaid / SMILES / chart drawing, tabs, and QR expand.
|
|
60
|
+
* See `references/embedding.md`.
|
|
61
|
+
*/
|
|
62
|
+
function getPreviewFrameAssets() {
|
|
63
|
+
const cdn = exports.PREVIEW_CDN;
|
|
64
|
+
const runtimeScript = (0, runtime_js_1.getBrowserRuntimeScript)();
|
|
65
|
+
return {
|
|
66
|
+
cdn,
|
|
67
|
+
runtimeScript,
|
|
68
|
+
hljsCss(scheme = 'light') {
|
|
69
|
+
return scheme === 'dark' ? cdn.hljsDarkCss : cdn.hljsLightCss;
|
|
70
|
+
},
|
|
71
|
+
headLinks(scheme = 'light') {
|
|
72
|
+
return ('<link rel="stylesheet" href="' + cdn.katexCss + '">' +
|
|
73
|
+
'<link id="orz-hljs" rel="stylesheet" href="' +
|
|
74
|
+
(scheme === 'dark' ? cdn.hljsDarkCss : cdn.hljsLightCss) +
|
|
75
|
+
'">');
|
|
76
|
+
},
|
|
77
|
+
bodyScripts() {
|
|
78
|
+
return ('<script src="' + cdn.hljsJs + '"></script>' +
|
|
79
|
+
'<script src="' + cdn.mermaidJs + '"></script>' +
|
|
80
|
+
'<script src="' + cdn.smilesJs + '"></script>' +
|
|
81
|
+
'<script src="' + cdn.chartJs + '"></script>' +
|
|
82
|
+
'<script>try{mermaid.initialize({startOnLoad:false})}catch(e){}</script>' +
|
|
83
|
+
'<script>' + guard(runtimeScript) + '</script>' +
|
|
84
|
+
'<script>window.__orzEnhance=function(){' + ENHANCE_BODY + '\n};</script>');
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=preview-frame.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preview-frame.js","sourceRoot":"","sources":["../src/preview-frame.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;;AAyDH,sDA6BC;AApFD,6CAAuD;AAIvD,2EAA2E;AAC9D,QAAA,WAAW,GAAG;IACzB,QAAQ,EAAE,+DAA+D;IACzE,MAAM,EAAE,6EAA6E;IACrF,YAAY,EAAE,kFAAkF;IAChG,WAAW,EAAE,yFAAyF;IACtG,SAAS,EAAE,6DAA6D;IACxE,QAAQ,EAAE,kEAAkE;IAC5E,OAAO,EAAE,+DAA+D;CAChE,CAAC;AAEX,+EAA+E;AAC/E,SAAS,KAAK,CAAC,EAAU;IACvB,OAAO,EAAE,CAAC,OAAO,CAAC,eAAe,EAAE,QAAQ,CAAC,CAAC;AAC/C,CAAC;AAED;;;;kCAIkC;AAClC,MAAM,YAAY,GAChB,0BAA0B;IAC1B,wIAAwI;IACxI,4HAA4H;IAC5H,waAAwa;IACxa,wiBAAwiB;IACxiB,sFAAsF,CAAC;AAkBzF;;;;;GAKG;AACH,SAAgB,qBAAqB;IACnC,MAAM,GAAG,GAAG,mBAAW,CAAC;IACxB,MAAM,aAAa,GAAG,IAAA,oCAAuB,GAAE,CAAC;IAChD,OAAO;QACL,GAAG;QACH,aAAa;QACb,OAAO,CAAC,SAAsB,OAAO;YACnC,OAAO,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC;QAChE,CAAC;QACD,SAAS,CAAC,SAAsB,OAAO;YACrC,OAAO,CACL,+BAA+B,GAAG,GAAG,CAAC,QAAQ,GAAG,IAAI;gBACrD,6CAA6C;gBAC7C,CAAC,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,YAAY,CAAC;gBACxD,IAAI,CACL,CAAC;QACJ,CAAC;QACD,WAAW;YACT,OAAO,CACL,eAAe,GAAG,GAAG,CAAC,MAAM,GAAG,aAAa;gBAC5C,eAAe,GAAG,GAAG,CAAC,SAAS,GAAG,aAAa;gBAC/C,eAAe,GAAG,GAAG,CAAC,QAAQ,GAAG,aAAa;gBAC9C,eAAe,GAAG,GAAG,CAAC,OAAO,GAAG,aAAa;gBAC7C,yEAAyE;gBACzE,UAAU,GAAG,KAAK,CAAC,aAAa,CAAC,GAAG,WAAW;gBAC/C,yCAAyC,GAAG,YAAY,GAAG,eAAe,CAC3E,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/runtime.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,QA+
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,oBAAoB,QA+iBhC,CAAC;AAEF,wBAAgB,uBAAuB,IAAI,MAAM,CAEhD"}
|
package/dist/runtime.js
CHANGED
|
@@ -121,7 +121,7 @@ exports.browserRuntimeScript = String.raw `
|
|
|
121
121
|
// ---- copy-as-markdown: DOM -> Markdown walker ---------------------------
|
|
122
122
|
// Converts a selected DOM fragment back to Markdown so that copying rendered
|
|
123
123
|
// content yields source, not HTML. Standard constructs are reconstructed from
|
|
124
|
-
// their tags; generated constructs (math, mermaid, smiles, qr, youtube) carry
|
|
124
|
+
// their tags; generated constructs (math, mermaid, smiles, qr, youtube, chart) carry
|
|
125
125
|
// a [data-md] breadcrumb that is emitted verbatim. Written without template
|
|
126
126
|
// literals/backticks because this whole file is a String.raw template.
|
|
127
127
|
var BT = String.fromCharCode(96);
|
|
@@ -191,6 +191,9 @@ exports.browserRuntimeScript = String.raw `
|
|
|
191
191
|
case 'br': return ' \n';
|
|
192
192
|
case 'img': return rt_img(node);
|
|
193
193
|
case 'input': return '';
|
|
194
|
+
case 'span':
|
|
195
|
+
var spCls = (rt_attr(node, 'class') || '').trim();
|
|
196
|
+
return spCls ? '{{sp[' + spCls + '] ' + rt_inlineChildren(node) + '}}' : rt_inlineChildren(node);
|
|
194
197
|
default: return rt_inlineChildren(node);
|
|
195
198
|
}
|
|
196
199
|
}
|
|
@@ -346,6 +349,53 @@ exports.browserRuntimeScript = String.raw `
|
|
|
346
349
|
return parts.join('\n\n');
|
|
347
350
|
}
|
|
348
351
|
|
|
352
|
+
var rt_containerNames = ['info', 'success', 'warning', 'danger', 'left', 'right', 'center', 'cols', 'col', 'tabs', 'tab'];
|
|
353
|
+
// A markdown-it-container div.name (or details.spoil) -> its ::: name
|
|
354
|
+
// directive name, or null if the node is not a container.
|
|
355
|
+
function rt_containerName(node) {
|
|
356
|
+
if (node.nodeType !== 1 || !node.classList) return null;
|
|
357
|
+
var tag = node.tagName.toLowerCase();
|
|
358
|
+
if (tag === 'details' && node.classList.contains('spoil')) {
|
|
359
|
+
var sum = node.querySelector ? node.querySelector('summary') : null;
|
|
360
|
+
var title = sum ? (sum.textContent || '').trim() : '';
|
|
361
|
+
return title ? 'spoil ' + title : 'spoil';
|
|
362
|
+
}
|
|
363
|
+
if (tag !== 'div') return null;
|
|
364
|
+
for (var i = 0; i < rt_containerNames.length; i++) {
|
|
365
|
+
var n = rt_containerNames[i];
|
|
366
|
+
if (node.classList.contains(n)) {
|
|
367
|
+
if (n === 'tab') { var lbl = rt_attr(node, 'data-label'); return lbl ? 'tab ' + lbl : 'tab'; }
|
|
368
|
+
return n;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
// Emit a ::: name ... ::: block, using a fence longer than any inner fence so
|
|
374
|
+
// nested containers (cols > col, tabs > tab) re-parse correctly.
|
|
375
|
+
function rt_containerMd(node, name) {
|
|
376
|
+
var parts = [];
|
|
377
|
+
var kids = node.childNodes;
|
|
378
|
+
for (var i = 0; i < kids.length; i++) {
|
|
379
|
+
var k = kids[i];
|
|
380
|
+
if (k.nodeType === 1) {
|
|
381
|
+
var ktag = k.tagName.toLowerCase();
|
|
382
|
+
if (ktag === 'summary') continue; // spoil title, captured in the name
|
|
383
|
+
if (k.classList && k.classList.contains('tabs-bar')) continue; // JS-injected tab buttons
|
|
384
|
+
}
|
|
385
|
+
var m = rt_blockNode(k);
|
|
386
|
+
if (m && m.trim()) parts.push(m.trim());
|
|
387
|
+
}
|
|
388
|
+
var inner = parts.join('\n\n');
|
|
389
|
+
var maxFence = 2;
|
|
390
|
+
var lines = inner.split('\n');
|
|
391
|
+
for (var j = 0; j < lines.length; j++) {
|
|
392
|
+
var mm = lines[j].match(/^(:{3,})/);
|
|
393
|
+
if (mm && mm[1].length > maxFence) maxFence = mm[1].length;
|
|
394
|
+
}
|
|
395
|
+
var fence = rt_repeat(':', Math.max(3, maxFence + 1));
|
|
396
|
+
return fence + ' ' + name + '\n' + inner + '\n' + fence;
|
|
397
|
+
}
|
|
398
|
+
|
|
349
399
|
function rt_blockNode(node) {
|
|
350
400
|
if (node.nodeType === 3) {
|
|
351
401
|
var t = node.nodeValue;
|
|
@@ -355,7 +405,10 @@ exports.browserRuntimeScript = String.raw `
|
|
|
355
405
|
var dm = rt_attr(node, 'data-md');
|
|
356
406
|
if (dm != null) return dm;
|
|
357
407
|
if (node.classList) {
|
|
358
|
-
|
|
408
|
+
// Display math: the katex-display span OR its katex-block <p> wrapper.
|
|
409
|
+
// Without this the wrapper is walked as a paragraph and the inner katex is
|
|
410
|
+
// emitted as inline math instead of a block equation.
|
|
411
|
+
if (node.classList.contains('katex-display') || node.classList.contains('katex-block')) {
|
|
359
412
|
var k = node.querySelector ? node.querySelector('.katex') : null;
|
|
360
413
|
return rt_katex(k || node, true);
|
|
361
414
|
}
|
|
@@ -374,6 +427,8 @@ exports.browserRuntimeScript = String.raw `
|
|
|
374
427
|
case 'hr': return '---';
|
|
375
428
|
case 'li': return rt_inlineChildren(node).trim();
|
|
376
429
|
case 'figure': case 'div': case 'section': case 'article': case 'details': case 'summary':
|
|
430
|
+
var cn = rt_containerName(node);
|
|
431
|
+
if (cn) return rt_containerMd(node, cn);
|
|
377
432
|
return rt_blockChildren(node);
|
|
378
433
|
default: return rt_inlineNode(node).trim();
|
|
379
434
|
}
|
|
@@ -414,18 +469,27 @@ exports.browserRuntimeScript = String.raw `
|
|
|
414
469
|
return false;
|
|
415
470
|
}
|
|
416
471
|
|
|
417
|
-
// When a selection sits entirely within one table/blockquote/pre
|
|
418
|
-
// whole block
|
|
419
|
-
//
|
|
472
|
+
// When a selection sits entirely within one table/blockquote/pre — or inside a
|
|
473
|
+
// ::: container — copy that whole block, so the wrapper is included (a partial
|
|
474
|
+
// table/quote fragment isn't valid Markdown, and a copied container should keep
|
|
475
|
+
// its ::: fence). Browsers often clone such selections without the wrapper.
|
|
476
|
+
// Tables/quotes/code don't nest, so the innermost wins; containers DO nest
|
|
477
|
+
// (cols > col, tabs > tab), so promote to the OUTERMOST one.
|
|
420
478
|
function rt_promotableBlock(node) {
|
|
479
|
+
var container = null;
|
|
421
480
|
while (node && !rt_isCopyRoot(node)) {
|
|
422
481
|
if (node.nodeType === 1) {
|
|
423
482
|
var tag = node.tagName.toLowerCase();
|
|
424
483
|
if (tag === 'table' || tag === 'blockquote' || tag === 'pre') return node;
|
|
484
|
+
// A selection inside a display equation copies the whole block equation;
|
|
485
|
+
// a partial KaTeX fragment is not valid Markdown.
|
|
486
|
+
if (node.classList &&
|
|
487
|
+
(node.classList.contains('katex-block') || node.classList.contains('katex-display'))) return node;
|
|
488
|
+
if (rt_containerName(node)) container = node;
|
|
425
489
|
}
|
|
426
490
|
node = node.parentNode;
|
|
427
491
|
}
|
|
428
|
-
return
|
|
492
|
+
return container;
|
|
429
493
|
}
|
|
430
494
|
|
|
431
495
|
function onCopy(event) {
|
package/dist/runtime.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"runtime.js","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":";;;AAijBA,0DAEC;AAnjBY,QAAA,oBAAoB,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+iB7C,CAAC;AAEF,SAAgB,uBAAuB;IACrC,OAAO,4BAAoB,CAAC;AAC9B,CAAC"}
|