@mzebley/mark-down 1.2.2 → 1.2.3
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 +16 -22
- package/dist/angular/index.d.ts +3 -1
- package/dist/angular/index.js +18 -8
- package/dist/angular/index.js.map +1 -1
- package/dist/browser.js +222 -31
- package/dist/browser.js.map +1 -1
- package/dist/{chunk-MWZFQXNW.js → chunk-WZCXKUXV.js} +128 -3
- package/dist/chunk-WZCXKUXV.js.map +1 -0
- package/dist/{chunk-35YHML5Z.js → chunk-X5L6GGFF.js} +69 -25
- package/dist/chunk-X5L6GGFF.js.map +1 -0
- package/dist/{chunk-GWLMADTU.js → chunk-ZEQXN4ZD.js} +4 -2
- package/dist/{chunk-GWLMADTU.js.map → chunk-ZEQXN4ZD.js.map} +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +7 -5
- package/dist/inline.d.ts +4 -0
- package/dist/inline.js +20 -6
- package/dist/inline.js.map +1 -1
- package/dist/mark-down-inline.umd.js +8951 -14
- package/dist/mark-down-inline.umd.js.map +1 -1
- package/dist/sanitize-DI2uKnlG.d.ts +10 -0
- package/dist/slug.js +1 -1
- package/dist/{snippet-client-CiQX2Zcn.d.ts → snippet-client-S6E_j24g.d.ts} +3 -0
- package/package.json +5 -2
- package/dist/chunk-35YHML5Z.js.map +0 -1
- package/dist/chunk-MWZFQXNW.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { S as SnippetMeta } from './snippet-client-
|
|
2
|
-
export { M as ManifestSource, R as ResponseLike, a as Snippet, f as SnippetClient, e as SnippetClientOptions, d as SnippetFetcher, c as SnippetFetcherResult, b as SnippetSearchFilter } from './snippet-client-
|
|
1
|
+
import { S as SnippetMeta } from './snippet-client-S6E_j24g.js';
|
|
2
|
+
export { M as ManifestSource, R as ResponseLike, a as Snippet, f as SnippetClient, e as SnippetClientOptions, d as SnippetFetcher, c as SnippetFetcherResult, b as SnippetSearchFilter } from './snippet-client-S6E_j24g.js';
|
|
3
3
|
export { normalizeSlug } from './slug.js';
|
|
4
|
+
export { S as SanitizeOptions, a as SanitizePolicy, s as sanitizeMarkup } from './sanitize-DI2uKnlG.js';
|
|
5
|
+
import 'sanitize-html';
|
|
4
6
|
|
|
5
7
|
declare class SnippetNotFoundError extends Error {
|
|
6
8
|
readonly slug: string;
|
package/dist/index.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SnippetClient
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-X5L6GGFF.js";
|
|
4
4
|
import {
|
|
5
5
|
normalizeSlug
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-ZEQXN4ZD.js";
|
|
7
7
|
import {
|
|
8
8
|
ManifestLoadError,
|
|
9
9
|
SnippetNotFoundError,
|
|
10
10
|
parseFrontMatter,
|
|
11
|
-
renderMarkdown
|
|
12
|
-
|
|
11
|
+
renderMarkdown,
|
|
12
|
+
sanitizeMarkup
|
|
13
|
+
} from "./chunk-WZCXKUXV.js";
|
|
13
14
|
import "./chunk-BRKEJJFQ.js";
|
|
14
15
|
export {
|
|
15
16
|
ManifestLoadError,
|
|
@@ -17,6 +18,7 @@ export {
|
|
|
17
18
|
SnippetNotFoundError,
|
|
18
19
|
normalizeSlug,
|
|
19
20
|
parseFrontMatter,
|
|
20
|
-
renderMarkdown
|
|
21
|
+
renderMarkdown,
|
|
22
|
+
sanitizeMarkup
|
|
21
23
|
};
|
|
22
24
|
//# sourceMappingURL=index.js.map
|
package/dist/inline.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
+
import { S as SanitizeOptions } from './sanitize-DI2uKnlG.js';
|
|
2
|
+
import 'sanitize-html';
|
|
3
|
+
|
|
1
4
|
interface InlineMarkdownOptions {
|
|
2
5
|
selector?: string;
|
|
3
6
|
processFrontMatter?: boolean;
|
|
4
7
|
applyMetaToDom?: boolean;
|
|
8
|
+
sanitize?: SanitizeOptions;
|
|
5
9
|
}
|
|
6
10
|
declare function enhanceInlineMarkdown(options?: InlineMarkdownOptions): void;
|
|
7
11
|
|
package/dist/inline.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
parseFrontMatter,
|
|
3
|
-
renderMarkdown
|
|
4
|
-
|
|
3
|
+
renderMarkdown,
|
|
4
|
+
sanitizeMarkup
|
|
5
|
+
} from "./chunk-WZCXKUXV.js";
|
|
5
6
|
import "./chunk-BRKEJJFQ.js";
|
|
6
7
|
|
|
7
8
|
// src/inline.ts
|
|
@@ -13,12 +14,19 @@ function enhanceInlineMarkdown(options = {}) {
|
|
|
13
14
|
const selector = options.selector ?? DEFAULT_SELECTOR;
|
|
14
15
|
const processFrontMatter = options.processFrontMatter !== false;
|
|
15
16
|
const applyMetaToDom = options.applyMetaToDom !== false;
|
|
16
|
-
const
|
|
17
|
+
const sanitize = options.sanitize;
|
|
18
|
+
let elements = [];
|
|
19
|
+
try {
|
|
20
|
+
elements = Array.from(document.querySelectorAll(selector));
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.warn("[mark\u2193 inline] Invalid selector provided:", error);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
17
25
|
for (const element of elements) {
|
|
18
26
|
if (element.dataset.markdownProcessed === "true") {
|
|
19
27
|
continue;
|
|
20
28
|
}
|
|
21
|
-
processElement(element, { processFrontMatter, applyMetaToDom });
|
|
29
|
+
processElement(element, { processFrontMatter, applyMetaToDom, sanitize });
|
|
22
30
|
}
|
|
23
31
|
}
|
|
24
32
|
function processElement(element, options) {
|
|
@@ -28,12 +36,18 @@ function processElement(element, options) {
|
|
|
28
36
|
try {
|
|
29
37
|
frontMatter = parseFrontMatter(raw);
|
|
30
38
|
} catch (error) {
|
|
31
|
-
console.warn(
|
|
39
|
+
console.warn(
|
|
40
|
+
"[mark\u2193 inline] Failed to parse front matter for element:",
|
|
41
|
+
error
|
|
42
|
+
);
|
|
32
43
|
frontMatter = void 0;
|
|
33
44
|
}
|
|
34
45
|
}
|
|
35
46
|
const body = frontMatter?.content ?? raw;
|
|
36
|
-
|
|
47
|
+
let html = renderMarkdown(body);
|
|
48
|
+
if (options.sanitize) {
|
|
49
|
+
html = sanitizeMarkup(html, options.sanitize);
|
|
50
|
+
}
|
|
37
51
|
element.innerHTML = html;
|
|
38
52
|
element.dataset.markdownProcessed = "true";
|
|
39
53
|
if (options.applyMetaToDom && frontMatter?.hasFrontMatter) {
|
package/dist/inline.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/inline.ts"],"sourcesContent":["import { parseFrontMatter, type FrontMatterResult } from \"./front-matter\";\nimport { renderMarkdown } from \"./markdown\";\n\nexport interface InlineMarkdownOptions {\n selector?: string;\n processFrontMatter?: boolean;\n applyMetaToDom?: boolean;\n}\n\nconst DEFAULT_SELECTOR = \"[data-markdown]\";\n\nexport function enhanceInlineMarkdown(options: InlineMarkdownOptions = {}): void {\n if (typeof document === \"undefined\") {\n return;\n }\n\n const selector = options.selector ?? DEFAULT_SELECTOR;\n const processFrontMatter = options.processFrontMatter !== false;\n const applyMetaToDom = options.applyMetaToDom !== false;\n\n
|
|
1
|
+
{"version":3,"sources":["../src/inline.ts"],"sourcesContent":["import { parseFrontMatter, type FrontMatterResult } from \"./front-matter\";\nimport { renderMarkdown } from \"./markdown\";\nimport { sanitizeMarkup, type SanitizeOptions } from \"./sanitize\";\n\nexport interface InlineMarkdownOptions {\n selector?: string;\n processFrontMatter?: boolean;\n applyMetaToDom?: boolean;\n sanitize?: SanitizeOptions;\n}\n\nconst DEFAULT_SELECTOR = \"[data-markdown]\";\n\nexport function enhanceInlineMarkdown(\n options: InlineMarkdownOptions = {},\n): void {\n if (typeof document === \"undefined\") {\n return;\n }\n\n const selector = options.selector ?? DEFAULT_SELECTOR;\n const processFrontMatter = options.processFrontMatter !== false;\n const applyMetaToDom = options.applyMetaToDom !== false;\n const sanitize = options.sanitize;\n\n let elements: HTMLElement[] = [];\n try {\n elements = Array.from(document.querySelectorAll<HTMLElement>(selector));\n } catch (error) {\n console.warn(\"[mark↓ inline] Invalid selector provided:\", error);\n return;\n }\n for (const element of elements) {\n if (element.dataset.markdownProcessed === \"true\") {\n continue;\n }\n processElement(element, { processFrontMatter, applyMetaToDom, sanitize });\n }\n}\n\nfunction processElement(\n element: HTMLElement,\n options: {\n processFrontMatter: boolean;\n applyMetaToDom: boolean;\n sanitize?: SanitizeOptions;\n },\n): void {\n const raw = element.textContent ?? \"\";\n let frontMatter: FrontMatterResult | undefined;\n\n if (options.processFrontMatter) {\n try {\n frontMatter = parseFrontMatter(raw);\n } catch (error) {\n console.warn(\n \"[mark↓ inline] Failed to parse front matter for element:\",\n error,\n );\n frontMatter = undefined;\n }\n }\n\n const body = frontMatter?.content ?? raw;\n let html = renderMarkdown(body);\n if (options.sanitize) {\n html = sanitizeMarkup(html, options.sanitize);\n }\n\n element.innerHTML = html;\n element.dataset.markdownProcessed = \"true\";\n\n if (options.applyMetaToDom && frontMatter?.hasFrontMatter) {\n applyMetaAttributes(element, frontMatter);\n }\n}\n\nfunction applyMetaAttributes(\n element: HTMLElement,\n frontMatter: FrontMatterResult,\n): void {\n const { slug, meta, extra } = frontMatter;\n\n if (slug) {\n if (!element.id) {\n element.id = slug;\n }\n element.dataset.slug = slug;\n }\n\n if (meta.title) {\n element.dataset.title = meta.title;\n }\n\n if (meta.tags?.length) {\n element.dataset.tags = meta.tags.join(\",\");\n }\n\n const variant = typeof extra.variant === \"string\" ? extra.variant.trim() : \"\";\n if (variant) {\n element.classList.add(`md-block--${variant}`);\n }\n}\n"],"mappings":";;;;;;;;AAWA,IAAM,mBAAmB;AAElB,SAAS,sBACd,UAAiC,CAAC,GAC5B;AACN,MAAI,OAAO,aAAa,aAAa;AACnC;AAAA,EACF;AAEA,QAAM,WAAW,QAAQ,YAAY;AACrC,QAAM,qBAAqB,QAAQ,uBAAuB;AAC1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