@mintlify/common 1.0.1272 → 1.0.1273

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.
@@ -0,0 +1,9 @@
1
+ import type { Root, RootContent } from 'mdast';
2
+ import type { VFile } from 'vfile';
3
+ type InlineMath = Extract<RootContent, {
4
+ type: 'inlineMath';
5
+ }>;
6
+ export declare const isCurrencyMath: (node: InlineMath, text: string) => boolean;
7
+ export declare const unwrapCurrencyMath: (root: Root, text: string) => void;
8
+ export declare const remarkCurrencyText: () => (tree: Root, file: VFile) => void;
9
+ export {};
@@ -0,0 +1,18 @@
1
+ import { SKIP, visit } from 'unist-util-visit';
2
+ export const isCurrencyMath = (node, text) => {
3
+ var _a, _b, _c;
4
+ const start = (_a = node.position) === null || _a === void 0 ? void 0 : _a.start.offset;
5
+ const end = (_b = node.position) === null || _b === void 0 ? void 0 : _b.end.offset;
6
+ if (start === undefined || end === undefined)
7
+ return false;
8
+ return !text.startsWith('$$', start) && /^\d/.test(node.value) && /\d/.test((_c = text[end]) !== null && _c !== void 0 ? _c : '');
9
+ };
10
+ export const unwrapCurrencyMath = (root, text) => {
11
+ visit(root, 'inlineMath', (node, index, parent) => {
12
+ if (!parent || index === undefined || !isCurrencyMath(node, text))
13
+ return;
14
+ parent.children.splice(index, 1, { type: 'text', value: `$${node.value}$` });
15
+ return [SKIP, index];
16
+ });
17
+ };
18
+ export const remarkCurrencyText = () => (tree, file) => unwrapCurrencyMath(tree, String(file.value));
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,36 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { remark } from 'remark';
11
+ import remarkMath from 'remark-math';
12
+ import remarkMdx from 'remark-mdx';
13
+ import { visit } from 'unist-util-visit';
14
+ import { describe, expect, it } from 'vitest';
15
+ import { remarkCurrencyText } from './currencyMath.js';
16
+ const inlineMath = (source) => __awaiter(void 0, void 0, void 0, function* () {
17
+ const processor = remark().use(remarkMdx).use(remarkMath).use(remarkCurrencyText);
18
+ const tree = (yield processor.run(processor.parse(source), source));
19
+ const values = [];
20
+ visit(tree, 'inlineMath', (node) => {
21
+ values.push(node.value);
22
+ });
23
+ return values;
24
+ });
25
+ describe('remarkCurrencyText', () => {
26
+ it('turns paired prices into text', () => __awaiter(void 0, void 0, void 0, function* () {
27
+ expect(yield inlineMath('Savings are $1 today ($5 tomorrow).')).toEqual([]);
28
+ }));
29
+ it.each([
30
+ ['single-dollar math', 'The formula is $x$ in text', ['x']],
31
+ ['math that starts with a digit', 'Use $2x$ here.', ['2x']],
32
+ ['double-dollar math followed by a digit', 'The value is $$2^3$$8.', ['2^3']],
33
+ ])('keeps %s', (_label, source, expected) => __awaiter(void 0, void 0, void 0, function* () {
34
+ expect(yield inlineMath(source)).toEqual(expected);
35
+ }));
36
+ });
@@ -1,3 +1,4 @@
1
+ import { remarkCurrencyText } from './currencyMath.js';
1
2
  import { remarkPackageIslands, } from './islands/remarkPackageIslands.js';
2
3
  import { rehypeCodeBlocks, rehypeDynamicTailwindCss, rehypeKeyboardSymbols, rehypeListItemText, rehypeMdxExtractEndpoint, rehypeMdxExtractExamples, rehypeParamFieldIds, rehypeRawComponents, rehypeTable, rehypeUnicodeIds, rehypeZoomImages, remarkExtractChangelogFilters, remarkExtractTableOfContents, remarkFileTree, remarkFrames, remarkComponentIds, remarkMdxInjectSnippets, remarkMdxStyleStringToObject, remarkMdxRemoveUnusedVariables, remarkRemoveImports, remarkMdxExtractPanel, remarkResolveRelativeLinks, remarkVideo, remarkMdxClientComponentBoundaries, remarkExtractMultiView, remarkPrompt, remarkUnwrapInlineJsx, remarkUnwrapJsxHeadings, remarkMapExplicitAnchors, } from './plugins/index.js';
3
4
  import { remarkMdxExpandExpressions, } from './plugins/remark/remarkMdxExpandExpressions.js';
@@ -27,6 +28,7 @@ export const getMDXOptions = ({ data, remarkPlugins = [], earlyRemarkPlugins = [
27
28
  remarkPlugins: [
28
29
  // first, so `<Snippet file>` is injected on the page and inside every `<MDX>` fragment
29
30
  [remarkMdxInjectSnippets, data.snippetTreeMap],
31
+ remarkCurrencyText,
30
32
  ...(fragment || !packageIslands
31
33
  ? []
32
34
  : [
@@ -6,6 +6,7 @@ export * from './plugins/index.js';
6
6
  export * from './lib/index.js';
7
7
  export * from './preprocessCustomHeadingIds.js';
8
8
  export * from './preprocessMdxFragmentCode.js';
9
+ export * from './currencyMath.js';
9
10
  export * from './getMDXOptions.js';
10
11
  export * from './astUtils.js';
11
12
  export * from './getS3ImageUri.js';
package/dist/mdx/index.js CHANGED
@@ -6,6 +6,7 @@ export * from './plugins/index.js';
6
6
  export * from './lib/index.js';
7
7
  export * from './preprocessCustomHeadingIds.js';
8
8
  export * from './preprocessMdxFragmentCode.js';
9
+ export * from './currencyMath.js';
9
10
  export * from './getMDXOptions.js';
10
11
  export * from './astUtils.js';
11
12
  export * from './getS3ImageUri.js';