@mintlify/common 1.0.606 → 1.0.607

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.
@@ -1,4 +1,4 @@
1
- import { rehypeCodeBlocks, rehypeDynamicTailwindCss, rehypeMdxExtractEndpoint, rehypeMdxExtractExamples, rehypeParamFieldIds, rehypeRawComponents, rehypeTable, rehypeUnicodeIds, rehypeZoomImages, remarkExtractChangelogFilters, remarkExtractTableOfContents, remarkFrames, remarkComponentIds, remarkMdxInjectSnippets, remarkMdxRemoveUnusedVariables, remarkRemoveImports, remarkMdxExtractPanel, remarkVideo, remarkExtractMultiView, } from './plugins/index.js';
1
+ import { rehypeCodeBlocks, rehypeDynamicTailwindCss, rehypeKeyboardSymbols, rehypeMdxExtractEndpoint, rehypeMdxExtractExamples, rehypeParamFieldIds, rehypeRawComponents, rehypeTable, rehypeUnicodeIds, rehypeZoomImages, remarkExtractChangelogFilters, remarkExtractTableOfContents, remarkFrames, remarkComponentIds, remarkMdxInjectSnippets, remarkMdxRemoveUnusedVariables, remarkRemoveImports, remarkMdxExtractPanel, remarkVideo, remarkExtractMultiView, } from './plugins/index.js';
2
2
  import { remarkMdxRemoveUnknownJsx } from './plugins/remark/remarkMdxRemoveUnknownJsx/index.js';
3
3
  import { remarkMermaid } from './plugins/remark/remarkMermaid.js';
4
4
  // avoid running extractors unnecessarily
@@ -29,6 +29,7 @@ export const getMDXOptions = ({ data, remarkPlugins = [], rehypePlugins = [], md
29
29
  ],
30
30
  rehypePlugins: [
31
31
  rehypeCodeBlocks,
32
+ rehypeKeyboardSymbols,
32
33
  rehypeParamFieldIds,
33
34
  ...rehypeExtractors(mdxExtracts, data),
34
35
  rehypeTable,
@@ -7,3 +7,4 @@ export * from './rehypeTable.js';
7
7
  export * from './rehypeZoomImages.js';
8
8
  export * from './rehypeUnicodeIds.js';
9
9
  export * from './rehypeDynamicTailwindCss.js';
10
+ export * from './rehypeKeyboardSymbols.js';
@@ -7,3 +7,4 @@ export * from './rehypeTable.js';
7
7
  export * from './rehypeZoomImages.js';
8
8
  export * from './rehypeUnicodeIds.js';
9
9
  export * from './rehypeDynamicTailwindCss.js';
10
+ export * from './rehypeKeyboardSymbols.js';
@@ -0,0 +1,2 @@
1
+ import type { Root } from 'hast';
2
+ export declare const rehypeKeyboardSymbols: () => (tree: Root) => void;
@@ -0,0 +1,78 @@
1
+ import { visit } from 'unist-util-visit';
2
+ const KEYBOARD_SYMBOL_RANGES = [
3
+ [0x2318, 0x2319], // ⌘⌙ (Command/Apple key)
4
+ [0x2325, 0x2326], // ⌥⌦ (Option/Alt key)
5
+ [0x2303, 0x2303], // ⌃ (Control key)
6
+ [0x21e7, 0x21e7], // ⇧ (Shift key)
7
+ [0x232b, 0x232c], // ⌫⌬ (Backspace/Delete keys)
8
+ [0x21a9, 0x21a9], // ↩ (Return key)
9
+ [0x21b5, 0x21b5], // ↵ (Enter key)
10
+ [0x2380, 0x2380], // ⌀ (Null key)
11
+ [0x2387, 0x238a], // ⌧⌨〈〉 (Clear, Keyboard, Left/Right angle brackets)
12
+ [0x21e4, 0x21e5], // ⇤⇥ (Tab keys)
13
+ ];
14
+ const isKeyboardSymbol = (char) => {
15
+ const code = char.codePointAt(0);
16
+ if (code === undefined)
17
+ return false;
18
+ return KEYBOARD_SYMBOL_RANGES.some((range) => {
19
+ const [start, end] = range;
20
+ return start !== undefined && end !== undefined && code >= start && code <= end;
21
+ });
22
+ };
23
+ const containsKeyboardSymbols = (text) => {
24
+ const trimmed = text.trim();
25
+ if (trimmed.length === 0)
26
+ return false;
27
+ for (const char of trimmed) {
28
+ if (isKeyboardSymbol(char)) {
29
+ return true;
30
+ }
31
+ }
32
+ return false;
33
+ };
34
+ const extractTextFromChildren = (children) => {
35
+ let text = '';
36
+ for (const child of children) {
37
+ if (child && typeof child === 'object' && 'type' in child) {
38
+ if (child.type === 'text' && 'value' in child) {
39
+ text += child.value;
40
+ }
41
+ else if (child.type === 'element' || child.type === 'mdxJsxTextElement') {
42
+ if ('children' in child && Array.isArray(child.children)) {
43
+ text += extractTextFromChildren(child.children);
44
+ }
45
+ }
46
+ }
47
+ }
48
+ return text;
49
+ };
50
+ export const rehypeKeyboardSymbols = () => (tree) => {
51
+ visit(tree, 'element', (node, _, parent) => {
52
+ if (node.tagName !== 'code')
53
+ return;
54
+ if (parent && parent.type === 'element' && parent.tagName === 'pre')
55
+ return;
56
+ const text = extractTextFromChildren(node.children);
57
+ if (containsKeyboardSymbols(text)) {
58
+ node.properties['data-symbols'] = 'true';
59
+ }
60
+ });
61
+ visit(tree, 'mdxJsxTextElement', (node, _, parent) => {
62
+ if (node.name !== 'code')
63
+ return;
64
+ if (parent && parent.type === 'element' && parent.tagName === 'pre')
65
+ return;
66
+ const text = extractTextFromChildren(node.children);
67
+ if (containsKeyboardSymbols(text)) {
68
+ const existingAttr = node.attributes.find((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'data-symbols');
69
+ if (!existingAttr) {
70
+ node.attributes.push({
71
+ type: 'mdxJsxAttribute',
72
+ name: 'data-symbols',
73
+ value: 'true',
74
+ });
75
+ }
76
+ }
77
+ });
78
+ };