@bettercms-ai/richtext 0.8.1 → 0.8.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.
- package/package.json +1 -1
- package/src/ingest.ts +9 -2
- package/src/styled.ts +8 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bettercms-ai/richtext",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "The one Portable Text contract for BetterCMS: schema, converters, and rendering. Shared by the backend, the dashboard and every delivery SDK.",
|
package/src/ingest.ts
CHANGED
|
@@ -187,13 +187,20 @@ function tableRule(key: KeyGenerator, ingestCell: (html: string) => PortableText
|
|
|
187
187
|
};
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
-
/** A
|
|
190
|
+
/** A highlighter's line box (Expressive Code): a `<div>` directly under the `<code>` or the `<pre>`. */
|
|
191
|
+
const isCodeLine = (node: Node): boolean =>
|
|
192
|
+
node.nodeName.toLowerCase() === "div" && /^(code|pre)$/i.test(node.parentNode?.nodeName ?? "");
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* A code block's text, line breaks included: Lexical writes them as `<br>`, a highlighter that
|
|
196
|
+
* boxes each line writes none at all, and read without one two commands became one word.
|
|
197
|
+
*/
|
|
191
198
|
const codeText = (node: Node): string =>
|
|
192
199
|
node.nodeName.toLowerCase() === "br"
|
|
193
200
|
? "\n"
|
|
194
201
|
: node.nodeType === 3
|
|
195
202
|
? (node.textContent ?? "")
|
|
196
|
-
: [...node.childNodes].map(codeText).join("");
|
|
203
|
+
: [...node.childNodes].map(codeText).join("") + (isCodeLine(node) ? "\n" : "");
|
|
197
204
|
|
|
198
205
|
/** `language-x` on the `<code>` (Markdown, our renderer) or `data-language` on the `<pre>` (Lexical, Shiki). */
|
|
199
206
|
const codeLanguage = (pre: Element): string | undefined =>
|
package/src/styled.ts
CHANGED
|
@@ -36,8 +36,14 @@ export const STYLED_TAGS = [
|
|
|
36
36
|
"strong", "b", "em", "i", "u", "s", "mark", "code", "q", "cite", "dfn", "var", "samp", "ins", "del",
|
|
37
37
|
] as const;
|
|
38
38
|
|
|
39
|
-
/**
|
|
40
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Tags whose bare form IS the design, so they are annotated even with no class: every styled tag
|
|
41
|
+
* that is neither a `<span>` nor a tag a decorator already holds. A keycap, a citation or a
|
|
42
|
+
* deleted price dropped to bare words is the page restyled by the author's first save.
|
|
43
|
+
*/
|
|
44
|
+
export const BARE_IS_DESIGN: ReadonlySet<string> = new Set([
|
|
45
|
+
"small", "sup", "sub", "kbd", "abbr", "time", "q", "cite", "dfn", "var", "samp", "ins", "del",
|
|
46
|
+
]);
|
|
41
47
|
|
|
42
48
|
export type StyledTag = (typeof STYLED_TAGS)[number];
|
|
43
49
|
|