@ai-matrx/rich-content 0.2.19 → 0.2.20

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.20
4
+
5
+ - Readable Markdown copy now uses Content IR's canonical fence opener and closer. Inline code made from four or more backticks remains prose, while closed, unclosed, and nested fenced-code bodies are copied without their outer fence.
6
+
7
+ ### Consumer action
8
+
9
+ - None required. Public imports and host setup are unchanged.
10
+
3
11
  ## 0.2.10
4
12
 
5
13
  - Markdown copy goes through the host's `app.CopyButtons` (the copy menu; matrx-frontend ALC-19).
@@ -133,4 +141,3 @@ held-back streaming text; the heal tests encode 1.3.1's behavior).
133
141
 
134
142
  - matrx-frontend: call `configureRichContent` at the root (see README) and import from
135
143
  `@ai-matrx/rich-content/<domain>/<module>`.
136
-
@@ -1,11 +1,15 @@
1
- import { unwrapKindEnvelopes } from "@ai-matrx/content-ir/source";
1
+ import {
2
+ closeFence,
3
+ fenceOpenerOf,
4
+ fenceParts,
5
+ unwrapKindEnvelopes
6
+ } from "@ai-matrx/content-ir/source";
2
7
  import {
3
8
  findTableEnd,
4
9
  rowCells,
5
10
  tableStartsAt,
6
11
  unescapeCellPipes
7
12
  } from "../display/markdown-classification/processors/utils/gfm-table-lines.js";
8
- const FENCE = /^( {0,3})(`{3,}|~{3,})/;
9
13
  function readableInline(line) {
10
14
  const codes = [];
11
15
  let out = line.replace(/(`+)([\s\S]*?[^`])\1(?!`)/g, (_m, _ticks, body) => {
@@ -20,18 +24,22 @@ function readableInline(line) {
20
24
  }
21
25
  function markdownToReadableText(markdown) {
22
26
  const lines = unwrapKindEnvelopes(markdown).replace(/\r\n?/g, "\n").split("\n");
27
+ const fenceLines = {
28
+ count: lines.length,
29
+ line: (line) => lines[line] ?? null
30
+ };
23
31
  const out = [];
24
32
  for (let i = 0; i < lines.length; i += 1) {
25
33
  const line = lines[i];
26
- const fence = FENCE.exec(line);
27
- if (fence) {
28
- const marker = fence[2];
29
- let j = i + 1;
30
- while (j < lines.length && !new RegExp(`^ {0,3}${marker[0] === "`" ? "`" : "~"}{${marker.length},}\\s*$`).test(lines[j])) {
31
- out.push(lines[j]);
32
- j += 1;
34
+ const opener = fenceOpenerOf(line);
35
+ if (opener) {
36
+ const end = closeFence(fenceLines, i, opener);
37
+ const parts = fenceParts(lines.slice(i, end.line + 1).join("\n"));
38
+ if (parts) {
39
+ const bodyLineCount = end.line - i - (end.closed ? 1 : 0);
40
+ if (parts.body || bodyLineCount > 0) out.push(...parts.body.split("\n"));
33
41
  }
34
- i = j;
42
+ i = end.line;
35
43
  continue;
36
44
  }
37
45
  if (tableStartsAt(lines, i)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-matrx/rich-content",
3
- "version": "0.2.19",
3
+ "version": "0.2.20",
4
4
  "description": "The AI Matrx formatted-text engine: the one markdown renderer, streaming markdown, the block splitter and renderer, the generic blocks, <RichContent> levels, the rich-document action registry and menus, copy, and the selection toolbar — as portable React.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -137,10 +137,10 @@
137
137
  "@ai-matrx/content-ir-react": "latest",
138
138
  "@ai-matrx/data": "latest",
139
139
  "@ai-matrx/design-system": "latest",
140
+ "@ai-matrx/diff": "latest",
140
141
  "@ai-matrx/icons": "latest",
141
142
  "@ai-matrx/kit": "latest",
142
143
  "@ai-matrx/media": "latest",
143
- "@ai-matrx/diff": "latest",
144
144
  "@ai-matrx/print": "latest",
145
145
  "@ai-matrx/records": "latest",
146
146
  "@ai-matrx/records-ui": "latest",