@markdy/cli 1.4.2 → 1.4.3

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.
Files changed (3) hide show
  1. package/README.md +17 -0
  2. package/dist/index.js +20 -29
  3. package/package.json +7 -5
package/README.md CHANGED
@@ -55,9 +55,26 @@ markdy explain scene.markdy # display AST structure and stats
55
55
  markdy new demo.markdy # scaffold fresh starter scene
56
56
  markdy docs # display docs and tutorial links
57
57
  markdy ai # generate prompt context for LLMs
58
+ markdy check docs/ # validate diagrams in Markdown, MDX, and .markdy files
59
+ markdy check docs/ --json # machine-readable validation report
60
+ markdy check --dist dist/ # validate diagrams embedded in built HTML
58
61
  markdy check-all . --arch-rules # batch lint entire workspace
59
62
  ```
60
63
 
64
+ ## Validate Documentation
65
+
66
+ Run `markdy check docs/` to validate embedded diagrams alongside standalone `.markdy` files.
67
+ Markdown fences accept the `markdy` and `markdyscript` language names, backticks or tildes,
68
+ and optional metadata. Fences inside lists and blockquotes are supported. As in Markdown,
69
+ an unclosed fence continues to the end of its container or document.
70
+
71
+ Live MDX `<Markdy>` and `<MarkdyDiagram>` components with literal `code` values are also
72
+ checked. Fences and components quoted inside other code blocks, plus inline code examples,
73
+ are ignored. Diagnostics point to the original document's line numbers.
74
+
75
+ Use `--strict` to treat warnings as failures, `--arch-rules` for architecture governance,
76
+ or `--json` for structured CI output. Validation errors return a nonzero exit code.
77
+
61
78
  ## Notes
62
79
 
63
80
  - The CLI resolves `import "file.markdy" as ns` from disk before parsing.
package/dist/index.js CHANGED
@@ -32,6 +32,8 @@ import { fileURLToPath, pathToFileURL } from "url";
32
32
  import { createServer } from "http";
33
33
  import { readdir, readFile, stat, writeFile } from "fs/promises";
34
34
  import { spawn } from "child_process";
35
+ import { fromMarkdown } from "mdast-util-from-markdown";
36
+ import { visit } from "unist-util-visit";
35
37
 
36
38
  // src/format.ts
37
39
  import { formatScene } from "@markdy/core";
@@ -659,41 +661,30 @@ async function checkAllCommand(parsed, io) {
659
661
  }
660
662
  function extractDiagramsFromMarkdown(content) {
661
663
  const diagrams = [];
662
- const lines = content.replace(/\r\n/g, "\n").split("\n");
663
- let inFence = false;
664
- let fenceStartLine = 0;
665
- let fenceBuffer = [];
666
- for (let idx = 0; idx < lines.length; idx++) {
667
- const line = lines[idx];
668
- const lineNo = idx + 1;
669
- const trimmed = line.trim();
670
- if (!inFence) {
671
- const match = trimmed.match(/^```+(markdy|markdyscript)\b/i);
672
- if (match) {
673
- inFence = true;
674
- fenceStartLine = lineNo + 1;
675
- fenceBuffer = [];
676
- continue;
677
- }
678
- } else {
679
- if (/^```+\s*$/.test(trimmed)) {
680
- inFence = false;
681
- diagrams.push({
682
- code: fenceBuffer.join("\n"),
683
- line: fenceStartLine,
684
- kind: "fence"
685
- });
686
- fenceBuffer = [];
687
- continue;
688
- }
689
- fenceBuffer.push(line);
664
+ const codeRanges = [];
665
+ const tree = fromMarkdown(content);
666
+ visit(tree, (node) => {
667
+ if (node.type !== "code" && node.type !== "inlineCode") return;
668
+ const position = node.position;
669
+ if (position?.start.offset !== void 0 && position.end.offset !== void 0) {
670
+ codeRanges.push({ start: position.start.offset, end: position.end.offset });
690
671
  }
691
- }
672
+ if (node.type === "code" && /^(markdy|markdyscript)$/i.test(node.lang ?? "") && position) {
673
+ diagrams.push({
674
+ code: node.value.replace(/\r\n?/g, "\n"),
675
+ line: position.start.line + 1,
676
+ kind: "fence"
677
+ });
678
+ }
679
+ });
692
680
  const jsxRegex = /<(?:Markdy|MarkdyDiagram)\b([\s\S]*?)(?:\/>|<\/(?:Markdy|MarkdyDiagram)>)/g;
693
681
  let jsxMatch;
694
682
  while ((jsxMatch = jsxRegex.exec(content)) !== null) {
695
683
  const tagContent = jsxMatch[1];
696
684
  const tagStartIndex = jsxMatch.index;
685
+ if (codeRanges.some((range) => tagStartIndex >= range.start && tagStartIndex < range.end)) {
686
+ continue;
687
+ }
697
688
  const lineBefore = content.slice(0, tagStartIndex).split("\n").length;
698
689
  const templateMatch = tagContent.match(/\bcode=\{\s*`([\s\S]*?)`\s*\}/);
699
690
  if (templateMatch) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markdy/cli",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "description": "First-party CLI for diagram-native MarkdyScript diagrams: lint, format, explain, render, and preview.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -43,10 +43,12 @@
43
43
  "registry": "https://registry.npmjs.org"
44
44
  },
45
45
  "dependencies": {
46
- "@markdy/compat": "1.4.2",
47
- "@markdy/core": "1.4.2",
48
- "@markdy/stdlib-systems": "1.4.2",
49
- "@markdy/renderer-dom": "1.4.2"
46
+ "mdast-util-from-markdown": "^2.0.3",
47
+ "unist-util-visit": "^5.0.0",
48
+ "@markdy/compat": "1.4.3",
49
+ "@markdy/core": "1.4.3",
50
+ "@markdy/stdlib-systems": "1.4.3",
51
+ "@markdy/renderer-dom": "1.4.3"
50
52
  },
51
53
  "devDependencies": {
52
54
  "@types/node": "^25.9.5",