@readme/markdown 14.2.4 → 14.2.6

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,20 @@
1
+ import { type RepairResult } from './utils';
2
+ /**
3
+ * mdxjs's micromark extension fails when a JSX element's opener-line and
4
+ * closer-line don't match in "is the tag alone on its line?" Concretely:
5
+ *
6
+ * <span>X\n</span> ❌ opener-line has text, closer-line is bare
7
+ * <span>\nX</span> ❌ opener-line is bare, closer-line has text
8
+ * text <span>X\n</span> ❌ opener-line has leading + trailing text
9
+ * <span>\nX\n</span> text ❌ closer-line has trailing text
10
+ * <span>X\nY</span> ✅ both lines have adjacent text
11
+ * <span>\nX\n</span> ✅ both lines are bare
12
+ * <span>X</span> ✅ same line
13
+ *
14
+ * When the two lines disagree, mdxjs throws "Expected a closing tag…before
15
+ * the end of `paragraph`" (or its mirror). This pass detects asymmetric
16
+ * pairs and inserts newlines (+ matching indent) to push the offending side's
17
+ * non-tag content to a separate line, restoring symmetry. Scoped to the
18
+ * malformed-retry path; the happy path doesn't touch this.
19
+ */
20
+ export declare const normalizeTagSpacing: (html: string) => RepairResult;
@@ -0,0 +1,9 @@
1
+ import type { Insert } from './utils';
2
+ import type { Node } from 'mdast';
3
+ /**
4
+ * Walk `tree`, translating every node's position from the repaired source's
5
+ * coordinate space back to the original source. Offsets are remapped via the
6
+ * insert list; line/column are recomputed from the original source so they
7
+ * remain accurate even if repairs introduced newlines.
8
+ */
9
+ export declare const remapPositionsToOriginal: (tree: Node, originalSource: string, inserts: Insert[]) => void;
@@ -0,0 +1,11 @@
1
+ import { type RepairResult } from './utils';
2
+ /**
3
+ * Rewrites `html` so every open tag has a matching close. Returns the input
4
+ * unchanged when nothing needed repair, so callers can cheaply detect no-ops.
5
+ *
6
+ * Detection runs through htmlparser2: any close event flagged `implicit` is
7
+ * a tag the user opened but didn't explicitly close. We pair it with the
8
+ * matching opener (popped from a stack we maintain) and insert `</name>` at
9
+ * the end of the opener's line, or at the trigger if they're on the same line.
10
+ */
11
+ export declare const repairUnclosedTags: (html: string) => RepairResult;
@@ -0,0 +1,19 @@
1
+ interface TagEvent {
2
+ end: number;
3
+ name: string;
4
+ start: number;
5
+ }
6
+ interface CloseEvent extends TagEvent {
7
+ implicit: boolean;
8
+ }
9
+ interface TagWalkHandlers {
10
+ onClose?: (event: CloseEvent) => void;
11
+ onOpen?: (event: TagEvent) => void;
12
+ }
13
+ /**
14
+ * Drive htmlparser2 over `html` (after masking non-tag regions) and emit
15
+ * tag-balance events. `start`/`end` use the original-string offsets, so
16
+ * callers can splice against the input directly.
17
+ */
18
+ export declare const walkTags: (html: string, handlers: TagWalkHandlers) => void;
19
+ export {};
@@ -1,4 +1,12 @@
1
1
  import type { Node } from 'mdast';
2
+ export interface Insert {
3
+ offset: number;
4
+ text: string;
5
+ }
6
+ export interface RepairResult {
7
+ inserts: Insert[];
8
+ value: string;
9
+ }
2
10
  export declare const tableTags: Set<string>;
3
11
  /**
4
12
  * If the cell has exactly one paragraph child, unwrap it so its inline children sit
@@ -8,3 +16,9 @@ export declare const tableTags: Set<string>;
8
16
  * of content that need to be preserved for JSX `<Table>` serialization.
9
17
  */
10
18
  export declare const unwrapSoleParagraph: (children: Node[]) => Node[];
19
+ /**
20
+ * Splice each text into `html` at its offset. Inserts at the same offset
21
+ * are emitted in their input order (a stable sort by offset), so callers can
22
+ * rely on innermost-first ordering by emitting events in stack-unwind order.
23
+ */
24
+ export declare const applyInserts: (html: string, inserts: Insert[]) => RepairResult;
@@ -21,3 +21,9 @@ export declare const RUNTIME_COMPONENT_TAGS: Set<string>;
21
21
  * Uses the html-tags package, converted to a Set<string> for efficient lookups.
22
22
  */
23
23
  export declare const STANDARD_HTML_TAGS: Set<string>;
24
+ /**
25
+ * HTML void elements — elements that have no closing tag and no children.
26
+ *
27
+ * @see https://html.spec.whatwg.org/multipage/syntax.html#void-elements
28
+ */
29
+ export declare const HTML_VOID_ELEMENTS: Set<string>;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@readme/markdown",
3
3
  "description": "ReadMe's React-based Markdown parser",
4
4
  "author": "Rafe Goldberg <rafe@readme.io>",
5
- "version": "14.2.4",
5
+ "version": "14.2.6",
6
6
  "main": "dist/main.node.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "browser": "dist/main.js",
@@ -42,6 +42,7 @@
42
42
  "hast-util-sanitize": "^4.0.0",
43
43
  "hastscript": "^9.0.0",
44
44
  "html-tags": "^5.1.0",
45
+ "htmlparser2": "^12.0.0",
45
46
  "lodash.escape": "^4.0.1",
46
47
  "lodash.kebabcase": "^4.1.1",
47
48
  "mdast-util-find-and-replace": "^3.0.1",
@@ -171,7 +172,7 @@
171
172
  },
172
173
  {
173
174
  "path": "dist/main.node.js",
174
- "maxSize": "875KB"
175
+ "maxSize": "920KB"
175
176
  }
176
177
  ]
177
178
  },