@effected/markdown 0.18.0 → 0.20.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.
Files changed (66) hide show
  1. package/Frontmatter.js +1 -2
  2. package/FrontmatterResolver.js +1 -2
  3. package/FrontmatterSource.js +1 -2
  4. package/JsonFrontmatter.js +1 -2
  5. package/Markdown.js +25 -14
  6. package/MarkdownDiagnostic.js +1 -2
  7. package/MarkdownDocument.js +5 -39
  8. package/MarkdownEdit.js +1 -2
  9. package/MarkdownFormat.js +1 -2
  10. package/MarkdownNode.js +1 -2
  11. package/MarkdownTransform.js +166 -0
  12. package/MarkdownVisitor.js +1 -2
  13. package/Mdast.js +50 -2
  14. package/TomlFrontmatter.js +1 -2
  15. package/YamlFrontmatter.js +1 -2
  16. package/index.d.ts +310 -39
  17. package/index.js +2 -1
  18. package/internal/blockParser.js +1 -2
  19. package/internal/blockRegistry.js +1 -2
  20. package/internal/blockTypes.js +1 -2
  21. package/internal/blocks/atxHeading.js +1 -2
  22. package/internal/blocks/blockquote.js +1 -2
  23. package/internal/blocks/code.js +1 -2
  24. package/internal/blocks/document.js +1 -2
  25. package/internal/blocks/fencedCode.js +1 -2
  26. package/internal/blocks/footnoteDefinition.js +1 -2
  27. package/internal/blocks/frontmatter.js +1 -2
  28. package/internal/blocks/htmlBlock.js +1 -2
  29. package/internal/blocks/indentedCode.js +1 -2
  30. package/internal/blocks/linkReferenceDefinition.js +1 -2
  31. package/internal/blocks/list.js +1 -2
  32. package/internal/blocks/paragraph.js +1 -2
  33. package/internal/blocks/setextHeading.js +1 -2
  34. package/internal/blocks/table.js +1 -2
  35. package/internal/blocks/taskListItem.js +1 -2
  36. package/internal/blocks/thematicBreak.js +1 -2
  37. package/internal/carriers.js +1 -2
  38. package/internal/entities.js +1 -2
  39. package/internal/entityMap.js +1 -2
  40. package/internal/htmlTags.js +1 -2
  41. package/internal/inlineNode.js +1 -2
  42. package/internal/inlineParser.js +1 -2
  43. package/internal/inlineRegistry.js +1 -2
  44. package/internal/inlines/autolink.js +1 -2
  45. package/internal/inlines/autolinkLiteral.js +1 -2
  46. package/internal/inlines/codeSpan.js +1 -2
  47. package/internal/inlines/emphasis.js +1 -2
  48. package/internal/inlines/entity.js +1 -2
  49. package/internal/inlines/escape.js +1 -2
  50. package/internal/inlines/footnoteReference.js +1 -2
  51. package/internal/inlines/lineBreak.js +1 -2
  52. package/internal/inlines/link.js +1 -2
  53. package/internal/inlines/rawHtml.js +1 -2
  54. package/internal/inlines/strikethrough.js +1 -2
  55. package/internal/inlines/text.js +1 -2
  56. package/internal/lineIndex.js +1 -2
  57. package/internal/patterns.js +1 -2
  58. package/internal/phrasing.js +1 -2
  59. package/internal/preprocess.js +1 -2
  60. package/internal/rawInline.js +1 -2
  61. package/internal/references.js +1 -2
  62. package/internal/sectionBounds.js +43 -0
  63. package/internal/segments.js +1 -2
  64. package/internal/stringify.js +8 -11
  65. package/internal/unescape.js +1 -2
  66. package/package.json +4 -4
@@ -1,4 +1,4 @@
1
- //#region src/internal/preprocess.ts
1
+ // src/internal/preprocess.ts
2
2
  /** The tab stop width CommonMark fixes for indentation arithmetic. */
3
3
  const TAB_STOP = 4;
4
4
  /**
@@ -54,5 +54,4 @@ const peekCode = (line, position) => position >= 0 && position < line.length ? l
54
54
  */
55
55
  const columnsToNextTabStop = (column) => 4 - column % 4;
56
56
 
57
- //#endregion
58
57
  export { columnsToNextTabStop, isSpaceOrTab, peekCode, preprocessLines, replaceNul };
@@ -1,6 +1,6 @@
1
1
  import { parseInlines } from "./inlineParser.js";
2
2
 
3
- //#region src/internal/rawInline.ts
3
+ // src/internal/rawInline.ts
4
4
  const reWhitespace = /\s/;
5
5
  const reCmarkSpace = /[ \t\n\r]/;
6
6
  /**
@@ -55,5 +55,4 @@ const prepareInline = (block, position, refmap, dialect = "commonmark", footnote
55
55
  };
56
56
  };
57
57
 
58
- //#endregion
59
58
  export { prepareInline, trimWithSegments };
@@ -1,7 +1,7 @@
1
1
  import { unescapeString } from "./unescape.js";
2
2
  import { stickyOf } from "./patterns.js";
3
3
 
4
- //#region src/internal/references.ts
4
+ // src/internal/references.ts
5
5
  const ESCAPABLE = "[!\"#$%&'()*+,./:;<=>?@[\\\\\\]^_`{|}~-]";
6
6
  const ESCAPED_CHAR = `\\\\${ESCAPABLE}`;
7
7
  const reLinkTitle = new RegExp(`^(?:"(${ESCAPED_CHAR}|\\\\[^\\\\]|[^\\\\"\\x00])*"|'(${ESCAPED_CHAR}|\\\\[^\\\\]|[^\\\\'\\x00])*'|\\((${ESCAPED_CHAR}|\\\\[^\\\\]|[^\\\\()\\x00])*\\))`);
@@ -175,5 +175,4 @@ const parseReference = (text) => {
175
175
  };
176
176
  };
177
177
 
178
- //#endregion
179
178
  export { ReferenceScanner, normalizeLabelText, normalizeReference, parseReference };
@@ -0,0 +1,43 @@
1
+ // src/internal/sectionBounds.ts
2
+ /**
3
+ * Every root-level heading of `children`, in document order, paired with the
4
+ * child index its section ends at.
5
+ */
6
+ const rootHeadingBounds = (children) => {
7
+ const headings = [];
8
+ for (let index = 0; index < children.length; index += 1) {
9
+ const block = children[index];
10
+ if (block !== void 0 && block.type === "heading") headings.push({
11
+ index,
12
+ node: block
13
+ });
14
+ }
15
+ const nextByDepth = [
16
+ void 0,
17
+ void 0,
18
+ void 0,
19
+ void 0,
20
+ void 0,
21
+ void 0,
22
+ void 0
23
+ ];
24
+ const bounds = new Array(headings.length);
25
+ for (let index = headings.length - 1; index >= 0; index -= 1) {
26
+ const current = headings[index];
27
+ if (current === void 0) continue;
28
+ let boundary;
29
+ for (let depth = 1; depth <= current.node.depth; depth += 1) {
30
+ const candidate = nextByDepth[depth];
31
+ if (candidate !== void 0 && (boundary === void 0 || candidate < boundary)) boundary = candidate;
32
+ }
33
+ bounds[index] = {
34
+ heading: current.node,
35
+ index: current.index,
36
+ end: boundary === void 0 ? children.length : headings[boundary]?.index ?? children.length
37
+ };
38
+ nextByDepth[current.node.depth] = index;
39
+ }
40
+ return bounds;
41
+ };
42
+
43
+ export { rootHeadingBounds };
@@ -1,4 +1,4 @@
1
- //#region src/internal/segments.ts
1
+ // src/internal/segments.ts
2
2
  /**
3
3
  * The absolute source offset of `textIndex` within a segmented content run.
4
4
  *
@@ -32,5 +32,4 @@ const sliceWithSegments = (segments, from, to) => {
32
32
  return sliced;
33
33
  };
34
34
 
35
- //#endregion
36
35
  export { sliceWithSegments, sourceOffsetAt };
@@ -1,7 +1,7 @@
1
1
  import { ENTITY } from "./unescape.js";
2
2
  import { GuardExceeded } from "./carriers.js";
3
3
 
4
- //#region src/internal/stringify.ts
4
+ // src/internal/stringify.ts
5
5
  const FLOW_CONTEXT = {
6
6
  singleLine: false,
7
7
  inTable: false,
@@ -824,21 +824,18 @@ const serializeBlocks = (children, state, tight = false) => {
824
824
  return out;
825
825
  };
826
826
  /**
827
- * Serialize a document tree to canonical markdown source.
828
- *
829
- * Throws the raw `GuardExceeded` carrier when the tree nests past
830
- * `MAX_NESTING_DEPTH`; the facade materializes the typed error. Output is
831
- * empty for an empty root and ends with exactly one newline otherwise.
827
+ * Serialize a root-level block list — the one path behind both a whole
828
+ * `Root` and a lone flow node (`[node]`), so the two cannot diverge. Builds
829
+ * no wrapper node, so nothing here can fail a schema constructor.
832
830
  */
833
- const stringifyTree = (root) => {
831
+ const stringifyBlocks = (children) => {
834
832
  const state = {
835
833
  depth: 0,
836
834
  jsxDepth: 0,
837
- mdx: treeContainsMdx(root)
835
+ mdx: children.some((child) => treeContainsMdx(child))
838
836
  };
839
- const body = serializeBlocks(root.children, state);
837
+ const body = serializeBlocks(children, state);
840
838
  return body === "" ? "" : `${body}\n`;
841
839
  };
842
840
 
843
- //#endregion
844
- export { stringifyTree };
841
+ export { stringifyBlocks };
@@ -1,6 +1,6 @@
1
1
  import { decodeEntity } from "./entities.js";
2
2
 
3
- //#region src/internal/unescape.ts
3
+ // src/internal/unescape.ts
4
4
  /** The punctuation set a backslash may escape, per the spec. */
5
5
  const ESCAPABLE = "[!\"#$%&'()*+,./:;<=>?@[\\\\\\]^_`{|}~-]";
6
6
  /** One entity, in any of the three spec forms. */
@@ -14,5 +14,4 @@ const unescapeChar = (source) => {
14
14
  /** Replace every backslash escape and character reference with its literal. */
15
15
  const unescapeString = (source) => reBackslashOrAmp.test(source) ? source.replace(reEntityOrEscapedChar, unescapeChar) : source;
16
16
 
17
- //#endregion
18
17
  export { ENTITY, ESCAPABLE, unescapeString };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effected/markdown",
3
- "version": "0.18.0",
3
+ "version": "0.20.0",
4
4
  "private": false,
5
5
  "description": "CommonMark and GFM markdown parse, edit and transform schemas for Effect",
6
6
  "keywords": [
@@ -39,9 +39,9 @@
39
39
  "./package.json": "./package.json"
40
40
  },
41
41
  "peerDependencies": {
42
- "@effected/jsonc": "^0.18.0",
43
- "@effected/toml": "^0.14.0",
44
- "@effected/yaml": "^0.22.0",
42
+ "@effected/jsonc": "^0.19.0",
43
+ "@effected/toml": "^0.15.0",
44
+ "@effected/yaml": "^0.23.0",
45
45
  "effect": "^4.0.0"
46
46
  },
47
47
  "peerDependenciesMeta": {