@scalar/code-highlight 0.1.0 → 0.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.
- package/CHANGELOG.md +7 -0
- package/dist/css/markdown.css +1 -1
- package/package.json +3 -3
- package/dist/code/highlight.test.js +0 -64
- package/dist/code/highlight.test.js.map +0 -7
- package/dist/markdown/getHeadings.test.js +0 -45
- package/dist/markdown/getHeadings.test.js.map +0 -7
- package/dist/markdown/htmlFromMarkdown.test.js +0 -41
- package/dist/markdown/htmlFromMarkdown.test.js.map +0 -7
- package/dist/markdown/splitContent.test.js +0 -17
- package/dist/markdown/splitContent.test.js.map +0 -7
- package/dist/rehype-alert/rehype-alert.test.js +0 -74
- package/dist/rehype-alert/rehype-alert.test.js.map +0 -7
package/CHANGELOG.md
CHANGED
package/dist/css/markdown.css
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
.scalar-app {
|
|
4
4
|
.markdown {
|
|
5
5
|
font-family: var(--scalar-font);
|
|
6
|
-
color: var(--scalar-color-1);
|
|
7
6
|
word-break: break-word;
|
|
8
7
|
}
|
|
9
8
|
|
|
@@ -105,6 +104,7 @@
|
|
|
105
104
|
font-weight: var(--scalar-bold);
|
|
106
105
|
display: block;
|
|
107
106
|
line-height: 1.45;
|
|
107
|
+
scroll-margin-top: 1rem;
|
|
108
108
|
}
|
|
109
109
|
.markdown b,
|
|
110
110
|
.markdown strong {
|
package/package.json
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"lowlight",
|
|
17
17
|
"highlightjs"
|
|
18
18
|
],
|
|
19
|
-
"version": "0.1.
|
|
19
|
+
"version": "0.1.1",
|
|
20
20
|
"engines": {
|
|
21
21
|
"node": ">=20"
|
|
22
22
|
},
|
|
@@ -97,8 +97,8 @@
|
|
|
97
97
|
"vfile": "^6.0.1",
|
|
98
98
|
"vite": "5.4.19",
|
|
99
99
|
"vue": "^3.5.12",
|
|
100
|
-
"@scalar/
|
|
101
|
-
"@scalar/
|
|
100
|
+
"@scalar/themes": "0.13.0",
|
|
101
|
+
"@scalar/build-tooling": "0.2.1"
|
|
102
102
|
},
|
|
103
103
|
"scripts": {
|
|
104
104
|
"build": "scalar-build-esbuild",
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { syntaxHighlight } from "./highlight.js";
|
|
3
|
-
describe("syntaxHighlight", () => {
|
|
4
|
-
const mockLanguages = {
|
|
5
|
-
javascript: () => ({
|
|
6
|
-
name: "javascript",
|
|
7
|
-
aliases: ["js"],
|
|
8
|
-
contains: []
|
|
9
|
-
})
|
|
10
|
-
};
|
|
11
|
-
const defaultOptions = {
|
|
12
|
-
lang: "javascript",
|
|
13
|
-
languages: mockLanguages
|
|
14
|
-
};
|
|
15
|
-
const codeExample = `
|
|
16
|
-
fetch('https://galaxy.scalar.com/planets', {
|
|
17
|
-
method: 'POST',
|
|
18
|
-
headers: {
|
|
19
|
-
'Content-Type': 'application/json'
|
|
20
|
-
}
|
|
21
|
-
})
|
|
22
|
-
`;
|
|
23
|
-
it("should return highlighted HTML for a given code string", () => {
|
|
24
|
-
const result = syntaxHighlight(codeExample, defaultOptions);
|
|
25
|
-
expect(result).toContain('class="hljs language-javascript"');
|
|
26
|
-
});
|
|
27
|
-
it("should mask credentials in the code string", () => {
|
|
28
|
-
const codeWithCredentials = `
|
|
29
|
-
fetch('https://galaxy.scalar.com/planets', {
|
|
30
|
-
method: 'POST',
|
|
31
|
-
headers: {
|
|
32
|
-
'Content-Type': 'application/json',
|
|
33
|
-
'Authorization': 'Bearer secret'
|
|
34
|
-
}
|
|
35
|
-
})
|
|
36
|
-
`;
|
|
37
|
-
const options = {
|
|
38
|
-
...defaultOptions,
|
|
39
|
-
maskCredentials: ["secret"]
|
|
40
|
-
};
|
|
41
|
-
const result = syntaxHighlight(codeWithCredentials, options);
|
|
42
|
-
expect(result).toContain('<span class="credential"><span class="credential-value">secret</span></span>');
|
|
43
|
-
});
|
|
44
|
-
it("should handle line numbers if option is enabled", () => {
|
|
45
|
-
const options = {
|
|
46
|
-
...defaultOptions,
|
|
47
|
-
lineNumbers: true
|
|
48
|
-
};
|
|
49
|
-
const result = syntaxHighlight(codeExample, options);
|
|
50
|
-
expect(result).toContain('class="line"');
|
|
51
|
-
});
|
|
52
|
-
it("should correctly work with special characters in credentials", () => {
|
|
53
|
-
const codeExampleWithSpecialChar = `
|
|
54
|
-
const secret = '(secret';
|
|
55
|
-
`;
|
|
56
|
-
const options = {
|
|
57
|
-
...defaultOptions,
|
|
58
|
-
maskCredentials: ["(secret"]
|
|
59
|
-
};
|
|
60
|
-
const result = syntaxHighlight(codeExampleWithSpecialChar, options);
|
|
61
|
-
expect(result).toContain('<span class="credential"><span class="credential-value">(secret</span></span>');
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
//# sourceMappingURL=highlight.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/code/highlight.test.ts"],
|
|
4
|
-
"sourcesContent": ["import type { LanguageFn } from 'highlight.js'\nimport { describe, expect, it } from 'vitest'\n\nimport { syntaxHighlight } from './highlight'\n\ndescribe('syntaxHighlight', () => {\n const mockLanguages: Record<string, LanguageFn> = {\n javascript: () => ({\n name: 'javascript',\n aliases: ['js'],\n contains: [],\n }),\n }\n\n const defaultOptions = {\n lang: 'javascript',\n languages: mockLanguages,\n }\n\n const codeExample = `\n fetch('https://galaxy.scalar.com/planets', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json'\n }\n })\n `\n\n it('should return highlighted HTML for a given code string', () => {\n const result = syntaxHighlight(codeExample, defaultOptions)\n expect(result).toContain('class=\"hljs language-javascript\"')\n })\n\n it('should mask credentials in the code string', () => {\n const codeWithCredentials = `\n fetch('https://galaxy.scalar.com/planets', {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Authorization': 'Bearer secret'\n }\n })\n `\n const options = {\n ...defaultOptions,\n maskCredentials: ['secret'],\n }\n\n const result = syntaxHighlight(codeWithCredentials, options)\n expect(result).toContain('<span class=\"credential\"><span class=\"credential-value\">secret</span></span>')\n })\n\n it('should handle line numbers if option is enabled', () => {\n const options = {\n ...defaultOptions,\n lineNumbers: true,\n }\n\n const result = syntaxHighlight(codeExample, options)\n expect(result).toContain('class=\"line\"')\n })\n\n it('should correctly work with special characters in credentials', () => {\n const codeExampleWithSpecialChar = `\n const secret = '(secret';\n `\n const options = {\n ...defaultOptions,\n maskCredentials: ['(secret'],\n }\n\n const result = syntaxHighlight(codeExampleWithSpecialChar, options)\n expect(result).toContain('<span class=\"credential\"><span class=\"credential-value\">(secret</span></span>')\n })\n})\n"],
|
|
5
|
-
"mappings": "AACA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,uBAAuB;AAEhC,SAAS,mBAAmB,MAAM;AAChC,QAAM,gBAA4C;AAAA,IAChD,YAAY,OAAO;AAAA,MACjB,MAAM;AAAA,MACN,SAAS,CAAC,IAAI;AAAA,MACd,UAAU,CAAC;AAAA,IACb;AAAA,EACF;AAEA,QAAM,iBAAiB;AAAA,IACrB,MAAM;AAAA,IACN,WAAW;AAAA,EACb;AAEA,QAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASpB,KAAG,0DAA0D,MAAM;AACjE,UAAM,SAAS,gBAAgB,aAAa,cAAc;AAC1D,WAAO,MAAM,EAAE,UAAU,kCAAkC;AAAA,EAC7D,CAAC;AAED,KAAG,8CAA8C,MAAM;AACrD,UAAM,sBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAS5B,UAAM,UAAU;AAAA,MACd,GAAG;AAAA,MACH,iBAAiB,CAAC,QAAQ;AAAA,IAC5B;AAEA,UAAM,SAAS,gBAAgB,qBAAqB,OAAO;AAC3D,WAAO,MAAM,EAAE,UAAU,8EAA8E;AAAA,EACzG,CAAC;AAED,KAAG,mDAAmD,MAAM;AAC1D,UAAM,UAAU;AAAA,MACd,GAAG;AAAA,MACH,aAAa;AAAA,IACf;AAEA,UAAM,SAAS,gBAAgB,aAAa,OAAO;AACnD,WAAO,MAAM,EAAE,UAAU,cAAc;AAAA,EACzC,CAAC;AAED,KAAG,gEAAgE,MAAM;AACvE,UAAM,6BAA6B;AAAA;AAAA;AAGnC,UAAM,UAAU;AAAA,MACd,GAAG;AAAA,MACH,iBAAiB,CAAC,SAAS;AAAA,IAC7B;AAEA,UAAM,SAAS,gBAAgB,4BAA4B,OAAO;AAClE,WAAO,MAAM,EAAE,UAAU,+EAA+E;AAAA,EAC1G,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { getHeadings } from "./markdown.js";
|
|
3
|
-
describe("getHeadings", () => {
|
|
4
|
-
it("gets a heading", () => {
|
|
5
|
-
const markdown = "# Example Heading";
|
|
6
|
-
const headings = getHeadings(markdown);
|
|
7
|
-
expect(headings).toStrictEqual([{ depth: 1, value: "Example Heading" }]);
|
|
8
|
-
});
|
|
9
|
-
it("gets nested headings", () => {
|
|
10
|
-
const markdown = `
|
|
11
|
-
# Example Heading
|
|
12
|
-
|
|
13
|
-
## Nested Heading
|
|
14
|
-
`;
|
|
15
|
-
const headings = getHeadings(markdown);
|
|
16
|
-
expect(headings).toStrictEqual([
|
|
17
|
-
{ depth: 1, value: "Example Heading" },
|
|
18
|
-
{ depth: 2, value: "Nested Heading" }
|
|
19
|
-
]);
|
|
20
|
-
});
|
|
21
|
-
it("ignores Markdown in code blocks", () => {
|
|
22
|
-
const markdown = `
|
|
23
|
-
# Example Heading
|
|
24
|
-
|
|
25
|
-
## Not a heading
|
|
26
|
-
|
|
27
|
-
## Nested Heading
|
|
28
|
-
|
|
29
|
-
\`\`\`
|
|
30
|
-
## Not a heading
|
|
31
|
-
\`\`\`
|
|
32
|
-
`;
|
|
33
|
-
const headings = getHeadings(markdown);
|
|
34
|
-
expect(headings).toStrictEqual([
|
|
35
|
-
{ depth: 1, value: "Example Heading" },
|
|
36
|
-
{ depth: 2, value: "Nested Heading" }
|
|
37
|
-
]);
|
|
38
|
-
});
|
|
39
|
-
it("works with links in headings", () => {
|
|
40
|
-
const markdown = "# [Example Heading](#example-heading)";
|
|
41
|
-
const headings = getHeadings(markdown);
|
|
42
|
-
expect(headings).toStrictEqual([{ depth: 1, value: "Example Heading" }]);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
//# sourceMappingURL=getHeadings.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/markdown/getHeadings.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { getHeadings } from './markdown'\n\ndescribe('getHeadings', () => {\n it('gets a heading', () => {\n const markdown = '# Example Heading'\n\n const headings = getHeadings(markdown)\n\n expect(headings).toStrictEqual([{ depth: 1, value: 'Example Heading' }])\n })\n\n it('gets nested headings', () => {\n const markdown = `\n# Example Heading\n\n## Nested Heading\n`\n\n const headings = getHeadings(markdown)\n\n expect(headings).toStrictEqual([\n { depth: 1, value: 'Example Heading' },\n { depth: 2, value: 'Nested Heading' },\n ])\n })\n\n it('ignores Markdown in code blocks', () => {\n const markdown = `\n# Example Heading\n\n ## Not a heading\n\n## Nested Heading\n\n\\`\\`\\`\n## Not a heading\n\\`\\`\\`\n`\n\n const headings = getHeadings(markdown)\n\n expect(headings).toStrictEqual([\n { depth: 1, value: 'Example Heading' },\n { depth: 2, value: 'Nested Heading' },\n ])\n })\n\n it('works with links in headings', () => {\n const markdown = '# [Example Heading](#example-heading)'\n\n const headings = getHeadings(markdown)\n\n expect(headings).toStrictEqual([{ depth: 1, value: 'Example Heading' }])\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,mBAAmB;AAE5B,SAAS,eAAe,MAAM;AAC5B,KAAG,kBAAkB,MAAM;AACzB,UAAM,WAAW;AAEjB,UAAM,WAAW,YAAY,QAAQ;AAErC,WAAO,QAAQ,EAAE,cAAc,CAAC,EAAE,OAAO,GAAG,OAAO,kBAAkB,CAAC,CAAC;AAAA,EACzE,CAAC;AAED,KAAG,wBAAwB,MAAM;AAC/B,UAAM,WAAW;AAAA;AAAA;AAAA;AAAA;AAMjB,UAAM,WAAW,YAAY,QAAQ;AAErC,WAAO,QAAQ,EAAE,cAAc;AAAA,MAC7B,EAAE,OAAO,GAAG,OAAO,kBAAkB;AAAA,MACrC,EAAE,OAAO,GAAG,OAAO,iBAAiB;AAAA,IACtC,CAAC;AAAA,EACH,CAAC;AAED,KAAG,mCAAmC,MAAM;AAC1C,UAAM,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYjB,UAAM,WAAW,YAAY,QAAQ;AAErC,WAAO,QAAQ,EAAE,cAAc;AAAA,MAC7B,EAAE,OAAO,GAAG,OAAO,kBAAkB;AAAA,MACrC,EAAE,OAAO,GAAG,OAAO,iBAAiB;AAAA,IACtC,CAAC;AAAA,EACH,CAAC;AAED,KAAG,gCAAgC,MAAM;AACvC,UAAM,WAAW;AAEjB,UAAM,WAAW,YAAY,QAAQ;AAErC,WAAO,QAAQ,EAAE,cAAc,CAAC,EAAE,OAAO,GAAG,OAAO,kBAAkB,CAAC,CAAC;AAAA,EACzE,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { htmlFromMarkdown } from "./markdown.js";
|
|
3
|
-
describe("htmlFromMarkdown", () => {
|
|
4
|
-
it("returns HTML", () => {
|
|
5
|
-
const html = htmlFromMarkdown("# Example Heading");
|
|
6
|
-
expect(html.trim()).toEqual("<h1>Example Heading</h1>");
|
|
7
|
-
});
|
|
8
|
-
it("removes tags", () => {
|
|
9
|
-
const html = htmlFromMarkdown("# <i>Example</i> <em>Heading</em>", {
|
|
10
|
-
removeTags: ["i"]
|
|
11
|
-
});
|
|
12
|
-
expect(html.trim()).toEqual("<h1>Example <em>Heading</em></h1>");
|
|
13
|
-
});
|
|
14
|
-
it("removes script tags", () => {
|
|
15
|
-
const html = htmlFromMarkdown(`# Example Heading<script>alert('foobar');<\/script>`);
|
|
16
|
-
expect(html.trim()).toEqual("<h1>Example Heading</h1>");
|
|
17
|
-
});
|
|
18
|
-
it("allows given tags", () => {
|
|
19
|
-
const html = htmlFromMarkdown(`# Example Heading<script>alert('foobar');<\/script>`, {
|
|
20
|
-
allowTags: ["script"]
|
|
21
|
-
});
|
|
22
|
-
expect(html.trim()).toEqual(`<h1>Example Heading
|
|
23
|
-
<script>alert('foobar');<\/script>
|
|
24
|
-
</h1>`);
|
|
25
|
-
});
|
|
26
|
-
it("allows to add ids", () => {
|
|
27
|
-
const html = htmlFromMarkdown("# Example Heading", {
|
|
28
|
-
transformType: "heading",
|
|
29
|
-
transform: (node) => {
|
|
30
|
-
node.data = {
|
|
31
|
-
hProperties: {
|
|
32
|
-
id: "example-heading"
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
return node;
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
expect(html.trim()).toEqual('<h1 id="example-heading">Example Heading</h1>');
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
//# sourceMappingURL=htmlFromMarkdown.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/markdown/htmlFromMarkdown.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { htmlFromMarkdown } from './markdown'\n\ndescribe('htmlFromMarkdown', () => {\n it('returns HTML', () => {\n const html = htmlFromMarkdown('# Example Heading')\n\n expect(html.trim()).toEqual('<h1>Example Heading</h1>')\n })\n\n it('removes tags', () => {\n const html = htmlFromMarkdown('# <i>Example</i> <em>Heading</em>', {\n removeTags: ['i'],\n })\n\n expect(html.trim()).toEqual('<h1>Example <em>Heading</em></h1>')\n })\n\n it('removes script tags', () => {\n const html = htmlFromMarkdown(`# Example Heading<script>alert('foobar');</script>`)\n\n expect(html.trim()).toEqual('<h1>Example Heading</h1>')\n })\n\n it('allows given tags', () => {\n const html = htmlFromMarkdown(`# Example Heading<script>alert('foobar');</script>`, {\n allowTags: ['script'],\n })\n\n expect(html.trim()).toEqual(`<h1>Example Heading\\n <script>alert('foobar');</script>\\n</h1>`)\n })\n\n it('allows to add ids', () => {\n const html = htmlFromMarkdown('# Example Heading', {\n transformType: 'heading',\n transform: (node) => {\n node.data = {\n hProperties: {\n id: 'example-heading',\n },\n }\n\n return node\n },\n })\n\n expect(html.trim()).toEqual('<h1 id=\"example-heading\">Example Heading</h1>')\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,wBAAwB;AAEjC,SAAS,oBAAoB,MAAM;AACjC,KAAG,gBAAgB,MAAM;AACvB,UAAM,OAAO,iBAAiB,mBAAmB;AAEjD,WAAO,KAAK,KAAK,CAAC,EAAE,QAAQ,0BAA0B;AAAA,EACxD,CAAC;AAED,KAAG,gBAAgB,MAAM;AACvB,UAAM,OAAO,iBAAiB,qCAAqC;AAAA,MACjE,YAAY,CAAC,GAAG;AAAA,IAClB,CAAC;AAED,WAAO,KAAK,KAAK,CAAC,EAAE,QAAQ,mCAAmC;AAAA,EACjE,CAAC;AAED,KAAG,uBAAuB,MAAM;AAC9B,UAAM,OAAO,iBAAiB,qDAAoD;AAElF,WAAO,KAAK,KAAK,CAAC,EAAE,QAAQ,0BAA0B;AAAA,EACxD,CAAC;AAED,KAAG,qBAAqB,MAAM;AAC5B,UAAM,OAAO,iBAAiB,uDAAsD;AAAA,MAClF,WAAW,CAAC,QAAQ;AAAA,IACtB,CAAC;AAED,WAAO,KAAK,KAAK,CAAC,EAAE,QAAQ;AAAA;AAAA,MAAiE;AAAA,EAC/F,CAAC;AAED,KAAG,qBAAqB,MAAM;AAC5B,UAAM,OAAO,iBAAiB,qBAAqB;AAAA,MACjD,eAAe;AAAA,MACf,WAAW,CAAC,SAAS;AACnB,aAAK,OAAO;AAAA,UACV,aAAa;AAAA,YACX,IAAI;AAAA,UACN;AAAA,QACF;AAEA,eAAO;AAAA,MACT;AAAA,IACF,CAAC;AAED,WAAO,KAAK,KAAK,CAAC,EAAE,QAAQ,+CAA+C;AAAA,EAC7E,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { splitContent } from "./markdown.js";
|
|
3
|
-
describe("splitContent", () => {
|
|
4
|
-
it("returns a single document if there\u2019s no heading", () => {
|
|
5
|
-
const sections = splitContent("Foobar");
|
|
6
|
-
expect(sections).toMatchObject(["Foobar"]);
|
|
7
|
-
});
|
|
8
|
-
it("splits the markdown document", () => {
|
|
9
|
-
const sections = splitContent("# Example Heading\n\nFoobar");
|
|
10
|
-
expect(sections).toMatchObject(["# Example Heading", "Foobar"]);
|
|
11
|
-
});
|
|
12
|
-
it("splits multiple headings", () => {
|
|
13
|
-
const sections = splitContent("# Example Heading\n\n## Other Heading\n\nFoobar");
|
|
14
|
-
expect(sections).toMatchObject(["# Example Heading", "## Other Heading", "Foobar"]);
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
//# sourceMappingURL=splitContent.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/markdown/splitContent.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\n\nimport { splitContent } from './markdown'\n\ndescribe('splitContent', () => {\n it('returns a single document if there\u2019s no heading', () => {\n const sections = splitContent('Foobar')\n\n expect(sections).toMatchObject(['Foobar'])\n })\n\n it('splits the markdown document', () => {\n const sections = splitContent('# Example Heading\\n\\nFoobar')\n\n expect(sections).toMatchObject(['# Example Heading', 'Foobar'])\n })\n\n it('splits multiple headings', () => {\n const sections = splitContent('# Example Heading\\n\\n## Other Heading\\n\\nFoobar')\n\n expect(sections).toMatchObject(['# Example Heading', '## Other Heading', 'Foobar'])\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AAErC,SAAS,oBAAoB;AAE7B,SAAS,gBAAgB,MAAM;AAC7B,KAAG,wDAAmD,MAAM;AAC1D,UAAM,WAAW,aAAa,QAAQ;AAEtC,WAAO,QAAQ,EAAE,cAAc,CAAC,QAAQ,CAAC;AAAA,EAC3C,CAAC;AAED,KAAG,gCAAgC,MAAM;AACvC,UAAM,WAAW,aAAa,6BAA6B;AAE3D,WAAO,QAAQ,EAAE,cAAc,CAAC,qBAAqB,QAAQ,CAAC;AAAA,EAChE,CAAC;AAED,KAAG,4BAA4B,MAAM;AACnC,UAAM,WAAW,aAAa,iDAAiD;AAE/E,WAAO,QAAQ,EAAE,cAAc,CAAC,qBAAqB,oBAAoB,QAAQ,CAAC;AAAA,EACpF,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { unified } from "unified";
|
|
3
|
-
import remarkParse from "remark-parse";
|
|
4
|
-
import remarkRehype from "remark-rehype";
|
|
5
|
-
import rehypeStringify from "rehype-stringify";
|
|
6
|
-
import { rehypeAlert } from "./rehype-alert.js";
|
|
7
|
-
describe("rehype-alert", () => {
|
|
8
|
-
const process = async (markdown) => {
|
|
9
|
-
const file = await unified().use(remarkParse).use(remarkRehype, { allowDangerousHtml: true }).use(rehypeAlert).use(rehypeStringify).process(markdown);
|
|
10
|
-
return String(file);
|
|
11
|
-
};
|
|
12
|
-
it("transforms note alerts correctly", async () => {
|
|
13
|
-
const input = "> [!note]\n> This is a note callout.";
|
|
14
|
-
const output = await process(input);
|
|
15
|
-
expect(output).toContain('<div class="markdown-alert markdown-alert-note">');
|
|
16
|
-
expect(output).toContain('<div class="markdown-alert-content">');
|
|
17
|
-
expect(output).toContain("This is a note callout.");
|
|
18
|
-
});
|
|
19
|
-
it("transforms warning alerts correctly", async () => {
|
|
20
|
-
const input = "> [!warning]\n> This is a warning callout.";
|
|
21
|
-
const output = await process(input);
|
|
22
|
-
expect(output).toContain('<div class="markdown-alert markdown-alert-warning">');
|
|
23
|
-
expect(output).toContain("This is a warning callout.");
|
|
24
|
-
});
|
|
25
|
-
it("transforms caution alerts correctly", async () => {
|
|
26
|
-
const input = "> [!caution]\n> This is a caution callout.";
|
|
27
|
-
const output = await process(input);
|
|
28
|
-
expect(output).toContain('<div class="markdown-alert markdown-alert-caution">');
|
|
29
|
-
expect(output).toContain("This is a caution callout.");
|
|
30
|
-
});
|
|
31
|
-
it("transforms important alerts correctly", async () => {
|
|
32
|
-
const input = "> [!important]\n> This is an important callout.";
|
|
33
|
-
const output = await process(input);
|
|
34
|
-
expect(output).toContain('<div class="markdown-alert markdown-alert-important">');
|
|
35
|
-
expect(output).toContain("This is an important callout.");
|
|
36
|
-
});
|
|
37
|
-
it("transforms tip alerts correctly", async () => {
|
|
38
|
-
const input = "> [!tip]\n> This is a tip callout.";
|
|
39
|
-
const output = await process(input);
|
|
40
|
-
expect(output).toContain('<div class="markdown-alert markdown-alert-tip">');
|
|
41
|
-
expect(output).toContain("This is a tip callout.");
|
|
42
|
-
});
|
|
43
|
-
it("ignores blockquotes without alert syntax", async () => {
|
|
44
|
-
const input = "> This is a regular blockquote.";
|
|
45
|
-
const output = await process(input);
|
|
46
|
-
expect(output).not.toContain("markdown-alert");
|
|
47
|
-
expect(output).toContain("<blockquote>");
|
|
48
|
-
expect(output).toContain("This is a regular blockquote.");
|
|
49
|
-
});
|
|
50
|
-
it("ignores invalid alert types", async () => {
|
|
51
|
-
const input = "> [!invalid]\n> This is an invalid alert type.";
|
|
52
|
-
const output = await process(input);
|
|
53
|
-
expect(output).not.toContain("markdown-alert");
|
|
54
|
-
expect(output).toContain("<blockquote>");
|
|
55
|
-
expect(output).toContain("[!invalid]");
|
|
56
|
-
expect(output).toContain("This is an invalid alert type.");
|
|
57
|
-
});
|
|
58
|
-
it("handles multiline alert content correctly", async () => {
|
|
59
|
-
const input = "> [!note]\n> First line\n> Second line\n> Third line";
|
|
60
|
-
const output = await process(input);
|
|
61
|
-
expect(output).toContain('<div class="markdown-alert markdown-alert-note">');
|
|
62
|
-
expect(output).toContain("First line");
|
|
63
|
-
expect(output).toContain("Second line");
|
|
64
|
-
expect(output).toContain("Third line");
|
|
65
|
-
});
|
|
66
|
-
it("preserves HTML structure in alert content", async () => {
|
|
67
|
-
const input = "> [!note]\n> This is a note with **bold** and *italic* text.";
|
|
68
|
-
const output = await process(input);
|
|
69
|
-
expect(output).toContain('<div class="markdown-alert markdown-alert-note">');
|
|
70
|
-
expect(output).toContain("<strong>bold</strong>");
|
|
71
|
-
expect(output).toContain("<em>italic</em>");
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
//# sourceMappingURL=rehype-alert.test.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/rehype-alert/rehype-alert.test.ts"],
|
|
4
|
-
"sourcesContent": ["import { describe, expect, it } from 'vitest'\nimport { unified } from 'unified'\nimport remarkParse from 'remark-parse'\nimport remarkRehype from 'remark-rehype'\nimport rehypeStringify from 'rehype-stringify'\nimport { rehypeAlert } from './rehype-alert'\n\ndescribe('rehype-alert', () => {\n const process = async (markdown: string) => {\n const file = await unified()\n .use(remarkParse)\n .use(remarkRehype, { allowDangerousHtml: true })\n .use(rehypeAlert)\n .use(rehypeStringify)\n .process(markdown)\n\n return String(file)\n }\n\n it('transforms note alerts correctly', async () => {\n const input = '> [!note]\\n> This is a note callout.'\n const output = await process(input)\n\n expect(output).toContain('<div class=\"markdown-alert markdown-alert-note\">')\n expect(output).toContain('<div class=\"markdown-alert-content\">')\n expect(output).toContain('This is a note callout.')\n })\n\n it('transforms warning alerts correctly', async () => {\n const input = '> [!warning]\\n> This is a warning callout.'\n const output = await process(input)\n\n expect(output).toContain('<div class=\"markdown-alert markdown-alert-warning\">')\n expect(output).toContain('This is a warning callout.')\n })\n\n it('transforms caution alerts correctly', async () => {\n const input = '> [!caution]\\n> This is a caution callout.'\n const output = await process(input)\n\n expect(output).toContain('<div class=\"markdown-alert markdown-alert-caution\">')\n expect(output).toContain('This is a caution callout.')\n })\n\n it('transforms important alerts correctly', async () => {\n const input = '> [!important]\\n> This is an important callout.'\n const output = await process(input)\n\n expect(output).toContain('<div class=\"markdown-alert markdown-alert-important\">')\n expect(output).toContain('This is an important callout.')\n })\n\n it('transforms tip alerts correctly', async () => {\n const input = '> [!tip]\\n> This is a tip callout.'\n const output = await process(input)\n\n expect(output).toContain('<div class=\"markdown-alert markdown-alert-tip\">')\n expect(output).toContain('This is a tip callout.')\n })\n\n it('ignores blockquotes without alert syntax', async () => {\n const input = '> This is a regular blockquote.'\n const output = await process(input)\n\n expect(output).not.toContain('markdown-alert')\n expect(output).toContain('<blockquote>')\n expect(output).toContain('This is a regular blockquote.')\n })\n\n it('ignores invalid alert types', async () => {\n const input = '> [!invalid]\\n> This is an invalid alert type.'\n const output = await process(input)\n\n expect(output).not.toContain('markdown-alert')\n expect(output).toContain('<blockquote>')\n expect(output).toContain('[!invalid]')\n expect(output).toContain('This is an invalid alert type.')\n })\n\n it('handles multiline alert content correctly', async () => {\n const input = '> [!note]\\n> First line\\n> Second line\\n> Third line'\n const output = await process(input)\n\n expect(output).toContain('<div class=\"markdown-alert markdown-alert-note\">')\n expect(output).toContain('First line')\n expect(output).toContain('Second line')\n expect(output).toContain('Third line')\n })\n\n it('preserves HTML structure in alert content', async () => {\n const input = '> [!note]\\n> This is a note with **bold** and *italic* text.'\n const output = await process(input)\n\n expect(output).toContain('<div class=\"markdown-alert markdown-alert-note\">')\n expect(output).toContain('<strong>bold</strong>')\n expect(output).toContain('<em>italic</em>')\n })\n})\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,UAAU,QAAQ,UAAU;AACrC,SAAS,eAAe;AACxB,OAAO,iBAAiB;AACxB,OAAO,kBAAkB;AACzB,OAAO,qBAAqB;AAC5B,SAAS,mBAAmB;AAE5B,SAAS,gBAAgB,MAAM;AAC7B,QAAM,UAAU,OAAO,aAAqB;AAC1C,UAAM,OAAO,MAAM,QAAQ,EACxB,IAAI,WAAW,EACf,IAAI,cAAc,EAAE,oBAAoB,KAAK,CAAC,EAC9C,IAAI,WAAW,EACf,IAAI,eAAe,EACnB,QAAQ,QAAQ;AAEnB,WAAO,OAAO,IAAI;AAAA,EACpB;AAEA,KAAG,oCAAoC,YAAY;AACjD,UAAM,QAAQ;AACd,UAAM,SAAS,MAAM,QAAQ,KAAK;AAElC,WAAO,MAAM,EAAE,UAAU,kDAAkD;AAC3E,WAAO,MAAM,EAAE,UAAU,sCAAsC;AAC/D,WAAO,MAAM,EAAE,UAAU,yBAAyB;AAAA,EACpD,CAAC;AAED,KAAG,uCAAuC,YAAY;AACpD,UAAM,QAAQ;AACd,UAAM,SAAS,MAAM,QAAQ,KAAK;AAElC,WAAO,MAAM,EAAE,UAAU,qDAAqD;AAC9E,WAAO,MAAM,EAAE,UAAU,4BAA4B;AAAA,EACvD,CAAC;AAED,KAAG,uCAAuC,YAAY;AACpD,UAAM,QAAQ;AACd,UAAM,SAAS,MAAM,QAAQ,KAAK;AAElC,WAAO,MAAM,EAAE,UAAU,qDAAqD;AAC9E,WAAO,MAAM,EAAE,UAAU,4BAA4B;AAAA,EACvD,CAAC;AAED,KAAG,yCAAyC,YAAY;AACtD,UAAM,QAAQ;AACd,UAAM,SAAS,MAAM,QAAQ,KAAK;AAElC,WAAO,MAAM,EAAE,UAAU,uDAAuD;AAChF,WAAO,MAAM,EAAE,UAAU,+BAA+B;AAAA,EAC1D,CAAC;AAED,KAAG,mCAAmC,YAAY;AAChD,UAAM,QAAQ;AACd,UAAM,SAAS,MAAM,QAAQ,KAAK;AAElC,WAAO,MAAM,EAAE,UAAU,iDAAiD;AAC1E,WAAO,MAAM,EAAE,UAAU,wBAAwB;AAAA,EACnD,CAAC;AAED,KAAG,4CAA4C,YAAY;AACzD,UAAM,QAAQ;AACd,UAAM,SAAS,MAAM,QAAQ,KAAK;AAElC,WAAO,MAAM,EAAE,IAAI,UAAU,gBAAgB;AAC7C,WAAO,MAAM,EAAE,UAAU,cAAc;AACvC,WAAO,MAAM,EAAE,UAAU,+BAA+B;AAAA,EAC1D,CAAC;AAED,KAAG,+BAA+B,YAAY;AAC5C,UAAM,QAAQ;AACd,UAAM,SAAS,MAAM,QAAQ,KAAK;AAElC,WAAO,MAAM,EAAE,IAAI,UAAU,gBAAgB;AAC7C,WAAO,MAAM,EAAE,UAAU,cAAc;AACvC,WAAO,MAAM,EAAE,UAAU,YAAY;AACrC,WAAO,MAAM,EAAE,UAAU,gCAAgC;AAAA,EAC3D,CAAC;AAED,KAAG,6CAA6C,YAAY;AAC1D,UAAM,QAAQ;AACd,UAAM,SAAS,MAAM,QAAQ,KAAK;AAElC,WAAO,MAAM,EAAE,UAAU,kDAAkD;AAC3E,WAAO,MAAM,EAAE,UAAU,YAAY;AACrC,WAAO,MAAM,EAAE,UAAU,aAAa;AACtC,WAAO,MAAM,EAAE,UAAU,YAAY;AAAA,EACvC,CAAC;AAED,KAAG,6CAA6C,YAAY;AAC1D,UAAM,QAAQ;AACd,UAAM,SAAS,MAAM,QAAQ,KAAK;AAElC,WAAO,MAAM,EAAE,UAAU,kDAAkD;AAC3E,WAAO,MAAM,EAAE,UAAU,uBAAuB;AAChD,WAAO,MAAM,EAAE,UAAU,iBAAiB;AAAA,EAC5C,CAAC;AACH,CAAC;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|