@clidey/dory 0.12.0 → 0.13.0

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@clidey/dory",
3
3
  "private": false,
4
- "version": "0.12.0",
4
+ "version": "0.13.0",
5
5
  "type": "module",
6
6
  "description": "A CLI tool for building and previewing documentation sites",
7
7
  "keywords": [
@@ -1,10 +1,10 @@
1
1
  import { visit } from 'unist-util-visit';
2
2
 
3
+ // This plugin replaces mdxTextExpression nodes with inlineCode for safety.
3
4
  export const remarkSafeVars = () => {
4
5
  return (tree: any) => {
5
6
  visit(tree, 'mdxTextExpression', (node: any, index: number | undefined, parent: any) => {
6
7
  if (parent && typeof index === 'number') {
7
- // Replace mdxTextExpression with inlineCode node for code formatting
8
8
  parent.children[index] = {
9
9
  type: 'inlineCode',
10
10
  value: node.value
@@ -33,6 +33,16 @@ const KNOWN_COMPONENTS = [
33
33
  'address', 'cite', 'q', 'dfn'
34
34
  ];
35
35
 
36
+ // Helper: returns true if the given code string is inside a code block (```)
37
+ function isInsideCodeBlock(code: string, idx: number): boolean {
38
+ // Count the number of ``` before idx
39
+ const before = code.slice(0, idx);
40
+ const codeBlockMatches = before.match(/```/g);
41
+ // Odd number of ``` means inside a code block
42
+ return codeBlockMatches ? codeBlockMatches.length % 2 === 1 : false;
43
+ }
44
+
45
+ // Allow <service> and any <[a-z][a-z0-9]*> tag inside code blocks to be left as-is (not parsed as JSX).
36
46
  export function preprocessMdxTags() {
37
47
  return {
38
48
  name: 'preprocess-mdx-tags',
@@ -43,10 +53,23 @@ export function preprocessMdxTags() {
43
53
  // Remove leading whitespace from code fence blocks
44
54
  let processed = code.replace(/^(\s+)(```\w*)/gm, '$2');
45
55
 
46
- // Replace unrecognized <someTag> with `"<someTag>"`
47
- processed = processed.replace(/<([a-z][a-z0-9]+)>/gi, (match, tag) => {
48
- const known = KNOWN_COMPONENTS.includes(tag);
49
- return known ? match : `\`<${tag}>\``; // wrap in backticks to keep as code
56
+ // Only replace unrecognized <someTag> with `"<someTag>"` if NOT inside a code block
57
+ // This regex finds all <tag> occurrences
58
+ processed = processed.replace(/<([a-z][a-z0-9]*)>/gi, (match, tag, offset) => {
59
+ // If inside a code block, do not touch
60
+ if (isInsideCodeBlock(processed, offset)) {
61
+ return match;
62
+ }
63
+ // If known component, leave as-is
64
+ if (KNOWN_COMPONENTS.includes(tag)) {
65
+ return match;
66
+ }
67
+ // If tag is 'service', always leave as-is (do not wrap in backticks)
68
+ if (tag === 'service') {
69
+ return match;
70
+ }
71
+ // Otherwise, wrap in backticks to prevent JSX parsing
72
+ return `\`<${tag}>\``;
50
73
  });
51
74
 
52
75
  return {