@vxrn/mdx 1.2.78 → 1.2.79

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vxrn/mdx",
3
- "version": "1.2.78",
3
+ "version": "1.2.79",
4
4
  "type": "commonjs",
5
5
  "exports": {
6
6
  "./package.json": "./package.json",
@@ -55,6 +55,7 @@
55
55
  "rehype-parse": "^8.0.4",
56
56
  "rehype-slug": "^5.0.1",
57
57
  "remark-gfm": "^4.0.1",
58
+ "remark-smartypants": "^3.0.2",
58
59
  "shiki": "1.3.0",
59
60
  "unified": "^10.1.2",
60
61
  "unist-util-visit": "^2.0.3"
package/src/getMDX.ts CHANGED
@@ -7,6 +7,7 @@ import { getHeadings } from './getHeadings'
7
7
  import { processImageMeta } from './processImageMeta'
8
8
  import { rehypeHighlightCode } from './rehypeHighlightCode'
9
9
  import rehypeMetaAttribute from './rehypeMetaAttribute'
10
+ import { remarkSmartypantsFixed } from './remarkSmartypantsFixed'
10
11
  import type { Frontmatter, ImageMeta, UnifiedPlugin } from './types'
11
12
 
12
13
  export type GetMDXOptions = {
@@ -27,7 +28,11 @@ export async function getMDX(
27
28
  const { frontmatter, code } = await bundleMDX({
28
29
  source,
29
30
  mdxOptions(options) {
30
- options.remarkPlugins = [...(options.remarkPlugins ?? []), remarkGfm]
31
+ options.remarkPlugins = [
32
+ ...(options.remarkPlugins ?? []),
33
+ remarkGfm,
34
+ remarkSmartypantsFixed,
35
+ ]
31
36
  const plugins = [
32
37
  ...(opts.extraPlugins || []),
33
38
  ...(options.rehypePlugins ?? []),
package/src/index.ts CHANGED
@@ -3,6 +3,7 @@ export { getMDX, type GetMDXOptions } from './getMDX'
3
3
  export { getAllVersionsFromPath, getMDXBySlug } from './getMDXBySlug'
4
4
  export { createCodeHighlighter } from './highlightCode'
5
5
  export { rehypeHeroTemplate } from './rehypeHeroTemplate'
6
+ export { remarkSmartypantsFixed } from './remarkSmartypantsFixed'
6
7
  export { notifyFileRead } from './watchFile'
7
8
  export type { Frontmatter, ImageMeta, UnifiedPlugin } from './types'
8
9
  export type { RehypeHeroTemplateOptions } from './rehypeHeroTemplate'
@@ -0,0 +1,39 @@
1
+ import remarkSmartypants from 'remark-smartypants'
2
+
3
+ import type { Root, Code, InlineCode, Parent } from 'mdast'
4
+
5
+ // remark-smartypants incorrectly processes text inside code blocks and inline code
6
+ // this wrapper preserves code content and restores it after smartypants runs
7
+
8
+ type Options = Parameters<typeof remarkSmartypants>[0]
9
+
10
+ export function remarkSmartypantsFixed(options?: Options) {
11
+ // @ts-expect-error unified plugin type complexities
12
+ const smartypantsTransformer = remarkSmartypants(options) as (tree: Root) => void
13
+
14
+ return (tree: Root) => {
15
+ const codeBlocks = new Map<Code | InlineCode, string>()
16
+
17
+ // save all code content before smartypants
18
+ function collectCode(node: Root | Parent | Code | InlineCode) {
19
+ if (node.type === 'code' || node.type === 'inlineCode') {
20
+ codeBlocks.set(node as Code | InlineCode, (node as Code | InlineCode).value)
21
+ }
22
+ if ('children' in node && Array.isArray(node.children)) {
23
+ for (const child of node.children) {
24
+ collectCode(child as Parent | Code | InlineCode)
25
+ }
26
+ }
27
+ }
28
+
29
+ collectCode(tree)
30
+
31
+ // run smartypants
32
+ smartypantsTransformer(tree)
33
+
34
+ // restore code content
35
+ for (const [node, originalValue] of codeBlocks) {
36
+ node.value = originalValue
37
+ }
38
+ }
39
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"getMDX.d.ts","sourceRoot":"","sources":["../src/getMDX.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,WAAW,EAAa,aAAa,EAAE,MAAM,SAAS,CAAA;AAEpE,MAAM,MAAM,aAAa,GAAG;IAC1B,YAAY,CAAC,EAAE,aAAa,CAAA;IAC5B,qFAAqF;IACrF,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,wBAAsB,MAAM,CAC1B,MAAM,EAAE,MAAM,EACd,qBAAqB,CAAC,EAAE,aAAa,GAAG,aAAa;iBAuC9C,WAAW;;GAGnB"}
1
+ {"version":3,"file":"getMDX.d.ts","sourceRoot":"","sources":["../src/getMDX.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,WAAW,EAAa,aAAa,EAAE,MAAM,SAAS,CAAA;AAEpE,MAAM,MAAM,aAAa,GAAG;IAC1B,YAAY,CAAC,EAAE,aAAa,CAAA;IAC5B,qFAAqF;IACrF,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,wBAAsB,MAAM,CAC1B,MAAM,EAAE,MAAM,EACd,qBAAqB,CAAC,EAAE,aAAa,GAAG,aAAa;iBA2C9C,WAAW;;GAGnB"}
package/types/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export { getMDX, type GetMDXOptions } from './getMDX';
3
3
  export { getAllVersionsFromPath, getMDXBySlug } from './getMDXBySlug';
4
4
  export { createCodeHighlighter } from './highlightCode';
5
5
  export { rehypeHeroTemplate } from './rehypeHeroTemplate';
6
+ export { remarkSmartypantsFixed } from './remarkSmartypantsFixed';
6
7
  export { notifyFileRead } from './watchFile';
7
8
  export type { Frontmatter, ImageMeta, UnifiedPlugin } from './types';
8
9
  export type { RehypeHeroTemplateOptions } from './rehypeHeroTemplate';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAA;AACrD,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5C,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACpE,YAAY,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AACvD,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,UAAU,CAAA;AACrD,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AACrE,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAC5C,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACpE,YAAY,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAA"}
@@ -0,0 +1,6 @@
1
+ import remarkSmartypants from 'remark-smartypants';
2
+ import type { Root } from 'mdast';
3
+ type Options = Parameters<typeof remarkSmartypants>[0];
4
+ export declare function remarkSmartypantsFixed(options?: Options): (tree: Root) => void;
5
+ export {};
6
+ //# sourceMappingURL=remarkSmartypantsFixed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remarkSmartypantsFixed.d.ts","sourceRoot":"","sources":["../src/remarkSmartypantsFixed.ts"],"names":[],"mappings":"AAAA,OAAO,iBAAiB,MAAM,oBAAoB,CAAA;AAElD,OAAO,KAAK,EAAE,IAAI,EAA4B,MAAM,OAAO,CAAA;AAK3D,KAAK,OAAO,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAA;AAEtD,wBAAgB,sBAAsB,CAAC,OAAO,CAAC,EAAE,OAAO,IAI9C,MAAM,IAAI,UAyBnB"}