@mintlify/common 1.0.412 → 1.0.414
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/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/mdx/plugins/rehype/index.d.ts +1 -1
- package/dist/mdx/plugins/rehype/index.js +1 -1
- package/dist/mdx/plugins/rehype/rehypeCodeBlocks/buildMetaAttributes.d.ts +3 -0
- package/dist/mdx/plugins/rehype/rehypeCodeBlocks/buildMetaAttributes.js +16 -0
- package/dist/mdx/plugins/rehype/{rehypeCodeBlocks.d.ts → rehypeCodeBlocks/index.d.ts} +2 -0
- package/dist/mdx/plugins/rehype/rehypeCodeBlocks/index.js +124 -0
- package/dist/mdx/plugins/rehype/rehypeCodeBlocks/metaOptions.d.ts +123 -0
- package/dist/mdx/plugins/rehype/rehypeCodeBlocks/metaOptions.js +429 -0
- package/dist/mdx/plugins/rehype/rehypeCodeBlocks/parseMetaString.d.ts +20 -0
- package/dist/mdx/plugins/rehype/rehypeCodeBlocks/parseMetaString.js +69 -0
- package/dist/rss/index.d.ts +6 -0
- package/dist/rss/index.js +33 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/rss.d.ts +13 -0
- package/dist/types/rss.js +1 -0
- package/package.json +2 -2
- package/dist/mdx/plugins/rehype/rehypeCodeBlocks.js +0 -59
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export function buildMetaAttributes(meta) {
|
|
2
|
+
const attributes = [];
|
|
3
|
+
for (const [key, value] of Object.entries(meta)) {
|
|
4
|
+
if (typeof value === 'boolean' || typeof value === 'number' || typeof value === 'string') {
|
|
5
|
+
attributes.push({ type: 'mdxJsxAttribute', name: key, value: value.toString() });
|
|
6
|
+
}
|
|
7
|
+
else if (Array.isArray(value)) {
|
|
8
|
+
attributes.push({
|
|
9
|
+
type: 'mdxJsxAttribute',
|
|
10
|
+
name: key,
|
|
11
|
+
value: JSON.stringify(value),
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return attributes;
|
|
16
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { Parent } from 'unist';
|
|
2
|
+
export declare const FOCUS_CLASS_NAME = "line-focus";
|
|
3
|
+
export declare const HIGHLIGHT_CLASS_NAME = "line-highlight";
|
|
2
4
|
declare function addCodeBlocks<T extends Parent>(tree: T): void;
|
|
3
5
|
export declare function rehypeCodeBlocks(): typeof addCodeBlocks;
|
|
4
6
|
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { visit } from 'unist-util-visit';
|
|
2
|
+
import { buildMetaAttributes } from './buildMetaAttributes.js';
|
|
3
|
+
import { parseMetaString } from './parseMetaString.js';
|
|
4
|
+
export const FOCUS_CLASS_NAME = 'line-focus';
|
|
5
|
+
export const HIGHLIGHT_CLASS_NAME = 'line-highlight';
|
|
6
|
+
const exampleNames = ['RequestExample', 'ResponseExample'];
|
|
7
|
+
const flowElementType = 'mdxJsxFlowElement';
|
|
8
|
+
function isElement(node, key = 'type', element = 'element') {
|
|
9
|
+
return node != undefined && node[key] === element;
|
|
10
|
+
}
|
|
11
|
+
function addCodeBlocks(tree) {
|
|
12
|
+
visit(tree, (node, i, parent) => {
|
|
13
|
+
var _a, _b;
|
|
14
|
+
if (parent == null || i == null || !isElement(node) || !isElement(node, 'tagName', 'pre')) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const code = node.children[0];
|
|
18
|
+
if (!isElement(code, 'tagName', 'code'))
|
|
19
|
+
return;
|
|
20
|
+
const isFlowElement = isElement(parent, 'type', flowElementType);
|
|
21
|
+
const parentName = isFlowElement ? parent.name : undefined;
|
|
22
|
+
let properties = code.type === 'element' ? Object.entries(code.properties) : [];
|
|
23
|
+
let meta;
|
|
24
|
+
if (parentName && exampleNames.includes(parentName)) {
|
|
25
|
+
const parentType = parentName.slice(0, -7);
|
|
26
|
+
meta = parseMetaString(parentType);
|
|
27
|
+
if (!((_a = code.data) === null || _a === void 0 ? void 0 : _a.meta)) {
|
|
28
|
+
code.data = Object.assign(Object.assign({}, code.data), { meta: i === 0 ? parentType : `${parentType} ${i + 1}` });
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (((_b = code.data) === null || _b === void 0 ? void 0 : _b.meta) && typeof code.data.meta === 'string') {
|
|
32
|
+
meta = parseMetaString(code.data.meta);
|
|
33
|
+
}
|
|
34
|
+
const attributes = buildMetaAttributes(meta !== null && meta !== void 0 ? meta : {});
|
|
35
|
+
const lineNumber = addLineHighlightAndFocus(code, meta === null || meta === void 0 ? void 0 : meta.highlight, meta === null || meta === void 0 ? void 0 : meta.focus);
|
|
36
|
+
if (lineNumber) {
|
|
37
|
+
properties = properties.filter(([key]) => key !== 'numberOfLines');
|
|
38
|
+
attributes.push({
|
|
39
|
+
type: 'mdxJsxAttribute',
|
|
40
|
+
name: 'numberOfLines',
|
|
41
|
+
value: lineNumber.toString(),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const wrapElement = {
|
|
45
|
+
type: flowElementType,
|
|
46
|
+
name: 'CodeBlock',
|
|
47
|
+
attributes: [
|
|
48
|
+
...attributes,
|
|
49
|
+
...properties
|
|
50
|
+
.filter(([_key, val]) => val != null)
|
|
51
|
+
.map(([key, val]) => ({
|
|
52
|
+
type: 'mdxJsxAttribute',
|
|
53
|
+
name: key,
|
|
54
|
+
value: Array.isArray(val) ? val.join(' ') : val === null || val === void 0 ? void 0 : val.toString(),
|
|
55
|
+
})),
|
|
56
|
+
],
|
|
57
|
+
data: { _mdxExplicitJsx: true },
|
|
58
|
+
children: [],
|
|
59
|
+
};
|
|
60
|
+
wrapElement.children = [node];
|
|
61
|
+
parent.children[i] = wrapElement;
|
|
62
|
+
});
|
|
63
|
+
tree.children = [...tree.children];
|
|
64
|
+
}
|
|
65
|
+
function addLineHighlightAndFocus(codeElement, highlightLines, focusLines) {
|
|
66
|
+
let lineNumber = 0;
|
|
67
|
+
// remove last empty line span if it exists
|
|
68
|
+
const lastChild = codeElement.children[codeElement.children.length - 1];
|
|
69
|
+
if (lastChild &&
|
|
70
|
+
lastChild.type === 'element' &&
|
|
71
|
+
lastChild.tagName === 'span' &&
|
|
72
|
+
lastChild.properties.class &&
|
|
73
|
+
lastChild.children.length === 0) {
|
|
74
|
+
const classValue = lastChild.properties.class;
|
|
75
|
+
const hasLineClass = typeof classValue === 'string'
|
|
76
|
+
? classValue.includes('line')
|
|
77
|
+
: Array.isArray(classValue) && classValue.includes('line');
|
|
78
|
+
if (hasLineClass) {
|
|
79
|
+
codeElement.children.pop();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
visit(codeElement, 'element', (span, _, spanParent) => {
|
|
83
|
+
if (!spanParent ||
|
|
84
|
+
spanParent.type !== 'element' ||
|
|
85
|
+
spanParent.tagName !== 'code' ||
|
|
86
|
+
span.tagName !== 'span' ||
|
|
87
|
+
!span.properties.class) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const classValue = span.properties.class;
|
|
91
|
+
const hasLineClass = typeof classValue === 'string'
|
|
92
|
+
? classValue.includes('line')
|
|
93
|
+
: Array.isArray(classValue) && classValue.includes('line');
|
|
94
|
+
if (!hasLineClass) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
lineNumber++;
|
|
98
|
+
if (highlightLines && highlightLines.length && highlightLines.includes(lineNumber)) {
|
|
99
|
+
addClassToSpan(span, HIGHLIGHT_CLASS_NAME);
|
|
100
|
+
}
|
|
101
|
+
if (focusLines && focusLines.length && focusLines.includes(lineNumber)) {
|
|
102
|
+
addClassToSpan(span, FOCUS_CLASS_NAME);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
if (lineNumber > 0) {
|
|
106
|
+
codeElement.properties.numberOfLines = lineNumber;
|
|
107
|
+
}
|
|
108
|
+
return lineNumber;
|
|
109
|
+
}
|
|
110
|
+
function addClassToSpan(span, className) {
|
|
111
|
+
const currentClass = span.properties.class;
|
|
112
|
+
if (typeof currentClass === 'string') {
|
|
113
|
+
span.properties.class = currentClass + ' ' + className;
|
|
114
|
+
}
|
|
115
|
+
else if (Array.isArray(currentClass)) {
|
|
116
|
+
span.properties.class = [...currentClass, className];
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
span.properties.class = className;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
export function rehypeCodeBlocks() {
|
|
123
|
+
return addCodeBlocks;
|
|
124
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
export type MetaOptionBase = {
|
|
2
|
+
index: number;
|
|
3
|
+
raw: string;
|
|
4
|
+
key: string | undefined;
|
|
5
|
+
valueStartDelimiter: string;
|
|
6
|
+
valueEndDelimiter: string;
|
|
7
|
+
};
|
|
8
|
+
export type MetaOptionString = MetaOptionBase & {
|
|
9
|
+
kind: 'string';
|
|
10
|
+
value: string;
|
|
11
|
+
};
|
|
12
|
+
export type MetaOptionRange = MetaOptionBase & {
|
|
13
|
+
kind: 'range';
|
|
14
|
+
value: string;
|
|
15
|
+
};
|
|
16
|
+
export type MetaOptionRegExp = MetaOptionBase & {
|
|
17
|
+
kind: 'regexp';
|
|
18
|
+
value: RegExp;
|
|
19
|
+
};
|
|
20
|
+
export type MetaOptionBoolean = MetaOptionBase & {
|
|
21
|
+
kind: 'boolean';
|
|
22
|
+
value: boolean;
|
|
23
|
+
};
|
|
24
|
+
export type MetaOption = MetaOptionString | MetaOptionRange | MetaOptionRegExp | MetaOptionBoolean;
|
|
25
|
+
export type MetaOptionKind = MetaOption['kind'];
|
|
26
|
+
export declare class MetaOptions {
|
|
27
|
+
constructor(input: string, reservedKeys?: string[]);
|
|
28
|
+
parsedOptions: MetaOption[];
|
|
29
|
+
errors: string[] | undefined;
|
|
30
|
+
remainingText: string;
|
|
31
|
+
/**
|
|
32
|
+
* A list of error messages that occurred when parsing the meta string,
|
|
33
|
+
* or `undefined` if no errors occurred.
|
|
34
|
+
*/
|
|
35
|
+
get getErrors(): string[] | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Returns the remaining text after all parsed options are removed.
|
|
38
|
+
* This is useful for extracting filename from meta strings.
|
|
39
|
+
*/
|
|
40
|
+
getRemainingText(): string;
|
|
41
|
+
/**
|
|
42
|
+
* Returns a list of meta options, optionally filtered by their key and/or {@link MetaOptionKind}.
|
|
43
|
+
*
|
|
44
|
+
* @param keyOrKeys
|
|
45
|
+
* Allows to filter the options by key. An empty string will return options without a key.
|
|
46
|
+
* A non-empty string will return options with a matching key (case-insensitive).
|
|
47
|
+
* An array of strings will return options with any of the matching keys.
|
|
48
|
+
* If omitted, no key-based filtering will be applied.
|
|
49
|
+
*
|
|
50
|
+
* @param kind
|
|
51
|
+
* Allows to filter the options by {@link MetaOptionKind}.
|
|
52
|
+
* If omitted, no kind-based filtering will be applied.
|
|
53
|
+
*/
|
|
54
|
+
list<K extends MetaOptionKind | undefined = undefined>(keyOrKeys?: string | string[], kind?: K): K extends "string" | "boolean" | "range" | "regexp" ? (Extract<MetaOptionString, {
|
|
55
|
+
kind: K;
|
|
56
|
+
}> | Extract<MetaOptionRange, {
|
|
57
|
+
kind: K;
|
|
58
|
+
}> | Extract<MetaOptionRegExp, {
|
|
59
|
+
kind: K;
|
|
60
|
+
}> | Extract<MetaOptionBoolean, {
|
|
61
|
+
kind: K;
|
|
62
|
+
}>)[] : MetaOption[];
|
|
63
|
+
value<K extends MetaOptionKind | undefined = undefined>(key: string, kind?: K): (K extends "string" | "boolean" | "range" | "regexp" ? Extract<MetaOptionString, {
|
|
64
|
+
kind: K;
|
|
65
|
+
}> | Extract<MetaOptionRange, {
|
|
66
|
+
kind: K;
|
|
67
|
+
}> | Extract<MetaOptionRegExp, {
|
|
68
|
+
kind: K;
|
|
69
|
+
}> | Extract<MetaOptionBoolean, {
|
|
70
|
+
kind: K;
|
|
71
|
+
}> : MetaOption)["value"] | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* Returns the last string value with the given key (case-insensitive),
|
|
74
|
+
* or without a key by passing an empty string.
|
|
75
|
+
*/
|
|
76
|
+
getString(key: string): string | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Returns an array of all string values with the given keys (case-insensitive),
|
|
79
|
+
* or without a key by passing an empty string.
|
|
80
|
+
*/
|
|
81
|
+
getStrings(keyOrKeys?: string | string[]): string[];
|
|
82
|
+
/**
|
|
83
|
+
* Returns the last range value (`{value}`) with the given key (case-insensitive),
|
|
84
|
+
* or without a key by passing an empty string.
|
|
85
|
+
*/
|
|
86
|
+
getRange(key: string): string | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Returns an array of all range values (`{value}`) with the given keys (case-insensitive),
|
|
89
|
+
* or without a key by passing an empty string.
|
|
90
|
+
*/
|
|
91
|
+
getRanges(keyOrKeys?: string | string[]): string[];
|
|
92
|
+
/**
|
|
93
|
+
* Returns the last integer value with the given key (case-insensitive),
|
|
94
|
+
* or without a key by passing an empty string.
|
|
95
|
+
*/
|
|
96
|
+
getInteger(key: string): number | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Returns an array of all integer values with the given keys (case-insensitive),
|
|
99
|
+
* or without a key by passing an empty string.
|
|
100
|
+
*/
|
|
101
|
+
getIntegers(keyOrKeys?: string | string[]): number[];
|
|
102
|
+
getStringsWithInteger(keyOrKeys?: string | string[]): number[];
|
|
103
|
+
/**
|
|
104
|
+
* Returns an array of all integers from range values with the given keys (case-insensitive),
|
|
105
|
+
* parsing ranges like "1,3-5" to return [1,3,4,5].
|
|
106
|
+
* Works with range values (`{value}`) that contain comma-separated integers and ranges.
|
|
107
|
+
*/
|
|
108
|
+
getRangesWithInteger(keyOrKeys?: string | string[]): number[];
|
|
109
|
+
/**
|
|
110
|
+
* Returns the last RegExp value (`/value/`) with the given key (case-insensitive),
|
|
111
|
+
* or without a key by passing an empty string.
|
|
112
|
+
*/
|
|
113
|
+
getRegExp(key: string): RegExp | undefined;
|
|
114
|
+
/**
|
|
115
|
+
* Returns an array of all RegExp values (`/value/`) with the given keys (case-insensitive),
|
|
116
|
+
* or without a key by passing an empty string.
|
|
117
|
+
*/
|
|
118
|
+
getRegExps(keyOrKeys?: string | string[]): RegExp[];
|
|
119
|
+
/**
|
|
120
|
+
* Returns the last boolean value with the given key (case-insensitive).
|
|
121
|
+
*/
|
|
122
|
+
getBoolean(key: string): boolean | undefined;
|
|
123
|
+
}
|