react-smart-copy 1.18.0 → 1.19.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 +87 -11
- package/dist/chunks/inert-html-D75NyVvT.js +34 -0
- package/dist/chunks/inert-html-D75NyVvT.js.map +1 -0
- package/dist/chunks/inert-html-DyxjWDok.cjs +39 -0
- package/dist/chunks/inert-html-DyxjWDok.cjs.map +1 -0
- package/dist/chunks/url-B9jdFGQy.cjs +86 -0
- package/dist/chunks/url-B9jdFGQy.cjs.map +1 -0
- package/dist/chunks/url-vJaFPbNL.js +57 -0
- package/dist/chunks/url-vJaFPbNL.js.map +1 -0
- package/dist/code.cjs +2 -1
- package/dist/code.cjs.map +1 -1
- package/dist/code.js +2 -1
- package/dist/code.js.map +1 -1
- package/dist/link.cjs +2 -1
- package/dist/link.cjs.map +1 -1
- package/dist/link.js +2 -1
- package/dist/link.js.map +1 -1
- package/dist/markdown.cjs +11 -62
- package/dist/markdown.cjs.map +1 -1
- package/dist/markdown.js +3 -54
- package/dist/markdown.js.map +1 -1
- package/dist/rich.cjs +1097 -6
- package/dist/rich.cjs.map +1 -1
- package/dist/rich.d.cts +97 -1
- package/dist/rich.d.ts +97 -1
- package/dist/rich.js +1095 -7
- package/dist/rich.js.map +1 -1
- package/dist/table.cjs +2 -1
- package/dist/table.cjs.map +1 -1
- package/dist/table.js +2 -1
- package/dist/table.js.map +1 -1
- package/package.json +21 -6
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ ID PLT-29018 [Copy]
|
|
|
33
33
|
- **`react-smart-copy/code`**: copy code blocks the way developers expect (a terminal session copies as its commands, gutters and prompts stay behind, colours survive in Docs and Slack), paste code cleaned and indented, and catch Trojan Source, invisible identifiers and lookalike letters
|
|
34
34
|
- **`react-smart-copy/image`**: get pasted photos and screenshots ready to upload. It removes GPS location, camera data and hidden thumbnails without touching a pixel, and fits size and byte limits, re-encoding only when it has to
|
|
35
35
|
- **`react-smart-copy/link`**: "Copy link" buttons that paste as a titled link in Slack, Docs and Notion and as the URL in editors, links that scroll to a highlighted passage, tracking parameters removed, and pasting a URL over selected text to make a link
|
|
36
|
-
- **`react-smart-copy/rich`**: copy styled content so it pastes as it looks in Gmail, Outlook, Apple Mail, Google Docs, Word, Notion and Slack: sanitized HTML with inline styles, email-safe colours and absolute links, plus readable plain text. Works for buttons and for Ctrl/⌘+C
|
|
36
|
+
- **`react-smart-copy/rich`**: copy styled content so it pastes as it looks in Gmail, Outlook, Apple Mail, Google Docs, Word, Notion and Slack: sanitized HTML with inline styles, email-safe colours and absolute links, plus readable plain text. Works for buttons and for Ctrl/⌘+C. And the other way: paste from Docs, Word and mail into a rich-text editor (TipTap, Lexical, `contenteditable`) as clean, semantic HTML
|
|
37
37
|
- **`react-smart-copy/color`**: copy colours in any CSS format (hex to `oklch()` and Display P3) with a swatch for Docs and Slack, paste any format into a colour field, and check WCAG contrast. Wide-gamut colours are mapped the way CSS specifies, never clipped to a wrong hue
|
|
38
38
|
- **`react-smart-copy/share`**: one "Share" button that opens the share sheet on phones and copies a titled link on desktop, with honest states: a closed share sheet is never an error
|
|
39
39
|
- **`react-smart-copy/capture`**: copy an `<svg>` or any piece of your UI as a PNG
|
|
@@ -60,6 +60,7 @@ This package only promises what browsers actually support.
|
|
|
60
60
|
| Pasted images, made safe | ✅ paste | `react-smart-copy/image`: removes location and camera metadata losslessly; resizes and compresses under a byte budget |
|
|
61
61
|
| Links (titled, to a passage) | ✅ | `react-smart-copy/link`: a titled `<a>` plus the URL; `text/uri-list` when dragged; text fragment links; never `javascript:` |
|
|
62
62
|
| Styled content, portable | ✅ | `react-smart-copy/rich`: sanitized HTML with inline styles and email-safe colours, plus plain text; for buttons and Ctrl/⌘+C |
|
|
63
|
+
| Rich text pasted into an editor | ✅ | `react-smart-copy/rich`: Docs, Word and mail into TipTap, Lexical or `contenteditable` as clean, semantic HTML |
|
|
63
64
|
| Colours (every CSS format) | ✅ | `react-smart-copy/color`: the value as text, plus a swatch for rich-text apps; any CSS colour read back on paste |
|
|
64
65
|
| Share sheet (Web Share API) | ✅ with copy fallback | `react-smart-copy/share`: the share sheet on phones and tablets, a titled link copied elsewhere; files where the share sheet takes them |
|
|
65
66
|
| SVG (icons, charts, logos) | ✅ as PNG | `svgToPngBlob()` from `react-smart-copy/capture` rasterises natively, no dependency. Raw SVG is not a clipboard image format |
|
|
@@ -685,7 +686,7 @@ documents with a CommonMark parser and compare the result character by character
|
|
|
685
686
|
- images default to their alt text (`images: "alt"`), so rendering the Markdown loads no tracking pixels. `"keep"` writes `` for `https:`/`http:` images, `"drop"` removes them
|
|
686
687
|
- `maxLength` (16 MiB), `maxNodes` (200,000) and `maxDepth` (200) bound the work; content left out sets `truncated: true`, and merged-cell expansion is capped
|
|
687
688
|
|
|
688
|
-
| Option | Default | |
|
|
689
|
+
| Option | Default | Notes |
|
|
689
690
|
| ------ | ------- | - |
|
|
690
691
|
| `images` | `"alt"` | `"alt"`, `"keep"` or `"drop"` |
|
|
691
692
|
| `links` | `"keep"` | `"text"` keeps only the link text |
|
|
@@ -763,7 +764,7 @@ Pasted code is never cut: past `maxLength` (2,000,000 characters) `pasteToCode`
|
|
|
763
764
|
`too-large` error, and `pasteAsCode` leaves the paste to the browser. HTML is parsed
|
|
764
765
|
inertly and only its text is used.
|
|
765
766
|
|
|
766
|
-
| Option | Default | |
|
|
767
|
+
| Option | Default | Notes |
|
|
767
768
|
| ------ | ------- | - |
|
|
768
769
|
| `prompt` | `"auto"` copy, `false` paste | a style (`"shell"`, `"powershell"`, `"cmd"`, `"python"`, `"ipython"`, `"node"`), `{ command, continuation }` regexes, or `false` |
|
|
769
770
|
| `diff` | `false` | `"after"` or `"before"` |
|
|
@@ -837,7 +838,7 @@ const info = await readImageInfo(file);
|
|
|
837
838
|
const { blob, removed } = await stripMetadata(file); // bit-for-bit the same picture
|
|
838
839
|
```
|
|
839
840
|
|
|
840
|
-
| Option (`prepareImage`) | Default | |
|
|
841
|
+
| Option (`prepareImage`) | Default | Notes |
|
|
841
842
|
| ----------------------- | ------- | - |
|
|
842
843
|
| `maxWidth` / `maxHeight` | none | only ever makes images smaller |
|
|
843
844
|
| `maxPixels` | 16,777,216 | Safari's canvas limit |
|
|
@@ -931,7 +932,7 @@ usePaste({ accept: ["text", "html", "text/uri-list"], onPaste: (result) => {
|
|
|
931
932
|
} });
|
|
932
933
|
```
|
|
933
934
|
|
|
934
|
-
| Option | Default | |
|
|
935
|
+
| Option | Default | Notes |
|
|
935
936
|
| ------ | ------- | - |
|
|
936
937
|
| `text` | `"url"` | plain text: `"url"`, `"title"`, `"title-and-url"` or `"markdown"` |
|
|
937
938
|
| `target` | clipboard | `"drag"` adds `text/uri-list` and `text/x-moz-url` |
|
|
@@ -999,7 +1000,7 @@ The output is property-tested against hostile HTML. [DOMPurify](https://github.c
|
|
|
999
1000
|
finds nothing to remove from it, and running the output through again changes nothing.
|
|
1000
1001
|
In Chromium, Firefox and WebKit, the computed styles are checked end to end.
|
|
1001
1002
|
|
|
1002
|
-
| Option | Default | |
|
|
1003
|
+
| Option | Default | Notes |
|
|
1003
1004
|
| --- | --- | --- |
|
|
1004
1005
|
| `colors` | `"readable"` | `"keep"`, `"none"` |
|
|
1005
1006
|
| `background` | `"#ffffff"` | where it is pasted, for readability |
|
|
@@ -1010,6 +1011,80 @@ In Chromium, Firefox and WebKit, the computed styles are checked end to end.
|
|
|
1010
1011
|
| `maxElements` / `maxLength` | 10,000 / 1,000,000 | then `truncated` |
|
|
1011
1012
|
| `text` | readable plain text | your own, such as Markdown |
|
|
1012
1013
|
|
|
1014
|
+
### Paste into a rich-text editor
|
|
1015
|
+
|
|
1016
|
+
The other way round: paste from Google Docs, Word, Outlook, Gmail or a web page into your
|
|
1017
|
+
editor, and get the content without the mess. Docs marks bold with `font-weight: 700` on
|
|
1018
|
+
spans inside a `<b>` that isn't bold. Word writes lists as paragraphs with `mso-list`
|
|
1019
|
+
styles and hides the bullets in spans. Mail wraps everything in layout tables. And every
|
|
1020
|
+
source brings its fonts, colours and classes, which fight your editor's look.
|
|
1021
|
+
`pasteToRich` turns all of it into clean, semantic HTML.
|
|
1022
|
+
|
|
1023
|
+
```tsx
|
|
1024
|
+
import { pasteAsRich, pasteToRich } from "react-smart-copy/rich";
|
|
1025
|
+
|
|
1026
|
+
// A contenteditable element: inserted with undo intact
|
|
1027
|
+
<div contentEditable onPaste={pasteAsRich} />
|
|
1028
|
+
|
|
1029
|
+
// TipTap / ProseMirror: clean it before the editor parses it
|
|
1030
|
+
useEditor({ editorProps: { transformPastedHTML: (html) => pasteToRich({ html })?.html ?? html } });
|
|
1031
|
+
|
|
1032
|
+
// Lexical: clean, then let Lexical import it
|
|
1033
|
+
editor.registerCommand(PASTE_COMMAND, (event) => {
|
|
1034
|
+
const pasted = pasteToRich({ html: event.clipboardData?.getData("text/html") });
|
|
1035
|
+
if (pasted?.source !== "html") return false;
|
|
1036
|
+
editor.update(() => $insertNodes($generateNodesFromDOM(editor, new DOMParser().parseFromString(pasted.html, "text/html"))));
|
|
1037
|
+
return true;
|
|
1038
|
+
}, COMMAND_PRIORITY_HIGH);
|
|
1039
|
+
|
|
1040
|
+
// A comment box: only what its toolbar has, and all of the text
|
|
1041
|
+
pasteToRich(result, { formats: ["bold", "italic", "link", "list"] });
|
|
1042
|
+
```
|
|
1043
|
+
|
|
1044
|
+
**What it writes:**
|
|
1045
|
+
|
|
1046
|
+
- **Semantic markup only.** Paragraphs, headings, lists, quotes, code blocks, tables, rules,
|
|
1047
|
+
links and images, with `<strong>`, `<em>`, `<u>`, `<s>`, `<code>`, `<sup>` and `<sub>`.
|
|
1048
|
+
Formatting set by CSS becomes these tags, and CSS wins over tags, as in the browser.
|
|
1049
|
+
Every style, class and id is left out, so pasted content takes your editor's look.
|
|
1050
|
+
- **Real structure from Word and Docs.** Word's list paragraphs become nested lists with
|
|
1051
|
+
their numbering. Docs' wrappers, paragraphs inside list items and lists nested beside
|
|
1052
|
+
their items are put right. Layout tables from mail become their content; data tables
|
|
1053
|
+
keep their sections, merged cells and captions. Code from editors and `<pre>` keeps its
|
|
1054
|
+
lines and indentation.
|
|
1055
|
+
- **Canonical.** The same content always gives the same HTML: links outermost, then formats
|
|
1056
|
+
in a fixed order, each over the longest stretch it covers. Whitespace collapses as the
|
|
1057
|
+
browser shows it. Cleaning the output again changes nothing.
|
|
1058
|
+
- **Safe.** The same sanitizer as `prepareRich`: allowlisted elements and attributes, links
|
|
1059
|
+
and images with absolute, scheme-checked URLs. Google and Outlook Safe Links redirects
|
|
1060
|
+
are unwrapped to their destination. Relative links have no address to resolve against,
|
|
1061
|
+
so they keep their text, unless you give `base`. `removed` reports scripts, embeds, unsafe
|
|
1062
|
+
links and images left out; it doesn't report what every clipboard document carries (its
|
|
1063
|
+
head, Office markup).
|
|
1064
|
+
- **`formats`** limits the output to what your editor holds. Nothing is lost: a heading
|
|
1065
|
+
becomes a bold paragraph, a list item a paragraph after its marker, a table its cells, a
|
|
1066
|
+
code block its lines, an image its alt text.
|
|
1067
|
+
|
|
1068
|
+
`pasteToRich(source, options)` takes `{ html, text }` (a `PasteResult` from `usePaste`
|
|
1069
|
+
fits) and returns `{ html, text, removed, truncated, source }`, or `null` when there is
|
|
1070
|
+
nothing to paste. Plain text becomes paragraphs and line breaks (`source: "text"`), and
|
|
1071
|
+
needs no DOM, so it works on a server too. `pasteAsRich(event, options)` handles a paste
|
|
1072
|
+
into a `contenteditable` element and leaves plain-text pastes to the browser; `onPaste`
|
|
1073
|
+
sees the result first, and returning `false` lets you insert it yourself. `maxNodes`
|
|
1074
|
+
(200,000), `maxElements` and `maxLength` bound the work, and HTML is read up to 16 MiB.
|
|
1075
|
+
|
|
1076
|
+
It is property-tested against generated Docs, Word, mail and hostile HTML. It writes only
|
|
1077
|
+
allowlisted markup, and DOMPurify finds nothing to remove. Every visible character is kept,
|
|
1078
|
+
with the bold, italic, underline, strikethrough, code, superscript and subscript it showed.
|
|
1079
|
+
And cleaning twice changes nothing.
|
|
1080
|
+
|
|
1081
|
+
A note for sites that collect Content Security Policy reports. Pasted HTML is parsed in an
|
|
1082
|
+
inert document, where scripts and handlers never run. Since Chromium 156, though, parsing an
|
|
1083
|
+
inline handler there (`<img onerror=…>` from a web page) under a policy that blocks inline
|
|
1084
|
+
handlers sends a `script-src-attr` report, whose target is the document rather than an element.
|
|
1085
|
+
Every HTML sanitizer that parses in the browser triggers it, and nothing is blocked that would
|
|
1086
|
+
have run ([w3c/webappsec-csp#824](https://github.com/w3c/webappsec-csp/issues/824)).
|
|
1087
|
+
|
|
1013
1088
|
## Copy and paste colours
|
|
1014
1089
|
|
|
1015
1090
|
`react-smart-copy/color` is for design-system docs, colour pickers, theme editors and
|
|
@@ -1061,7 +1136,7 @@ contrastLevel(contrastRatio("#767676", "#fff")); // "AA" (4.54)
|
|
|
1061
1136
|
parseColor("hsl(1turn 100% 50% / 50%)"); // { r: 1, g: 0, b: 0, alpha: 0.5 }
|
|
1062
1137
|
```
|
|
1063
1138
|
|
|
1064
|
-
| Option (`formatColor`, `colorPayload`) | Default | |
|
|
1139
|
+
| Option (`formatColor`, `colorPayload`) | Default | Notes |
|
|
1065
1140
|
| --- | --- | --- |
|
|
1066
1141
|
| `format` | `"hex"` | `colorPayload` only |
|
|
1067
1142
|
| `gamut` | `"map"` | `"clip"` |
|
|
@@ -1597,9 +1672,9 @@ embedded webviews. Where a capability is missing you get a typed error, never a
|
|
|
1597
1672
|
- ~~**1.16** `react-smart-copy/color` — copy and paste colours in every CSS format, CSS gamut mapping, WCAG contrast~~ shipped
|
|
1598
1673
|
- ~~**1.17** `react-smart-copy/rich` — styled content that pastes as it looks in mail, Docs, Word and Slack, for buttons and Ctrl/⌘+C~~ shipped
|
|
1599
1674
|
- ~~**1.18** One shared copy of the core across entry points: smaller bundles when you use several modules, and one `CopyFailure` class~~ shipped
|
|
1600
|
-
-
|
|
1675
|
+
- ~~**1.19** `react-smart-copy/rich`, paste side: paste from Word, Google Docs and web pages into rich-text editors as clean, safe HTML~~ shipped
|
|
1601
1676
|
|
|
1602
|
-
Full history: [CHANGELOG.md](./CHANGELOG.md) or the [Releases page](https://suprabhat02.github.io/react-smart-copy
|
|
1677
|
+
Full history: [CHANGELOG.md](./CHANGELOG.md) or the [Releases page](https://suprabhat02.github.io/react-smart-copy/project/releases/).
|
|
1603
1678
|
|
|
1604
1679
|
## Development
|
|
1605
1680
|
|
|
@@ -1607,8 +1682,9 @@ Full history: [CHANGELOG.md](./CHANGELOG.md) or the [Releases page](https://supr
|
|
|
1607
1682
|
npm install
|
|
1608
1683
|
npm run verify # lint, types, tests at 100% coverage, build, publint + attw, consumer types, size budgets
|
|
1609
1684
|
npm run changeset # describe your change for the changelog
|
|
1610
|
-
npm run
|
|
1611
|
-
npm run
|
|
1685
|
+
npm run docs:install # once: the docs site has its own lockfile, in docs/
|
|
1686
|
+
npm run docs:dev # the docs, with live demos, at http://localhost:4321/react-smart-copy/
|
|
1687
|
+
npm run docs:build && npm run test:e2e # end-to-end tests in Chromium, Firefox and WebKit
|
|
1612
1688
|
```
|
|
1613
1689
|
|
|
1614
1690
|
Releases are automated: merging the "chore: release" PR publishes to npm through
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/core/inert-html.ts
|
|
3
|
+
/**
|
|
4
|
+
* Parsing HTML text that came from outside (the clipboard, a drop, a caller): shared by the
|
|
5
|
+
* opt-in entry points. Internal: not part of `react-smart-copy/core`'s public API.
|
|
6
|
+
*/
|
|
7
|
+
/** A `NodeFilter.SHOW_ELEMENT`, without needing the global. */
|
|
8
|
+
const SHOW_ELEMENT = 1;
|
|
9
|
+
/**
|
|
10
|
+
* Parses HTML text into an inert document: scripts and event handlers never run, and nothing is
|
|
11
|
+
* fetched. Its nodes are only read, never inserted into a page.
|
|
12
|
+
*
|
|
13
|
+
* Event handler attributes (`onerror`, `onclick`, ...) are also removed at once, so no node of
|
|
14
|
+
* the document carries one, whatever reads it later.
|
|
15
|
+
*
|
|
16
|
+
* With a Content Security Policy that blocks inline handlers, Chromium (since 156) reports a
|
|
17
|
+
* `script-src-attr` violation, targeting the Document, for each handler it parses into an inert
|
|
18
|
+
* document, though the handler never runs (w3c/webappsec-csp#824). No parser can avoid that report.
|
|
19
|
+
*
|
|
20
|
+
* Needs `DOMParser`: callers check for it first.
|
|
21
|
+
*/
|
|
22
|
+
function parseInertHtml(html) {
|
|
23
|
+
const doc = new DOMParser().parseFromString(html, "text/html");
|
|
24
|
+
const walker = doc.createTreeWalker(doc, SHOW_ELEMENT);
|
|
25
|
+
for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) {
|
|
26
|
+
const element = node;
|
|
27
|
+
for (const attribute of Array.from(element.attributes)) if (attribute.name.length > 2 && attribute.name.slice(0, 2).toLowerCase() === "on") element.removeAttribute(attribute.name);
|
|
28
|
+
}
|
|
29
|
+
return doc;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { parseInertHtml as t };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=inert-html-D75NyVvT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inert-html-D75NyVvT.js","names":[],"sources":["../../src/core/inert-html.ts"],"sourcesContent":["/**\n * Parsing HTML text that came from outside (the clipboard, a drop, a caller): shared by the\n * opt-in entry points. Internal: not part of `react-smart-copy/core`'s public API.\n */\n\n/** A `NodeFilter.SHOW_ELEMENT`, without needing the global. */\nconst SHOW_ELEMENT = 1;\n\n/**\n * Parses HTML text into an inert document: scripts and event handlers never run, and nothing is\n * fetched. Its nodes are only read, never inserted into a page.\n *\n * Event handler attributes (`onerror`, `onclick`, ...) are also removed at once, so no node of\n * the document carries one, whatever reads it later.\n *\n * With a Content Security Policy that blocks inline handlers, Chromium (since 156) reports a\n * `script-src-attr` violation, targeting the Document, for each handler it parses into an inert\n * document, though the handler never runs (w3c/webappsec-csp#824). No parser can avoid that report.\n *\n * Needs `DOMParser`: callers check for it first.\n */\nexport function parseInertHtml(html: string): Document {\n // Inert: CodeQL's js/xss sees DOMParser as a sink, so this file is left out of its analysis (codeql.yml).\n const doc = new DOMParser().parseFromString(html, 'text/html');\n // A tree walker, not a selector: selector engines are slow to start in DOMs like jsdom.\n const walker = doc.createTreeWalker(doc, SHOW_ELEMENT);\n for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) {\n const element = node as Element;\n for (const attribute of Array.from(element.attributes)) {\n if (attribute.name.length > 2 && attribute.name.slice(0, 2).toLowerCase() === 'on') element.removeAttribute(attribute.name);\n }\n }\n return doc;\n}\n"],"mappings":";;;;;;;AAMA,MAAM,eAAe;;;;;;;;;;;;;;AAerB,SAAgB,eAAe,MAAwB;CAErD,MAAM,MAAM,IAAI,UAAU,CAAC,CAAC,gBAAgB,MAAM,WAAW;CAE7D,MAAM,SAAS,IAAI,iBAAiB,KAAK,YAAY;CACrD,KAAK,IAAI,OAAO,OAAO,SAAS,GAAG,SAAS,MAAM,OAAO,OAAO,SAAS,GAAG;EAC1E,MAAM,UAAU;EAChB,KAAK,MAAM,aAAa,MAAM,KAAK,QAAQ,UAAU,GACnD,IAAI,UAAU,KAAK,SAAS,KAAK,UAAU,KAAK,MAAM,GAAG,CAAC,CAAC,CAAC,YAAY,MAAM,MAAM,QAAQ,gBAAgB,UAAU,IAAI;CAE9H;CACA,OAAO;AACT"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/core/inert-html.ts
|
|
3
|
+
/**
|
|
4
|
+
* Parsing HTML text that came from outside (the clipboard, a drop, a caller): shared by the
|
|
5
|
+
* opt-in entry points. Internal: not part of `react-smart-copy/core`'s public API.
|
|
6
|
+
*/
|
|
7
|
+
/** A `NodeFilter.SHOW_ELEMENT`, without needing the global. */
|
|
8
|
+
const SHOW_ELEMENT = 1;
|
|
9
|
+
/**
|
|
10
|
+
* Parses HTML text into an inert document: scripts and event handlers never run, and nothing is
|
|
11
|
+
* fetched. Its nodes are only read, never inserted into a page.
|
|
12
|
+
*
|
|
13
|
+
* Event handler attributes (`onerror`, `onclick`, ...) are also removed at once, so no node of
|
|
14
|
+
* the document carries one, whatever reads it later.
|
|
15
|
+
*
|
|
16
|
+
* With a Content Security Policy that blocks inline handlers, Chromium (since 156) reports a
|
|
17
|
+
* `script-src-attr` violation, targeting the Document, for each handler it parses into an inert
|
|
18
|
+
* document, though the handler never runs (w3c/webappsec-csp#824). No parser can avoid that report.
|
|
19
|
+
*
|
|
20
|
+
* Needs `DOMParser`: callers check for it first.
|
|
21
|
+
*/
|
|
22
|
+
function parseInertHtml(html) {
|
|
23
|
+
const doc = new DOMParser().parseFromString(html, "text/html");
|
|
24
|
+
const walker = doc.createTreeWalker(doc, SHOW_ELEMENT);
|
|
25
|
+
for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) {
|
|
26
|
+
const element = node;
|
|
27
|
+
for (const attribute of Array.from(element.attributes)) if (attribute.name.length > 2 && attribute.name.slice(0, 2).toLowerCase() === "on") element.removeAttribute(attribute.name);
|
|
28
|
+
}
|
|
29
|
+
return doc;
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
Object.defineProperty(exports, "parseInertHtml", {
|
|
33
|
+
enumerable: true,
|
|
34
|
+
get: function() {
|
|
35
|
+
return parseInertHtml;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
//# sourceMappingURL=inert-html-DyxjWDok.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inert-html-DyxjWDok.cjs","names":[],"sources":["../../src/core/inert-html.ts"],"sourcesContent":["/**\n * Parsing HTML text that came from outside (the clipboard, a drop, a caller): shared by the\n * opt-in entry points. Internal: not part of `react-smart-copy/core`'s public API.\n */\n\n/** A `NodeFilter.SHOW_ELEMENT`, without needing the global. */\nconst SHOW_ELEMENT = 1;\n\n/**\n * Parses HTML text into an inert document: scripts and event handlers never run, and nothing is\n * fetched. Its nodes are only read, never inserted into a page.\n *\n * Event handler attributes (`onerror`, `onclick`, ...) are also removed at once, so no node of\n * the document carries one, whatever reads it later.\n *\n * With a Content Security Policy that blocks inline handlers, Chromium (since 156) reports a\n * `script-src-attr` violation, targeting the Document, for each handler it parses into an inert\n * document, though the handler never runs (w3c/webappsec-csp#824). No parser can avoid that report.\n *\n * Needs `DOMParser`: callers check for it first.\n */\nexport function parseInertHtml(html: string): Document {\n // Inert: CodeQL's js/xss sees DOMParser as a sink, so this file is left out of its analysis (codeql.yml).\n const doc = new DOMParser().parseFromString(html, 'text/html');\n // A tree walker, not a selector: selector engines are slow to start in DOMs like jsdom.\n const walker = doc.createTreeWalker(doc, SHOW_ELEMENT);\n for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) {\n const element = node as Element;\n for (const attribute of Array.from(element.attributes)) {\n if (attribute.name.length > 2 && attribute.name.slice(0, 2).toLowerCase() === 'on') element.removeAttribute(attribute.name);\n }\n }\n return doc;\n}\n"],"mappings":";;;;;;;AAMA,MAAM,eAAe;;;;;;;;;;;;;;AAerB,SAAgB,eAAe,MAAwB;CAErD,MAAM,MAAM,IAAI,UAAU,CAAC,CAAC,gBAAgB,MAAM,WAAW;CAE7D,MAAM,SAAS,IAAI,iBAAiB,KAAK,YAAY;CACrD,KAAK,IAAI,OAAO,OAAO,SAAS,GAAG,SAAS,MAAM,OAAO,OAAO,SAAS,GAAG;EAC1E,MAAM,UAAU;EAChB,KAAK,MAAM,aAAa,MAAM,KAAK,QAAQ,UAAU,GACnD,IAAI,UAAU,KAAK,SAAS,KAAK,UAAU,KAAK,MAAM,GAAG,CAAC,CAAC,CAAC,YAAY,MAAM,MAAM,QAAQ,gBAAgB,UAAU,IAAI;CAE9H;CACA,OAAO;AACT"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/markdown/url.ts
|
|
3
|
+
/**
|
|
4
|
+
* URL safety for pasted links and images. Only absolute URLs with an allowed
|
|
5
|
+
* scheme survive; everything else (`javascript:`, `data:`, `vbscript:`,
|
|
6
|
+
* relative links without a base, malformed URLs) is dropped and the visible
|
|
7
|
+
* text is kept. Parsing uses the WHATWG URL parser, the same one the browser
|
|
8
|
+
* uses when the link is clicked, so tricks like `java\tscript:` are seen as
|
|
9
|
+
* `javascript:`.
|
|
10
|
+
*/
|
|
11
|
+
const DEFAULT_LINK_PROTOCOLS = [
|
|
12
|
+
"http:",
|
|
13
|
+
"https:",
|
|
14
|
+
"mailto:"
|
|
15
|
+
];
|
|
16
|
+
const DEFAULT_IMAGE_PROTOCOLS = ["https:", "http:"];
|
|
17
|
+
function parse(raw, base) {
|
|
18
|
+
try {
|
|
19
|
+
return new URL(raw.trim(), base);
|
|
20
|
+
} catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Click-tracking redirects that pasted links often carry: Google (Docs,
|
|
26
|
+
* Search, Gmail) and Outlook Safe Links. Unwrapped only to an http(s) target.
|
|
27
|
+
*/
|
|
28
|
+
function unwrapRedirect(url) {
|
|
29
|
+
const host = url.hostname.toLowerCase();
|
|
30
|
+
const param = /(^|\.)google\.[a-z.]+$/.test(host) && url.pathname === "/url" ? url.searchParams.get("q") ?? url.searchParams.get("url") : host.endsWith(".safelinks.protection.outlook.com") ? url.searchParams.get("url") : null;
|
|
31
|
+
if (param === null) return url;
|
|
32
|
+
const target = parse(param, void 0);
|
|
33
|
+
return target !== null && (target.protocol === "https:" || target.protocol === "http:") ? target : url;
|
|
34
|
+
}
|
|
35
|
+
/** The normalised URL, or `null` when it is not absolute or its scheme is not allowed. */
|
|
36
|
+
function safeUrl(raw, protocols, base) {
|
|
37
|
+
const parsed = parse(raw, base);
|
|
38
|
+
if (parsed === null) return null;
|
|
39
|
+
const url = unwrapRedirect(parsed);
|
|
40
|
+
return protocols.includes(url.protocol) ? url.href : null;
|
|
41
|
+
}
|
|
42
|
+
/** `href` comes from the URL serialiser, which already percent-encodes every non-ASCII character. */
|
|
43
|
+
const percent = (char) => `%${char.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0")}`;
|
|
44
|
+
/**
|
|
45
|
+
* A Markdown link destination. ASCII whitespace, `<`, `>` and controls are
|
|
46
|
+
* percent-encoded (opaque URLs such as `mailto:` keep them otherwise),
|
|
47
|
+
* backslashes too so they can't act as escapes, and parentheses are kept
|
|
48
|
+
* exact by using the `<…>` form.
|
|
49
|
+
*/
|
|
50
|
+
function linkDestination(href) {
|
|
51
|
+
const encoded = href.replace(/[ <>\\\u0000-\u001f\u007f]/g, percent);
|
|
52
|
+
return /[()]/.test(encoded) ? `<${encoded}>` : encoded;
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
Object.defineProperty(exports, "DEFAULT_IMAGE_PROTOCOLS", {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
get: function() {
|
|
58
|
+
return DEFAULT_IMAGE_PROTOCOLS;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
Object.defineProperty(exports, "DEFAULT_LINK_PROTOCOLS", {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
get: function() {
|
|
64
|
+
return DEFAULT_LINK_PROTOCOLS;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
Object.defineProperty(exports, "linkDestination", {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
get: function() {
|
|
70
|
+
return linkDestination;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
Object.defineProperty(exports, "safeUrl", {
|
|
74
|
+
enumerable: true,
|
|
75
|
+
get: function() {
|
|
76
|
+
return safeUrl;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
Object.defineProperty(exports, "unwrapRedirect", {
|
|
80
|
+
enumerable: true,
|
|
81
|
+
get: function() {
|
|
82
|
+
return unwrapRedirect;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
//# sourceMappingURL=url-B9jdFGQy.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url-B9jdFGQy.cjs","names":[],"sources":["../../src/markdown/url.ts"],"sourcesContent":["/**\n * URL safety for pasted links and images. Only absolute URLs with an allowed\n * scheme survive; everything else (`javascript:`, `data:`, `vbscript:`,\n * relative links without a base, malformed URLs) is dropped and the visible\n * text is kept. Parsing uses the WHATWG URL parser, the same one the browser\n * uses when the link is clicked, so tricks like `java\\tscript:` are seen as\n * `javascript:`.\n */\n\nexport const DEFAULT_LINK_PROTOCOLS: readonly string[] = ['http:', 'https:', 'mailto:'];\nexport const DEFAULT_IMAGE_PROTOCOLS: readonly string[] = ['https:', 'http:'];\n\nfunction parse(raw: string, base: string | undefined): URL | null {\n try {\n return new URL(raw.trim(), base);\n } catch {\n return null;\n }\n}\n\n/**\n * Click-tracking redirects that pasted links often carry: Google (Docs,\n * Search, Gmail) and Outlook Safe Links. Unwrapped only to an http(s) target.\n */\nexport function unwrapRedirect(url: URL): URL {\n const host = url.hostname.toLowerCase();\n const param =\n /(^|\\.)google\\.[a-z.]+$/.test(host) && url.pathname === '/url'\n ? (url.searchParams.get('q') ?? url.searchParams.get('url'))\n : host.endsWith('.safelinks.protection.outlook.com')\n ? url.searchParams.get('url')\n : null;\n if (param === null) return url;\n const target = parse(param, undefined);\n return target !== null && (target.protocol === 'https:' || target.protocol === 'http:') ? target : url;\n}\n\n/** The normalised URL, or `null` when it is not absolute or its scheme is not allowed. */\nexport function safeUrl(raw: string, protocols: readonly string[], base: string | undefined): string | null {\n const parsed = parse(raw, base);\n if (parsed === null) return null;\n const url = unwrapRedirect(parsed);\n return protocols.includes(url.protocol) ? url.href : null;\n}\n\n/** `href` comes from the URL serialiser, which already percent-encodes every non-ASCII character. */\nconst percent = (char: string): string => `%${char.charCodeAt(0).toString(16).toUpperCase().padStart(2, '0')}`;\n\n/**\n * A Markdown link destination. ASCII whitespace, `<`, `>` and controls are\n * percent-encoded (opaque URLs such as `mailto:` keep them otherwise),\n * backslashes too so they can't act as escapes, and parentheses are kept\n * exact by using the `<…>` form.\n */\nexport function linkDestination(href: string): string {\n // eslint-disable-next-line no-control-regex -- control characters are exactly what must be encoded\n const encoded = href.replace(/[ <>\\\\\\u0000-\\u001f\\u007f]/g, percent);\n return /[()]/.test(encoded) ? `<${encoded}>` : encoded;\n}\n"],"mappings":";;;;;;;;;;AASA,MAAa,yBAA4C;CAAC;CAAS;CAAU;AAAS;AACtF,MAAa,0BAA6C,CAAC,UAAU,OAAO;AAE5E,SAAS,MAAM,KAAa,MAAsC;CAChE,IAAI;EACF,OAAO,IAAI,IAAI,IAAI,KAAK,GAAG,IAAI;CACjC,QAAQ;EACN,OAAO;CACT;AACF;;;;;AAMA,SAAgB,eAAe,KAAe;CAC5C,MAAM,OAAO,IAAI,SAAS,YAAY;CACtC,MAAM,QACJ,yBAAyB,KAAK,IAAI,KAAK,IAAI,aAAa,SACnD,IAAI,aAAa,IAAI,GAAG,KAAK,IAAI,aAAa,IAAI,KAAK,IACxD,KAAK,SAAS,mCAAmC,IAC/C,IAAI,aAAa,IAAI,KAAK,IAC1B;CACR,IAAI,UAAU,MAAM,OAAO;CAC3B,MAAM,SAAS,MAAM,OAAO,KAAA,CAAS;CACrC,OAAO,WAAW,SAAS,OAAO,aAAa,YAAY,OAAO,aAAa,WAAW,SAAS;AACrG;;AAGA,SAAgB,QAAQ,KAAa,WAA8B,MAAyC;CAC1G,MAAM,SAAS,MAAM,KAAK,IAAI;CAC9B,IAAI,WAAW,MAAM,OAAO;CAC5B,MAAM,MAAM,eAAe,MAAM;CACjC,OAAO,UAAU,SAAS,IAAI,QAAQ,IAAI,IAAI,OAAO;AACvD;;AAGA,MAAM,WAAW,SAAyB,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,YAAY,CAAC,CAAC,SAAS,GAAG,GAAG;;;;;;;AAQ3G,SAAgB,gBAAgB,MAAsB;CAEpD,MAAM,UAAU,KAAK,QAAQ,+BAA+B,OAAO;CACnE,OAAO,OAAO,KAAK,OAAO,IAAI,IAAI,QAAQ,KAAK;AACjD"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/markdown/url.ts
|
|
3
|
+
/**
|
|
4
|
+
* URL safety for pasted links and images. Only absolute URLs with an allowed
|
|
5
|
+
* scheme survive; everything else (`javascript:`, `data:`, `vbscript:`,
|
|
6
|
+
* relative links without a base, malformed URLs) is dropped and the visible
|
|
7
|
+
* text is kept. Parsing uses the WHATWG URL parser, the same one the browser
|
|
8
|
+
* uses when the link is clicked, so tricks like `java\tscript:` are seen as
|
|
9
|
+
* `javascript:`.
|
|
10
|
+
*/
|
|
11
|
+
const DEFAULT_LINK_PROTOCOLS = [
|
|
12
|
+
"http:",
|
|
13
|
+
"https:",
|
|
14
|
+
"mailto:"
|
|
15
|
+
];
|
|
16
|
+
const DEFAULT_IMAGE_PROTOCOLS = ["https:", "http:"];
|
|
17
|
+
function parse(raw, base) {
|
|
18
|
+
try {
|
|
19
|
+
return new URL(raw.trim(), base);
|
|
20
|
+
} catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Click-tracking redirects that pasted links often carry: Google (Docs,
|
|
26
|
+
* Search, Gmail) and Outlook Safe Links. Unwrapped only to an http(s) target.
|
|
27
|
+
*/
|
|
28
|
+
function unwrapRedirect(url) {
|
|
29
|
+
const host = url.hostname.toLowerCase();
|
|
30
|
+
const param = /(^|\.)google\.[a-z.]+$/.test(host) && url.pathname === "/url" ? url.searchParams.get("q") ?? url.searchParams.get("url") : host.endsWith(".safelinks.protection.outlook.com") ? url.searchParams.get("url") : null;
|
|
31
|
+
if (param === null) return url;
|
|
32
|
+
const target = parse(param, void 0);
|
|
33
|
+
return target !== null && (target.protocol === "https:" || target.protocol === "http:") ? target : url;
|
|
34
|
+
}
|
|
35
|
+
/** The normalised URL, or `null` when it is not absolute or its scheme is not allowed. */
|
|
36
|
+
function safeUrl(raw, protocols, base) {
|
|
37
|
+
const parsed = parse(raw, base);
|
|
38
|
+
if (parsed === null) return null;
|
|
39
|
+
const url = unwrapRedirect(parsed);
|
|
40
|
+
return protocols.includes(url.protocol) ? url.href : null;
|
|
41
|
+
}
|
|
42
|
+
/** `href` comes from the URL serialiser, which already percent-encodes every non-ASCII character. */
|
|
43
|
+
const percent = (char) => `%${char.charCodeAt(0).toString(16).toUpperCase().padStart(2, "0")}`;
|
|
44
|
+
/**
|
|
45
|
+
* A Markdown link destination. ASCII whitespace, `<`, `>` and controls are
|
|
46
|
+
* percent-encoded (opaque URLs such as `mailto:` keep them otherwise),
|
|
47
|
+
* backslashes too so they can't act as escapes, and parentheses are kept
|
|
48
|
+
* exact by using the `<…>` form.
|
|
49
|
+
*/
|
|
50
|
+
function linkDestination(href) {
|
|
51
|
+
const encoded = href.replace(/[ <>\\\u0000-\u001f\u007f]/g, percent);
|
|
52
|
+
return /[()]/.test(encoded) ? `<${encoded}>` : encoded;
|
|
53
|
+
}
|
|
54
|
+
//#endregion
|
|
55
|
+
export { unwrapRedirect as a, safeUrl as i, DEFAULT_LINK_PROTOCOLS as n, linkDestination as r, DEFAULT_IMAGE_PROTOCOLS as t };
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=url-vJaFPbNL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url-vJaFPbNL.js","names":[],"sources":["../../src/markdown/url.ts"],"sourcesContent":["/**\n * URL safety for pasted links and images. Only absolute URLs with an allowed\n * scheme survive; everything else (`javascript:`, `data:`, `vbscript:`,\n * relative links without a base, malformed URLs) is dropped and the visible\n * text is kept. Parsing uses the WHATWG URL parser, the same one the browser\n * uses when the link is clicked, so tricks like `java\\tscript:` are seen as\n * `javascript:`.\n */\n\nexport const DEFAULT_LINK_PROTOCOLS: readonly string[] = ['http:', 'https:', 'mailto:'];\nexport const DEFAULT_IMAGE_PROTOCOLS: readonly string[] = ['https:', 'http:'];\n\nfunction parse(raw: string, base: string | undefined): URL | null {\n try {\n return new URL(raw.trim(), base);\n } catch {\n return null;\n }\n}\n\n/**\n * Click-tracking redirects that pasted links often carry: Google (Docs,\n * Search, Gmail) and Outlook Safe Links. Unwrapped only to an http(s) target.\n */\nexport function unwrapRedirect(url: URL): URL {\n const host = url.hostname.toLowerCase();\n const param =\n /(^|\\.)google\\.[a-z.]+$/.test(host) && url.pathname === '/url'\n ? (url.searchParams.get('q') ?? url.searchParams.get('url'))\n : host.endsWith('.safelinks.protection.outlook.com')\n ? url.searchParams.get('url')\n : null;\n if (param === null) return url;\n const target = parse(param, undefined);\n return target !== null && (target.protocol === 'https:' || target.protocol === 'http:') ? target : url;\n}\n\n/** The normalised URL, or `null` when it is not absolute or its scheme is not allowed. */\nexport function safeUrl(raw: string, protocols: readonly string[], base: string | undefined): string | null {\n const parsed = parse(raw, base);\n if (parsed === null) return null;\n const url = unwrapRedirect(parsed);\n return protocols.includes(url.protocol) ? url.href : null;\n}\n\n/** `href` comes from the URL serialiser, which already percent-encodes every non-ASCII character. */\nconst percent = (char: string): string => `%${char.charCodeAt(0).toString(16).toUpperCase().padStart(2, '0')}`;\n\n/**\n * A Markdown link destination. ASCII whitespace, `<`, `>` and controls are\n * percent-encoded (opaque URLs such as `mailto:` keep them otherwise),\n * backslashes too so they can't act as escapes, and parentheses are kept\n * exact by using the `<…>` form.\n */\nexport function linkDestination(href: string): string {\n // eslint-disable-next-line no-control-regex -- control characters are exactly what must be encoded\n const encoded = href.replace(/[ <>\\\\\\u0000-\\u001f\\u007f]/g, percent);\n return /[()]/.test(encoded) ? `<${encoded}>` : encoded;\n}\n"],"mappings":";;;;;;;;;;AASA,MAAa,yBAA4C;CAAC;CAAS;CAAU;AAAS;AACtF,MAAa,0BAA6C,CAAC,UAAU,OAAO;AAE5E,SAAS,MAAM,KAAa,MAAsC;CAChE,IAAI;EACF,OAAO,IAAI,IAAI,IAAI,KAAK,GAAG,IAAI;CACjC,QAAQ;EACN,OAAO;CACT;AACF;;;;;AAMA,SAAgB,eAAe,KAAe;CAC5C,MAAM,OAAO,IAAI,SAAS,YAAY;CACtC,MAAM,QACJ,yBAAyB,KAAK,IAAI,KAAK,IAAI,aAAa,SACnD,IAAI,aAAa,IAAI,GAAG,KAAK,IAAI,aAAa,IAAI,KAAK,IACxD,KAAK,SAAS,mCAAmC,IAC/C,IAAI,aAAa,IAAI,KAAK,IAC1B;CACR,IAAI,UAAU,MAAM,OAAO;CAC3B,MAAM,SAAS,MAAM,OAAO,KAAA,CAAS;CACrC,OAAO,WAAW,SAAS,OAAO,aAAa,YAAY,OAAO,aAAa,WAAW,SAAS;AACrG;;AAGA,SAAgB,QAAQ,KAAa,WAA8B,MAAyC;CAC1G,MAAM,SAAS,MAAM,KAAK,IAAI;CAC9B,IAAI,WAAW,MAAM,OAAO;CAC5B,MAAM,MAAM,eAAe,MAAM;CACjC,OAAO,UAAU,SAAS,IAAI,QAAQ,IAAI,IAAI,OAAO;AACvD;;AAGA,MAAM,WAAW,SAAyB,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,YAAY,CAAC,CAAC,SAAS,GAAG,GAAG;;;;;;;AAQ3G,SAAgB,gBAAgB,MAAsB;CAEpD,MAAM,UAAU,KAAK,QAAQ,+BAA+B,OAAO;CACnE,OAAO,OAAO,KAAK,OAAO,IAAI,IAAI,QAAQ,KAAK;AACjD"}
|
package/dist/code.cjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const require_errors = require("./chunks/errors-BwOF6T_M.cjs");
|
|
4
|
+
const require_inert_html = require("./chunks/inert-html-DyxjWDok.cjs");
|
|
4
5
|
const require_text_field = require("./chunks/text-field-Ba8W3v4R.cjs");
|
|
5
6
|
//#region src/code/inspect.ts
|
|
6
7
|
/** Every finding kind, in a stable order. */
|
|
@@ -1011,7 +1012,7 @@ function pasteToCode(source, options = {}) {
|
|
|
1011
1012
|
let from = "text";
|
|
1012
1013
|
if (text === "" && typeof source.html === "string" && source.html.trim() !== "" && typeof DOMParser !== "undefined") {
|
|
1013
1014
|
if (source.html.length > maxLength) throw require_errors.copyFailure("too-large", `The pasted HTML is longer than maxLength (${String(maxLength)}).`);
|
|
1014
|
-
const body =
|
|
1015
|
+
const body = require_inert_html.parseInertHtml(source.html).body;
|
|
1015
1016
|
text = extract(body, { styles: false }).runs.map((run) => run.text).join("");
|
|
1016
1017
|
from = "html";
|
|
1017
1018
|
}
|