@mintlify/common 1.0.1304 → 1.0.1306
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/dist/frontmatter/index.d.ts +1 -1
- package/dist/frontmatter/index.js +1 -1
- package/dist/frontmatter/parseFrontmatter.d.ts +1 -0
- package/dist/frontmatter/parseFrontmatter.js +1 -0
- package/dist/mdx/getCodeRanges.d.ts +1 -0
- package/dist/mdx/getCodeRanges.js +22 -0
- package/dist/mdx/getCodeRanges.test.d.ts +1 -0
- package/dist/mdx/getCodeRanges.test.js +119 -0
- package/dist/mdx/index.d.ts +1 -0
- package/dist/mdx/index.js +1 -0
- package/dist/mdx/preprocessCustomHeadingIds.d.ts +1 -0
- package/dist/mdx/preprocessCustomHeadingIds.js +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +5 -2
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { parseFrontmatter, hasFrontmatter } from './parseFrontmatter.js';
|
|
1
|
+
export { FRONTMATTER_RE, parseFrontmatter, hasFrontmatter } from './parseFrontmatter.js';
|
|
2
2
|
export type { FrontmatterAttributes } from './parseFrontmatter.js';
|
|
3
3
|
export type { FrontMatterResult } from 'front-matter';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { parseFrontmatter, hasFrontmatter } from './parseFrontmatter.js';
|
|
1
|
+
export { FRONTMATTER_RE, parseFrontmatter, hasFrontmatter } from './parseFrontmatter.js';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fm from 'front-matter';
|
|
2
2
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
3
3
|
const frontmatter = fm;
|
|
4
|
+
export const FRONTMATTER_RE = /^?(---|\+\+\+)\r?\n[\s\S]*?\r?\n\1[ \t]*(?=\r?\n|$)/;
|
|
4
5
|
/**
|
|
5
6
|
* Type-safe wrapper for parsing front-matter from markdown content.
|
|
6
7
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getCodeRanges: (content: string) => [start: number, end: number][];
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { parse, postprocess, preprocess } from 'micromark';
|
|
2
|
+
import { frontmatter } from 'micromark-extension-frontmatter';
|
|
3
|
+
import { gfmTable } from 'micromark-extension-gfm-table';
|
|
4
|
+
const CODE_TYPES = new Set(['codeFenced', 'codeText', 'yaml', 'toml']);
|
|
5
|
+
const extensions = [
|
|
6
|
+
frontmatter(['yaml', 'toml']),
|
|
7
|
+
gfmTable(),
|
|
8
|
+
{ disable: { null: ['autolink', 'codeIndented', 'htmlFlow', 'htmlText'] } },
|
|
9
|
+
];
|
|
10
|
+
export const getCodeRanges = (content) => {
|
|
11
|
+
const bom = content.startsWith('') ? 1 : 0;
|
|
12
|
+
const events = postprocess(parse({ extensions })
|
|
13
|
+
.document()
|
|
14
|
+
.write(preprocess()(content.slice(bom), undefined, true)));
|
|
15
|
+
const ranges = [];
|
|
16
|
+
for (const [kind, token] of events) {
|
|
17
|
+
if (kind === 'enter' && CODE_TYPES.has(token.type)) {
|
|
18
|
+
ranges.push([token.start.offset + bom, token.end.offset + bom]);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return ranges;
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { getCodeRanges } from './getCodeRanges.js';
|
|
3
|
+
const slices = (content) => getCodeRanges(content).map(([start, end]) => content.slice(start, end));
|
|
4
|
+
describe('getCodeRanges', () => {
|
|
5
|
+
it('returns nothing for an empty page', () => {
|
|
6
|
+
expect(getCodeRanges('')).toEqual([]);
|
|
7
|
+
});
|
|
8
|
+
it('covers a fence including its fence lines', () => {
|
|
9
|
+
const content = 'Intro\n\n```js\nconst a = <br>;\n```\n\nOutro';
|
|
10
|
+
expect(getCodeRanges(content)).toEqual([[7, 32]]);
|
|
11
|
+
expect(slices(content)).toEqual(['```js\nconst a = <br>;\n```']);
|
|
12
|
+
});
|
|
13
|
+
it('covers a fence inside a blockquote', () => {
|
|
14
|
+
expect(slices('> Quote\n>\n> ```js\n> x\n> ```\n\nAfter')).toEqual(['```js\n> x\n> ```']);
|
|
15
|
+
});
|
|
16
|
+
it('does not close a fence on a line with an info string', () => {
|
|
17
|
+
expect(slices('```\na\n```js\nb\n```\nc')).toEqual(['```\na\n```js\nb\n```']);
|
|
18
|
+
});
|
|
19
|
+
it('runs an unclosed fence to the end of the file', () => {
|
|
20
|
+
expect(slices('Text\n\n```bash\necho hi\n\n<br>\n')).toEqual(['```bash\necho hi\n\n<br>\n']);
|
|
21
|
+
});
|
|
22
|
+
it('pairs inline code within a block but not across blank lines', () => {
|
|
23
|
+
expect(slices('Use `a` and ``b ` c``.')).toEqual(['`a`', '``b ` c``']);
|
|
24
|
+
expect(slices('Open `tick\n\nclose` here')).toEqual([]);
|
|
25
|
+
});
|
|
26
|
+
it('covers YAML frontmatter', () => {
|
|
27
|
+
expect(slices('---\ntitle: `x`\n---\n\nBody `y`')).toEqual(['---\ntitle: `x`\n---', '`y`']);
|
|
28
|
+
});
|
|
29
|
+
it('covers TOML frontmatter', () => {
|
|
30
|
+
expect(slices('+++\ntitle = "x"\n+++\n\nBody')).toEqual(['+++\ntitle = "x"\n+++']);
|
|
31
|
+
});
|
|
32
|
+
it('keeps offsets exact after a byte order mark', () => {
|
|
33
|
+
expect(slices('---\na: 1\n---\n\n`b`')).toEqual(['---\na: 1\n---', '`b`']);
|
|
34
|
+
});
|
|
35
|
+
it('does not treat indented lines inside JSX as code', () => {
|
|
36
|
+
expect(slices('<Card>\n <br>\n Text `x`\n</Card>')).toEqual(['`x`']);
|
|
37
|
+
});
|
|
38
|
+
it('finds fences indented inside JSX', () => {
|
|
39
|
+
expect(slices('<Tab>\n ```js\n x\n ```\n</Tab>')).toEqual(['```js\n x\n ```']);
|
|
40
|
+
});
|
|
41
|
+
it('finds code on pages with broken JSX', () => {
|
|
42
|
+
const content = '<Card title="a">\n\nLine<br>\n\n```html\n<br>\n```\n\nSee `<br>`.\n';
|
|
43
|
+
expect(slices(content)).toEqual(['```html\n<br>\n```', '`<br>`']);
|
|
44
|
+
});
|
|
45
|
+
it('matches the mdast positions on a mixed page', () => {
|
|
46
|
+
const content = [
|
|
47
|
+
'---',
|
|
48
|
+
'title: `Page`',
|
|
49
|
+
'---',
|
|
50
|
+
'',
|
|
51
|
+
'Intro with `inline` and ``double ` tick`` code.',
|
|
52
|
+
'',
|
|
53
|
+
'<Card title="a">',
|
|
54
|
+
'',
|
|
55
|
+
'Line<br>',
|
|
56
|
+
'',
|
|
57
|
+
'```js title="x.js"',
|
|
58
|
+
'const a = <br>;',
|
|
59
|
+
'```',
|
|
60
|
+
'',
|
|
61
|
+
'> Quote',
|
|
62
|
+
'> ```bash',
|
|
63
|
+
'> echo `x`',
|
|
64
|
+
'> ```',
|
|
65
|
+
'',
|
|
66
|
+
'- Item `one`',
|
|
67
|
+
'',
|
|
68
|
+
' ```py',
|
|
69
|
+
' print(1)',
|
|
70
|
+
' ```',
|
|
71
|
+
'',
|
|
72
|
+
'<Tab>',
|
|
73
|
+
' indented `two`',
|
|
74
|
+
'</Tab>',
|
|
75
|
+
'',
|
|
76
|
+
'Open `tick',
|
|
77
|
+
'',
|
|
78
|
+
'close` here',
|
|
79
|
+
'',
|
|
80
|
+
'~~~',
|
|
81
|
+
'tilde',
|
|
82
|
+
'~~~',
|
|
83
|
+
'',
|
|
84
|
+
'```',
|
|
85
|
+
'unclosed',
|
|
86
|
+
'',
|
|
87
|
+
].join('\n');
|
|
88
|
+
expect(getCodeRanges(content)).toEqual([
|
|
89
|
+
[0, 21],
|
|
90
|
+
[34, 42],
|
|
91
|
+
[47, 64],
|
|
92
|
+
[100, 138],
|
|
93
|
+
[150, 174],
|
|
94
|
+
[183, 188],
|
|
95
|
+
[194, 220],
|
|
96
|
+
[241, 246],
|
|
97
|
+
[280, 293],
|
|
98
|
+
[295, 308],
|
|
99
|
+
]);
|
|
100
|
+
expect(getCodeRanges('+++\na = 1\n+++\n\n`b`')).toEqual([
|
|
101
|
+
[0, 13],
|
|
102
|
+
[15, 18],
|
|
103
|
+
]);
|
|
104
|
+
});
|
|
105
|
+
it('does not pair backticks across table cells', () => {
|
|
106
|
+
expect(slices('| A | B |\n| - | - |\n| `open | <br> close` |')).toEqual([]);
|
|
107
|
+
});
|
|
108
|
+
it('covers inline code inside table cells', () => {
|
|
109
|
+
const content = '| A | B |\n| - | - |\n| `x` | y `<br>` |';
|
|
110
|
+
expect(getCodeRanges(content)).toEqual([
|
|
111
|
+
[22, 25],
|
|
112
|
+
[30, 36],
|
|
113
|
+
]);
|
|
114
|
+
expect(slices(`${content}`)).toEqual(['`x`', '`<br>`']);
|
|
115
|
+
});
|
|
116
|
+
it('ignores HTML and autolink syntax like MDX does', () => {
|
|
117
|
+
expect(slices('<div>\n\n`a`\n\n</div>\n\n<https://x.com/`b`>')).toEqual(['`a`', '`b`']);
|
|
118
|
+
});
|
|
119
|
+
});
|
package/dist/mdx/index.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export * from './page-style.js';
|
|
|
12
12
|
export * from './astUtils.js';
|
|
13
13
|
export * from './getS3ImageUri.js';
|
|
14
14
|
export * from './getCodeStyling.js';
|
|
15
|
+
export * from './getCodeRanges.js';
|
|
15
16
|
export * from './replaceVariables.js';
|
|
16
17
|
export * from './componentIds.js';
|
|
17
18
|
export * from './islands/index.js';
|
package/dist/mdx/index.js
CHANGED
|
@@ -12,6 +12,7 @@ export * from './page-style.js';
|
|
|
12
12
|
export * from './astUtils.js';
|
|
13
13
|
export * from './getS3ImageUri.js';
|
|
14
14
|
export * from './getCodeStyling.js';
|
|
15
|
+
export * from './getCodeRanges.js';
|
|
15
16
|
export * from './replaceVariables.js';
|
|
16
17
|
export * from './componentIds.js';
|
|
17
18
|
export * from './islands/index.js';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { RootContent } from 'mdast';
|
|
2
2
|
import { MdxJsxFlowElement } from 'mdast-util-mdx-jsx';
|
|
3
|
+
export declare const HEADING_ID_RE: RegExp;
|
|
3
4
|
export interface PreprocessCustomHeadingIdsOptions {
|
|
4
5
|
/**
|
|
5
6
|
* When true, preserves the original ID as-is (only removing characters unsafe
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const HEADING_ID_RE = /^( {0,3})(#{1,6})\s+(.+?)\s*\{\s*#([^}]+?)\s*\}\s*$/;
|
|
1
|
+
export const HEADING_ID_RE = /^( {0,3})(#{1,6})\s+(.+?)\s*\{\s*#([^}]+?)\s*\}\s*$/;
|
|
2
2
|
/**
|
|
3
3
|
* Inside an `<MDX>` block the body is dedented before it is parsed, so indentation carries no
|
|
4
4
|
* meaning there (4+ spaces is not an indented code block) and any indent may precede the heading.
|