Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(open-knowledge): preserve document NBSP through WYSIWYG round-trip (#2628)

Nick Gomez71024eeb2f3c
diff --git a/.changeset/nbsp-document-roundtrip.md b/.changeset/nbsp-document-roundtrip.md
new file mode 100644
index 000000000..417b2faac
--- /dev/null
+++ b/.changeset/nbsp-document-roundtrip.md
@@ -0,0 +1,5 @@
+---
+'@inkeep/open-knowledge': patch
+---
+
+Literal non-breaking spaces (U+00A0) in document prose now survive WYSIWYG edits and every markdown re-parse, instead of silently becoming regular spaces. The pipeline's internal NBSP whitespace sentinel was removed; whitespace-only text nodes are preserved by the existing inline-whitespace char-ref mechanism, which now also covers NBSP at emphasis boundaries.
diff --git a/packages/app/tests/integration/nbsp-wysiwyg-preservation.test.ts b/packages/app/tests/integration/nbsp-wysiwyg-preservation.test.ts
new file mode 100644
index 000000000..9fd276cf1
--- /dev/null
+++ b/packages/app/tests/integration/nbsp-wysiwyg-preservation.test.ts
@@ -0,0 +1,127 @@
+/**
+ * Document NBSP (U+00A0) preservation through a WYSIWYG edit.
+ *
+ * Agent writes land raw bytes into Y.Text verbatim (byte-sacred), so a document
+ * NBSP is intact at rest. The XmlFragment is a re-parse of the body, and a WYSIWYG
+ * edit triggers a server Observer A settlement that re-serializes the fragment
+ * over the Y.Text region — so the NBSP must survive the full mdast<->PM
+ * round-trip, not just the write. Per precedent #57, an agent-authored byte the
+ * human never touched must survive that settlement. Observer A fires on any
+ * fragment change, so both a SAME-block and a DIFFERENT-block edit are covered;
+ * the no-edit control pins the byte-sacred write path itself.
+ */
+
+import { afterAll, beforeAll, describe, expect, test } from 'bun:test';
+import * as Y from 'yjs';
+import { HARNESS_BOOT_TIMEOUT_MS } from './harness-boot-timeout';
+import {
+ agentWriteMd,
+ awaitDocQuiescence,
+ createTestClient,
+ createTestServer,
+ pollUntil,
+ type TestClient,
+ type TestServer,
+} from './test-harness';
+
+const NBSP = '\u00A0';
+
+let server: TestServer;
+
+beforeAll(async () => {
+ server = await createTestServer();
+}, HARNESS_BOOT_TIMEOUT_MS);
+
+afterAll(async () => {
+ await server.cleanup();
+});
+
+/** Depth-first find the first Y.XmlText whose string contains `marker`. */
+function findXmlTextContaining(
+ node: Y.XmlFragment | Y.XmlElement,
+ marker: string,
+): Y.XmlText | null {
+ const len = node.length;
+ for (let i = 0; i < len; i++) {
+ const child = node.get(i);
+ if (child instanceof Y.XmlText) {
+ if (child.toString().includes(marker)) return child;
+ } else if (child instanceof Y.XmlElement) {
+ const found = findXmlTextContaining(child, marker);
+ if (found) return found;
+ }
+ }
+ return null;
+}
+
+/**
+ * Seed `body` via the agent path (bytes land verbatim), assert the NBSP is
+ * intact at rest, then optionally append " EDITWORD" to the span containing
+ * `editMarker` through the XmlFragment (the WYSIWYG write surface). Awaits the
+ * server Observer A round-trip + local settlement, and returns the client's
+ * Y.Text('source') string.
+ */
+async function seedThenMaybeEdit(opts: { body: string; editMarker?: string }): Promise<string> {
+ const docName = `nbsp-${crypto.randomUUID()}`;
+ const client: TestClient = await createTestClient(server.port, docName, {
+ skipInvariantWatcher: true,
+ });
+ try {
+ await agentWriteMd(server.port, opts.body, { docName, position: 'replace' });
+ // Wait for the seed to land on the client, then confirm the seed itself is
+ // byte-sacred — the RED assertion below is only meaningful if the NBSP was
+ // present after the agent write and lost by the WYSIWYG edit, not absent
+ // from the start.
+ await pollUntil(() => client.ytext.toString().includes('bar'), 5000);
+ await awaitDocQuiescence(client.doc);
+ expect(client.ytext.toString()).toContain(NBSP);
+
+ if (opts.editMarker !== undefined) {
+ const target = findXmlTextContaining(client.fragment, opts.editMarker);
+ if (!target) {
+ throw new Error(`edit marker not found in fragment: ${opts.editMarker}`);
+ }
+ target.insert(target.length, ' EDITWORD');
+ // Wait for the server Observer A settlement to echo back, then settle any
+ // follow-on observer cascade locally.
+ await pollUntil(() => client.ytext.toString().includes('EDITWORD'), 5000);
+ await awaitDocQuiescence(client.doc);
+ // Guard against a false-RED: prove the edit actually round-tripped.
+ expect(client.ytext.toString()).toContain('EDITWORD');
+ }
+
+ return client.ytext.toString();
+ } finally {
+ await client.cleanup();
+ }
+}
+
+describe('document NBSP survives a WYSIWYG edit', () => {
+ test('document NBSP survives a WYSIWYG edit in the SAME block', async () => {
+ const ytext = await seedThenMaybeEdit({
+ body: `Alpha foo${NBSP}bar keepme\n`,
+ editMarker: 'keepme',
+ });
+ expect(ytext).toContain(NBSP);
+ }, 25_000);
+
+ test('document NBSP survives a WYSIWYG edit in a DIFFERENT block', async () => {
+ const ytext = await seedThenMaybeEdit({
+ body: `Kept foo${NBSP}bar paragraph.\n\nEditable paragraph editme.\n`,
+ editMarker: 'editme',
+ });
+ expect(ytext).toContain(NBSP);
+ }, 25_000);
+
+ /**
+ * Byte-sacred control: with no WYSIWYG edit, Observer A never fires and the
+ * verbatim NBSP survives in Y.Text. Pins the byte-sacred write path itself.
+ *
+ */
+ test('document NBSP survives verbatim with no WYSIWYG edit (byte-sacred control)', async () => {
+ const ytext = await seedThenMaybeEdit({
+ body: `Alpha foo${NBSP}bar keepme\n`,
+ });
+ expect(ytext).toContain(NBSP);
+ }, 25_000);
+});
diff --git a/packages/core/src/bridge/bind-frontmatter-doc.ts b/packages/core/src/bridge/bind-frontmatter-doc.ts
index 8f9d95287..c014b1413 100644
--- a/packages/core/src/bridge/bind-frontmatter-doc.ts
+++ b/packages/core/src/bridge/bind-frontmatter-doc.ts
@@ -1,4 +1,3 @@
-
import type * as Y from 'yjs';
import type { Err, Ok, Result } from '../config/result.ts';
import { type FrontmatterValidationError, toFrontmatterIssue } from '../frontmatter/errors.ts';
diff --git a/packages/core/src/bridge/bridge-invariant.ts b/packages/core/src/bridge/bridge-invariant.ts
index 8bfdb40cd..005627195 100644
--- a/packages/core/src/bridge/bridge-invariant.ts
+++ b/packages/core/src/bridge/bridge-invariant.ts
@@ -1,4 +1,3 @@
-
import { fnv1aDigest } from './hash-util.ts';
export type BridgeInvariantSite = 'observer-b' | 'persistence' | 'test-harness';
diff --git a/packages/core/src/bridge/doc-boundary-space.ts b/packages/core/src/bridge/doc-boundary-space.ts
index c18c086d5..8890f6739 100644
--- a/packages/core/src/bridge/doc-boundary-space.ts
+++ b/packages/core/src/bridge/doc-boundary-space.ts
@@ -1,4 +1,3 @@
-
import { FRONTMATTER_RE, stripFrontmatter } from '../extensions/frontmatter.ts';
const LEADING_BOUNDARY_RE = /^(?:\r?\n)+/;
diff --git a/packages/core/src/bridge/growth-detect.ts b/packages/core/src/bridge/growth-detect.ts
index 463e89595..9d9c244b0 100644
--- a/packages/core/src/bridge/growth-detect.ts
+++ b/packages/core/src/bridge/growth-detect.ts
@@ -1,4 +1,3 @@
-
const DEFAULT_MIN_SUBSTANTIVE_LINE_LENGTH = 16;
export const DUPLICATION_GATE_MIN_LINE_LENGTH = 8;
diff --git a/packages/core/src/bridge/merge-three-way.ts b/packages/core/src/bridge/merge-three-way.ts
index 3c927eb47..3ab9cc6ef 100644
--- a/packages/core/src/bridge/merge-three-way.ts
+++ b/packages/core/src/bridge/merge-three-way.ts
@@ -38,7 +38,6 @@ function mergeThreeWayImpl(baseline: string, userText: string, agentText: string
return parts.join('\n');
}
-
export type BridgeMergeContentLossSide = 'user' | 'agent';
export type BridgeMergeContentLossWhich = 'substring' | 'order' | 'growth';
diff --git a/packages/core/src/bridge/normalize.ts b/packages/core/src/bridge/normalize.ts
index 592f0b956..e67f33b40 100644
--- a/packages/core/src/bridge/normalize.ts
+++ b/packages/core/src/bridge/normalize.ts
@@ -1,4 +1,3 @@
-
const COMMONMARK_ESCAPE_RE = /\\([!"#$%&'()*+,\-./:;<=>?@[\]^_`{|}~])/g;
const TABLE_ALIGN_ROW_RE = /^\s*\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)+\|?\s*$/;
diff --git a/packages/core/src/bridge/pm-structural-equivalence.ts b/packages/core/src/bridge/pm-structural-equivalence.ts
index 0be5203e4..754dc5cc2 100644
--- a/packages/core/src/bridge/pm-structural-equivalence.ts
+++ b/packages/core/src/bridge/pm-structural-equivalence.ts
@@ -32,7 +32,6 @@ const BR_SENTINEL: PmStructuralNode = { type: '__br__' };
const BR_LITERAL_RE = /^<br\s*\/?>$/i;
-
interface DegradeEntry {
readonly label: string;
readonly severity: ToleranceClassSeverity;
@@ -128,7 +127,6 @@ export interface ComparePmStructuralOptions {
ignoreAttrs?: (attrKey: string) => boolean;
}
-
/** Rebuild a node with `fn` applied to each child; identity when childless.
* Shared by the degrade canonicalizers so none re-implements the walk. */
function mapChildren(
@@ -250,7 +248,6 @@ function applyDegrades(tree: PmStructuralNode): {
return { normalized: current, fired };
}
-
export function comparePmStructural(
expected: PmStructuralNode,
actual: PmStructuralNode,
diff --git a/packages/core/src/bridge/subsequence.ts b/packages/core/src/bridge/subsequence.ts
index dca644141..af20de1e2 100644
--- a/packages/core/src/bridge/subsequence.ts
+++ b/packages/core/src/bridge/subsequence.ts
@@ -1,4 +1,3 @@
-
/** True when `needle` is a subsequence of `haystack` (two-pointer, O(n+m)):
* insertions in `haystack` are free; any dropped or substituted `needle` byte
* fails. */
diff --git a/packages/core/src/extensions/source-literal-mark.test.ts b/packages/core/src/extensions/source-literal-mark.test.ts
index 59f8a84ed..3463a80f2 100644
--- a/packages/core/src/extensions/source-literal-mark.test.ts
+++ b/packages/core/src/extensions/source-literal-mark.test.ts
@@ -6,9 +6,10 @@
* can mutate the PM document could pin one byte sequence as visible text and
* a different sequence in `sourceRaw`, persisting bytes the user never saw —
* a hidden-content injection vector. `isValidSourceLiteralRaw` is the gate
- * that bounds legitimate divergence to: markdown backslash escapes, NBSP
- * normalization, and an inline-whitespace numeric char-ref run (`&#x20;`/`&#x9;`)
- * whose decoded space(s)/tab(s) equal the visible text.
+ * that bounds legitimate divergence to: markdown backslash escapes, a benign
+ * literal-NBSP-vs-space divergence, and an inline-whitespace numeric char-ref run
+ * (`&#x20;`/`&#x9;`/`&#xA0;`) whose decoded space(s)/tab(s)/NBSP(s) equal the
+ * visible text.
*/
import { describe, expect, test } from 'bun:test';
@@ -110,12 +111,28 @@ describe('isValidSourceLiteralRaw — inline-whitespace numeric char-ref diverge
expect(isValidSourceLiteralRaw('&#32;', ' ')).toBe(true); // decimal space
expect(isValidSourceLiteralRaw('&#x9;', '\t')).toBe(true); // hex tab
expect(isValidSourceLiteralRaw('&#9;', '\t')).toBe(true); // decimal tab
+ // NBSP (U+00A0) - the serializer mints `&#xA0;` at an attention boundary;
+ // the editor shows the real NBSP while sourceRaw keeps the exact bytes.
+ // Visible NBSP written as a \u00A0 escape, never a literal byte (false-green hazard).
+ expect(isValidSourceLiteralRaw('&#xA0;', '\u00A0')).toBe(true); // hex NBSP
+ expect(isValidSourceLiteralRaw('&#XA0;', '\u00A0')).toBe(true); // capital X
+ expect(isValidSourceLiteralRaw('&#160;', '\u00A0')).toBe(true); // decimal NBSP
});
test('accepts a RUN of whitespace refs decoding to the visible run (coalesced segment)', () => {
expect(isValidSourceLiteralRaw('&#x20;&#x20;', ' ')).toBe(true);
expect(isValidSourceLiteralRaw('&#x9;&#x9;', '\t\t')).toBe(true);
expect(isValidSourceLiteralRaw('&#x20;&#x9;', ' \t')).toBe(true);
+ expect(isValidSourceLiteralRaw('&#xA0;&#xA0;', '\u00A0\u00A0')).toBe(true);
+ expect(isValidSourceLiteralRaw('&#x20;&#xA0;', ' \u00A0')).toBe(true);
+ });
+
+ test('char-ref decode branch matches the decoded codepoint EXACTLY (no NBSP<->space fold)', () => {
+ // The mdast->PM decode always sets a `&#xA0;` node's display to a real NBSP
+ // and a `&#x20;` node's display to a real space, so the gate matches the
+ // decoded codepoint exactly on this branch — a cross pairing is rejected.
+ expect(isValidSourceLiteralRaw('&#xA0;', ' ')).toBe(false); // NBSP ref, plain-space visible
+ expect(isValidSourceLiteralRaw('&#x20;', '\u00A0')).toBe(false); // space ref, NBSP visible
});
test('rejects a run whose decoded length does NOT match the visible run', () => {
diff --git a/packages/core/src/extensions/source-literal-mark.ts b/packages/core/src/extensions/source-literal-mark.ts
index 971355729..f0715a241 100644
--- a/packages/core/src/extensions/source-literal-mark.ts
+++ b/packages/core/src/extensions/source-literal-mark.ts
@@ -51,13 +51,19 @@ export const SourceLiteralMark = Mark.create({
*
* Legitimate divergence between visible text and raw is bounded to:
* - markdown backslash escapes (`\<punct>` in source → `<punct>` in value)
- * - U+00A0 (NBSP) → U+0020 (SPACE) normalization applied during parse
- * - an inline-whitespace numeric char-ref (`&#x20;` / `&#x9;`) whose decoded
- * codepoint IS the visible text: the byte-fidelity serializer mints these
- * for a phrasing-boundary space/tab, the editor shows the real space/tab
- * while `sourceRaw` keeps the exact bytes. Strictly scoped to inline
- * whitespace — the decoded value can only ever be a single space or tab, so
- * it cannot smuggle attacker-visible text (script, scheme, structure).
+ * - U+00A0 (NBSP) folded to U+0020 (SPACE) for comparison: a defensive
+ * acceptance of a benign NBSP-vs-space divergence (both are horizontal
+ * spacing). Parse no longer normalizes NBSP to space — a document NBSP now
+ * round-trips verbatim — so this fold only admits a benign paste/legacy
+ * divergence, never a structure-smuggling one.
+ * - an inline-whitespace numeric char-ref (`&#x20;` / `&#x9;` / `&#xA0;`) whose
+ * decoded codepoint IS the visible text: the byte-fidelity serializer mints
+ * these for a phrasing-boundary space/tab/NBSP, the editor shows the real
+ * whitespace char while `sourceRaw` keeps the exact bytes. Strictly scoped to
+ * inline whitespace — the decoded value can only ever be a single space, tab,
+ * or NBSP, so it cannot smuggle attacker-visible text (script, scheme,
+ * structure). This branch matches the decoded codepoint EXACTLY (unfolded),
+ * keeping it in lockstep with the mdast→PM decode.
*
* Newlines and other control characters are rejected outright: sourceLiteral
* is an inline-only mark, so a control character in the raw bytes would by
@@ -76,12 +82,19 @@ export function isValidSourceLiteralRaw(sourceRaw: unknown, visibleText: unknown
if (normalizedRaw === normalizedVisible) return true;
if (stripMarkdownBackslashEscapes(normalizedRaw) === normalizedVisible) return true;
// A run of inline-whitespace numeric char-refs displayed as its decoded
- // spaces/tabs. The decoded value is provably whitespace-only (each member is a
- // space or tab), so this divergence class cannot display innocuous text while
- // persisting attacker bytes. A run (not a single ref) is admitted because the
- // mdast→PM display decode coalesces contiguous boundary-whitespace refs into
- // one segment to dodge ProseMirror's equal-mark text-node merge.
- return decodeInlineWhitespaceNumericCharRefRun(normalizedRaw) === normalizedVisible;
+ // spaces/tabs/NBSPs. The decoded value is provably whitespace-only (each member
+ // is a space, tab, or NBSP), so this divergence class cannot display innocuous
+ // text while persisting attacker bytes. A run (not a single ref) is admitted
+ // because the mdast→PM display decode coalesces contiguous boundary-whitespace
+ // refs into one segment to dodge ProseMirror's equal-mark text-node merge.
+ //
+ // This branch compares the UNFOLDED bytes on both sides, unlike the two above:
+ // the mdast→PM decode sets the display to exactly
+ // decodeInlineWhitespaceNumericCharRefRun(raw) (an NBSP for `&#xA0;`, a space
+ // for `&#x20;`), so the gate must match that same decoded codepoint. Folding
+ // NBSP→space here would reject a legitimate `&#xA0;`/NBSP pair while the direct
+ // branch above still admits the benign literal-NBSP↔space divergence.
+ return decodeInlineWhitespaceNumericCharRefRun(sourceRaw) === visibleText;
}
/**
diff --git a/packages/core/src/markdown/callout-transformer.ts b/packages/core/src/markdown/callout-transformer.ts
index a363dfd54..83d47404a 100644
--- a/packages/core/src/markdown/callout-transformer.ts
+++ b/packages/core/src/markdown/callout-transformer.ts
@@ -1,4 +1,3 @@
-
import type { Blockquote, Paragraph, Root } from 'mdast';
import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
import { visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/comment-promoter.ts b/packages/core/src/markdown/comment-promoter.ts
index 47f0d07e4..193e286b0 100644
--- a/packages/core/src/markdown/comment-promoter.ts
+++ b/packages/core/src/markdown/comment-promoter.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Paragraph, PhrasingContent, Root, RootContent, Text } from 'mdast';
import { SKIP, visit } from 'unist-util-visit';
import type { VFile } from 'vfile';
diff --git a/packages/core/src/markdown/dedent-block-jsx-close.ts b/packages/core/src/markdown/dedent-block-jsx-close.ts
index b6299a948..ece5c02a1 100644
--- a/packages/core/src/markdown/dedent-block-jsx-close.ts
+++ b/packages/core/src/markdown/dedent-block-jsx-close.ts
@@ -1,4 +1,3 @@
-
import { findFencedRegions, isInsideFence } from './fence-regions.ts';
const INDENTED_BLOCK_JSX_CLOSE_RE = /^([ ]{1,3})(<\/[A-Z][A-Za-z0-9_]*\s*>)([ \t]*)$/gm;
diff --git a/packages/core/src/markdown/details-accordion-promoter.ts b/packages/core/src/markdown/details-accordion-promoter.ts
index acd398aa6..54774764a 100644
--- a/packages/core/src/markdown/details-accordion-promoter.ts
+++ b/packages/core/src/markdown/details-accordion-promoter.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Paragraph, Parent, Root, Text } from 'mdast';
import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
import { visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/fence-regions.ts b/packages/core/src/markdown/fence-regions.ts
index fb5ac8e8a..c7518d614 100644
--- a/packages/core/src/markdown/fence-regions.ts
+++ b/packages/core/src/markdown/fence-regions.ts
@@ -1,4 +1,3 @@
-
const FENCE_RE = /^(`{3,}|~{3,})/gm;
export function findFencedRegions(src: string): Array<[number, number]> {
diff --git a/packages/core/src/markdown/fixtures/index.ts b/packages/core/src/markdown/fixtures/index.ts
index 6931623c7..00f5771ee 100644
--- a/packages/core/src/markdown/fixtures/index.ts
+++ b/packages/core/src/markdown/fixtures/index.ts
@@ -1,4 +1,3 @@
-
import { readFileSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
@@ -9,7 +8,6 @@ function fixturePath(...segments: string[]): string {
return resolve(FIXTURES_DIR, ...segments);
}
-
interface GfmExample {
section: string;
markdown: string;
@@ -19,7 +17,6 @@ export function loadGfmExamples(): GfmExample[] {
return JSON.parse(readFileSync(fixturePath('gfm', 'examples.json'), 'utf8')) as GfmExample[];
}
-
interface MdxCrashEntry {
id: string;
input: string;
@@ -71,7 +68,6 @@ export function loadLargeEmbedFixtures(): LargeEmbedFixture[] {
) as LargeEmbedFixture[];
}
-
export function loadPrd6955Before(): string {
return readFileSync(fixturePath('regression', 'prd-6955-before.md'), 'utf8');
}
@@ -80,7 +76,6 @@ export function loadPrd6955CorruptedTriplicated(): string {
return readFileSync(fixturePath('regression', 'prd-6955-corrupted-triplicated.md'), 'utf8');
}
-
export interface NgPinnedCase {
id: string;
name: string;
@@ -97,7 +92,6 @@ export function loadNgPinnedCases(): NgPinnedCase[] {
) as NgPinnedCase[];
}
-
export function loadLargeRealistic(): string {
return readFileSync(fixturePath('perf', 'large-realistic.md'), 'utf8');
}
diff --git a/packages/core/src/markdown/fixtures/perf/generate.ts b/packages/core/src/markdown/fixtures/perf/generate.ts
index daa3ef82b..8b1eb8519 100644
--- a/packages/core/src/markdown/fixtures/perf/generate.ts
+++ b/packages/core/src/markdown/fixtures/perf/generate.ts
@@ -1,4 +1,3 @@
-
import { writeFileSync } from 'node:fs';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
@@ -11,7 +10,6 @@ const BASELINE_ONLY_COUNTS = [500, 2500] as const;
const SEED = 0xf1de1117;
-
function mulberry32(seed: number): () => number {
let a = seed >>> 0;
return () => {
@@ -38,7 +36,6 @@ function pickWeighted<T>(rand: () => number, items: readonly [T, number][]): T {
return items[items.length - 1][0];
}
-
const WORDS = [
'lorem',
'ipsum',
@@ -156,7 +153,6 @@ function mdxBlock(rand: () => number): string {
return `<${name}>\n\n${sentence(rand)}\n\n</${name}>`;
}
-
type BlockKind = 'paragraph' | 'heading' | 'list' | 'code' | 'table' | 'mdx';
const MIX: readonly [BlockKind, number][] = [
@@ -195,7 +191,6 @@ function generateDocument(blockCount: number, seed: number): string {
return `${blocks.join('\n\n')}\n`;
}
-
function main(): void {
for (const count of [...BLOCK_COUNTS, ...BASELINE_ONLY_COUNTS]) {
const doc = generateDocument(count, SEED);
diff --git a/packages/core/src/markdown/guard-flanking-matrix.ts b/packages/core/src/markdown/guard-flanking-matrix.ts
index 32c055c5b..420dc0fe5 100644
--- a/packages/core/src/markdown/guard-flanking-matrix.ts
+++ b/packages/core/src/markdown/guard-flanking-matrix.ts
@@ -7,7 +7,6 @@ import {
import { BACKSLASH_GUARD_SUBSTITUTIONS, encodeBackslashEscapes } from './backslash-escape-guard.ts';
import { ENTITY_REF_GUARD_SUBSTITUTIONS, encodeEntityRefs } from './entity-ref-guard.ts';
-
export const ATTENTION_DELIMITERS = ['*', '_', '**', '~~', '=='] as const;
export type FlankClass = 'whitespace' | 'punctuation' | 'other';
diff --git a/packages/core/src/markdown/handler-shadow-audit.ts b/packages/core/src/markdown/handler-shadow-audit.ts
index 283913255..2653473da 100644
--- a/packages/core/src/markdown/handler-shadow-audit.ts
+++ b/packages/core/src/markdown/handler-shadow-audit.ts
@@ -1,4 +1,3 @@
-
export interface HandlerShadowWitness {
input: string;
expect: 'byte' | 'byte-and-reparse-type';
diff --git a/packages/core/src/markdown/highlight-promoter.ts b/packages/core/src/markdown/highlight-promoter.ts
index 7a22e8016..f758cf737 100644
--- a/packages/core/src/markdown/highlight-promoter.ts
+++ b/packages/core/src/markdown/highlight-promoter.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Parent, PhrasingContent, Root, Text } from 'mdast';
import type { MdxJsxTextElement } from 'mdast-util-mdx';
import { SKIP, visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/html-to-mdast.ts b/packages/core/src/markdown/html-to-mdast.ts
index 2f082e6d0..78fdfeb02 100644
--- a/packages/core/src/markdown/html-to-mdast.ts
+++ b/packages/core/src/markdown/html-to-mdast.ts
@@ -1,4 +1,3 @@
-
import type { Root as HastRoot } from 'hast';
import type { Root as MdastRoot } from 'mdast';
import rehypeParse from 'rehype-parse';
@@ -76,8 +75,7 @@ export function htmlToMdast(html: string, options?: HtmlToMdastOptions): MdastRo
throw new HtmlPayloadTooLargeError(html.length, maxBytes);
}
- const processor = unified()
- .use(rehypeParse, { fragment: true });
+ const processor = unified().use(rehypeParse, { fragment: true });
for (const plugin of cleanupPlugins) {
processor.use(plugin);
diff --git a/packages/core/src/markdown/image-promoter.ts b/packages/core/src/markdown/image-promoter.ts
index 994eb6917..706fa9afb 100644
--- a/packages/core/src/markdown/image-promoter.ts
+++ b/packages/core/src/markdown/image-promoter.ts
@@ -1,4 +1,3 @@
-
import type { Image, Paragraph, Root } from 'mdast';
import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
import { visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/index.ts b/packages/core/src/markdown/index.ts
index ceb72c4da..a5827a5d0 100644
--- a/packages/core/src/markdown/index.ts
+++ b/packages/core/src/markdown/index.ts
@@ -1,4 +1,3 @@
-
import {
type FromProseMirrorOptions,
fromPmMark,
@@ -197,7 +196,6 @@ export class MarkdownManager {
}
}
-
const registry = createRegistry();
function destructureAttrs(
@@ -246,7 +244,6 @@ function destructureAttrs(
return result;
}
-
function hasDirtyDescendant(node: PmNode): boolean {
let found = false;
node.descendants((child) => {
@@ -266,7 +263,6 @@ function effectiveDirty(node: PmNode, freshnessChecker?: StructuralFreshnessChec
return freshnessChecker ? freshnessChecker.isDiverged(node.toJSON()) : false;
}
-
function isEmptyMdastParagraph(node: MdastNodes): boolean {
if (node.type !== 'paragraph') return false;
const children = node.children ?? [];
@@ -335,7 +331,6 @@ function extractTextFromMdastNodes(nodes: MdastNodes[]): string {
return out;
}
-
import {
AUDIO_EXTENSIONS,
FILE_ATTACHMENT_EXTENSIONS,
@@ -471,17 +466,16 @@ function buildMdastToPmHandlers(
const sourceRaw = typeof node.data?.sourceRaw === 'string' ? node.data.sourceRaw : null;
if (!value && !sourceRaw) return null;
if (sourceRaw) {
- const normalized = value.replaceAll('\u00A0', ' ');
return m.sourceLiteral
- ? schema.text(normalized, [m.sourceLiteral.create({ sourceRaw })])
- : schema.text(normalized);
+ ? schema.text(value, [m.sourceLiteral.create({ sourceRaw })])
+ : schema.text(value);
}
const escapedChars: Array<{ offset: number; char: string }> | undefined =
node.data?.escapedChars;
const entityRefSpans: Array<{ offset: number; length: number; raw: string }> | undefined =
node.data?.entityRefSpans;
if (!escapedChars?.length && !entityRefSpans?.length) {
- return schema.text(value.replaceAll('\u00A0', ' '));
+ return schema.text(value);
}
type Marker =
| { kind: 'escape'; offset: number; length: number }
@@ -519,13 +513,11 @@ function buildMdastToPmHandlers(
let lastIdx = 0;
for (const marker of coalesced) {
if (marker.offset > lastIdx) {
- const segment = value.slice(lastIdx, marker.offset).replaceAll('\u00A0', ' ');
+ const segment = value.slice(lastIdx, marker.offset);
if (segment) fragments.push(schema.text(segment));
}
if (marker.offset < value.length) {
- const segmentText = value
- .slice(marker.offset, marker.offset + marker.length)
- .replaceAll('\u00A0', ' ');
+ const segmentText = value.slice(marker.offset, marker.offset + marker.length);
if (segmentText) {
if (marker.kind === 'escape') {
fragments.push(schema.text(segmentText, [m.escapeMark.create()]));
@@ -544,7 +536,7 @@ function buildMdastToPmHandlers(
}
}
if (lastIdx < value.length) {
- const remaining = value.slice(lastIdx).replaceAll('\u00A0', ' ');
+ const remaining = value.slice(lastIdx);
if (remaining) fragments.push(schema.text(remaining));
}
return fragments.length === 1 ? fragments[0] : fragments;
@@ -585,7 +577,6 @@ function buildMdastToPmHandlers(
}));
}
-
if (m.emphasis) {
handlers.emphasis = toPmMark(m.emphasis, (node: Emphasis) => ({
sourceDelimiter: node.data?.sourceDelimiter ?? '*',
@@ -665,7 +656,6 @@ function buildMdastToPmHandlers(
}));
}
-
if (m.link) {
const sourceLiteralMark = m.sourceLiteral;
handlers.link = (node: Link, _parent: MdastParent, state: MdastToPmState) => {
@@ -944,7 +934,6 @@ function buildMdastToPmHandlers(
};
}
-
const blockUnknownHandler = (node: {
type: string;
position?: { start: { offset: number }; end: { offset: number } };
@@ -1070,7 +1059,6 @@ function buildMdastToPmHandlers(
return handlers as RemarkProseMirrorOptions['handlers'];
}
-
function buildPmToMdastHandlers(
schema: Schema,
freshness: FreshnessCheckerHolder,
diff --git a/packages/core/src/markdown/math-promoter.ts b/packages/core/src/markdown/math-promoter.ts
index bd79424c7..a5b511f25 100644
--- a/packages/core/src/markdown/math-promoter.ts
+++ b/packages/core/src/markdown/math-promoter.ts
@@ -1,4 +1,3 @@
-
import type { Code, Root } from 'mdast';
import type { Math as MdastMath } from 'mdast-util-math';
import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
diff --git a/packages/core/src/markdown/mdast-to-hast-handlers.ts b/packages/core/src/markdown/mdast-to-hast-handlers.ts
index f84967798..679c72ef7 100644
--- a/packages/core/src/markdown/mdast-to-hast-handlers.ts
+++ b/packages/core/src/markdown/mdast-to-hast-handlers.ts
@@ -1,4 +1,3 @@
-
import type { Comment, Element, ElementContent, Properties } from 'hast';
import type { FootnoteDefinition, FootnoteReference } from 'mdast';
import type { MdxJsxFlowElement, MdxJsxTextElement } from 'mdast-util-mdx';
diff --git a/packages/core/src/markdown/mdast-to-html.ts b/packages/core/src/markdown/mdast-to-html.ts
index df788a80d..8ce2b2492 100644
--- a/packages/core/src/markdown/mdast-to-html.ts
+++ b/packages/core/src/markdown/mdast-to-html.ts
@@ -1,4 +1,3 @@
-
import type { Element, Root as HastRoot, Text as HastText } from 'hast';
import type { Root as MdastRoot, Text as MdastText } from 'mdast';
import type { Handler } from 'mdast-util-to-hast';
diff --git a/packages/core/src/markdown/merged-walker.ts b/packages/core/src/markdown/merged-walker.ts
index fa3cfcd86..bfd7e3109 100644
--- a/packages/core/src/markdown/merged-walker.ts
+++ b/packages/core/src/markdown/merged-walker.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Parent, Root } from 'mdast';
import { SKIP, visit } from 'unist-util-visit';
import type { VFile } from 'vfile';
diff --git a/packages/core/src/markdown/mermaid-promoter.ts b/packages/core/src/markdown/mermaid-promoter.ts
index 17ed2b829..1a897fca8 100644
--- a/packages/core/src/markdown/mermaid-promoter.ts
+++ b/packages/core/src/markdown/mermaid-promoter.ts
@@ -1,4 +1,3 @@
-
import type { Code, Root } from 'mdast';
import type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
import { visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/parse-with-fallback.ts b/packages/core/src/markdown/parse-with-fallback.ts
index 7e4a9a48b..9864b3b60 100644
--- a/packages/core/src/markdown/parse-with-fallback.ts
+++ b/packages/core/src/markdown/parse-with-fallback.ts
@@ -168,7 +168,6 @@ export function parseRecursive(
}
}
-
interface VFilePlace {
offset?: number;
start?: { offset?: number };
@@ -187,7 +186,6 @@ function extractErrorOffset(err: unknown): number | undefined {
return undefined;
}
-
interface Region {
start: number;
end: number;
@@ -211,7 +209,6 @@ function nearestBlankLineAfter(src: string, offset: number): number | null {
return null;
}
-
export interface TagEvent {
kind: 'open' | 'close' | 'self-close';
name: string;
@@ -358,7 +355,6 @@ function findFallbackRegion(src: string, errorOffset: number): Region {
return { start: blockStart, end: blockEnd };
}
-
interface SourceBlock {
src: string;
start: number;
@@ -456,7 +452,6 @@ function tryPerBlockFallback(
};
}
-
function wholeDocRawText(source: string): JSONContent {
return {
type: 'doc',
diff --git a/packages/core/src/markdown/parser-drop-closure.ts b/packages/core/src/markdown/parser-drop-closure.ts
index 43d420187..e6ab4fd57 100644
--- a/packages/core/src/markdown/parser-drop-closure.ts
+++ b/packages/core/src/markdown/parser-drop-closure.ts
@@ -1,4 +1,3 @@
-
export type DroppedTokenAdjudication =
| {
kind: 'format-dof-axis';
diff --git a/packages/core/src/markdown/pipeline.ts b/packages/core/src/markdown/pipeline.ts
index 5b9550e90..5d6db7aa8 100644
--- a/packages/core/src/markdown/pipeline.ts
+++ b/packages/core/src/markdown/pipeline.ts
@@ -1,4 +1,3 @@
-
import {
type FromProseMirrorOptions,
fromProseMirror,
diff --git a/packages/core/src/markdown/position-aware-join.ts b/packages/core/src/markdown/position-aware-join.ts
index f8f5e8530..5a5e4c42a 100644
--- a/packages/core/src/markdown/position-aware-join.ts
+++ b/packages/core/src/markdown/position-aware-join.ts
@@ -1,4 +1,3 @@
-
import type { Join } from 'mdast-util-to-markdown';
import type { Position } from 'unist';
diff --git a/packages/core/src/markdown/position-slice.ts b/packages/core/src/markdown/position-slice.ts
index 860a7b360..51f600876 100644
--- a/packages/core/src/markdown/position-slice.ts
+++ b/packages/core/src/markdown/position-slice.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Root } from 'mdast';
import { visit } from 'unist-util-visit';
import type { VFile } from 'vfile';
@@ -470,8 +469,7 @@ export function applyPositionSliceToNode(
const first = source[startOff];
if (first !== '[' && first !== '<' && !node.title) {
node.data.sourceStyle = 'gfm-autolink';
- }
- else if (first === '[') {
+ } else if (first === '[') {
const slice = source.slice(startOff, endOff);
const closeBracketIdx = slice.lastIndexOf('](');
if (closeBracketIdx !== -1) {
diff --git a/packages/core/src/markdown/rehype-plugins/skip-notion-whitespace.ts b/packages/core/src/markdown/rehype-plugins/skip-notion-whitespace.ts
index ca225ce9b..db10fa54b 100644
--- a/packages/core/src/markdown/rehype-plugins/skip-notion-whitespace.ts
+++ b/packages/core/src/markdown/rehype-plugins/skip-notion-whitespace.ts
@@ -1,4 +1,3 @@
-
import type { Comment, Element, Root, Text } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-cocoa-meta.ts b/packages/core/src/markdown/rehype-plugins/strip-cocoa-meta.ts
index 3a2524a9a..34068d103 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-cocoa-meta.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-cocoa-meta.ts
@@ -1,4 +1,3 @@
-
import type { Element, ElementContent, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-gdocs-wrapper.ts b/packages/core/src/markdown/rehype-plugins/strip-gdocs-wrapper.ts
index 2279a0189..93151d43b 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-gdocs-wrapper.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-gdocs-wrapper.ts
@@ -1,4 +1,3 @@
-
import type { Element, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-github-hovercard.ts b/packages/core/src/markdown/rehype-plugins/strip-github-hovercard.ts
index a0f467c42..188f02d83 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-github-hovercard.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-github-hovercard.ts
@@ -1,4 +1,3 @@
-
import type { Element, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-gmail-classes.ts b/packages/core/src/markdown/rehype-plugins/strip-gmail-classes.ts
index 4e8542a21..4ba2c3418 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-gmail-classes.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-gmail-classes.ts
@@ -1,4 +1,3 @@
-
import type { Element, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-gsheets-wrapper.ts b/packages/core/src/markdown/rehype-plugins/strip-gsheets-wrapper.ts
index a3c96b24a..1a74b1272 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-gsheets-wrapper.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-gsheets-wrapper.ts
@@ -1,4 +1,3 @@
-
import type { Element, ElementContent, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-mso-styles.ts b/packages/core/src/markdown/rehype-plugins/strip-mso-styles.ts
index e95cf43d6..de35e7b79 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-mso-styles.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-mso-styles.ts
@@ -1,4 +1,3 @@
-
import type { Comment, Element, ElementContent, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-slack-classes.ts b/packages/core/src/markdown/rehype-plugins/strip-slack-classes.ts
index ffdb4d5b5..b4be1b2ea 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-slack-classes.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-slack-classes.ts
@@ -1,4 +1,3 @@
-
import type { Element, ElementContent, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/rehype-plugins/strip-vscode-spans.ts b/packages/core/src/markdown/rehype-plugins/strip-vscode-spans.ts
index e2a96d1a7..3c8d88b7c 100644
--- a/packages/core/src/markdown/rehype-plugins/strip-vscode-spans.ts
+++ b/packages/core/src/markdown/rehype-plugins/strip-vscode-spans.ts
@@ -1,4 +1,3 @@
-
import type { Element, Root } from 'hast';
import type { Plugin } from 'unified';
diff --git a/packages/core/src/markdown/resolve-image-url.ts b/packages/core/src/markdown/resolve-image-url.ts
index 0389575ac..cf2c9da8e 100644
--- a/packages/core/src/markdown/resolve-image-url.ts
+++ b/packages/core/src/markdown/resolve-image-url.ts
@@ -1,4 +1,3 @@
-
import { isRelativeUrl } from './safe-url.ts';
function isDevDiagnosticContext(): boolean {
diff --git a/packages/core/src/markdown/safe-url.ts b/packages/core/src/markdown/safe-url.ts
index 8be632ba4..4d3250d3a 100644
--- a/packages/core/src/markdown/safe-url.ts
+++ b/packages/core/src/markdown/safe-url.ts
@@ -1,4 +1,3 @@
-
export const SAFE_URL_SCHEMES = ['https', 'http', 'mailto', 'tel', 'ftp', 'sms'] as const;
const SCHEME_ALT = SAFE_URL_SCHEMES.map((s) => `${s}:`).join('|');
diff --git a/packages/core/src/markdown/serialize-helpers.ts b/packages/core/src/markdown/serialize-helpers.ts
index 542204403..46cc6a074 100644
--- a/packages/core/src/markdown/serialize-helpers.ts
+++ b/packages/core/src/markdown/serialize-helpers.ts
@@ -1,4 +1,3 @@
-
import type { Node as PmNode } from '@tiptap/pm/model';
import type { MdxJsxAttribute, MdxJsxExpressionAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
import type { PropDef, SerializeContext } from '../registry/types.ts';
diff --git a/packages/core/src/markdown/single-dollar-math-promoter.ts b/packages/core/src/markdown/single-dollar-math-promoter.ts
index fe73659e6..be97d4d62 100644
--- a/packages/core/src/markdown/single-dollar-math-promoter.ts
+++ b/packages/core/src/markdown/single-dollar-math-promoter.ts
@@ -1,4 +1,3 @@
-
import type { PhrasingContent, Root, Text } from 'mdast';
import type { InlineMath } from 'mdast-util-math';
import { SKIP, visit } from 'unist-util-visit';
diff --git a/packages/core/src/markdown/to-markdown-handlers.ts b/packages/core/src/markdown/to-markdown-handlers.ts
index 94b9afd29..052f4a9fd 100644
--- a/packages/core/src/markdown/to-markdown-handlers.ts
+++ b/packages/core/src/markdown/to-markdown-handlers.ts
@@ -1,4 +1,3 @@
-
import type { Nodes, Parents } from 'mdast';
import type { MdxJsxAttribute, MdxJsxExpressionAttribute, MdxJsxFlowElement } from 'mdast-util-mdx';
import type { Handle, Info, State } from 'mdast-util-to-markdown';
@@ -82,7 +81,7 @@ export const toMarkdownHandlers = {
return result;
}
- return safeText(state, (node.value ?? '').replaceAll('\u00A0', ' '), info);
+ return safeText(state, node.value ?? '', info);
},
emphasis(node, _parent, state, info) {
@@ -822,7 +821,8 @@ function isWhitespaceNumericCharRef(body: string): boolean {
code === 0x0b ||
code === 0x0c ||
code === 0x0d ||
- code === 0x20
+ code === 0x20 ||
+ code === 0xa0
);
}
diff --git a/packages/core/src/markdown/unknown-mdast-guard.ts b/packages/core/src/markdown/unknown-mdast-guard.ts
index c5bfd2386..cd245c38c 100644
--- a/packages/core/src/markdown/unknown-mdast-guard.ts
+++ b/packages/core/src/markdown/unknown-mdast-guard.ts
@@ -1,4 +1,3 @@
-
import type { Root as MdastRoot } from 'mdast';
import type { VFile } from 'vfile';
diff --git a/packages/core/src/markdown/whitespace-char-ref.ts b/packages/core/src/markdown/whitespace-char-ref.ts
index 1b75ba564..d578476a7 100644
--- a/packages/core/src/markdown/whitespace-char-ref.ts
+++ b/packages/core/src/markdown/whitespace-char-ref.ts
@@ -1,7 +1,7 @@
-
const INLINE_WHITESPACE_BY_CODE: ReadonlyMap<number, string> = new Map([
[0x20, ' '],
[0x09, '\t'],
+ [0xa0, '\u00A0'],
]);
function numericCharRefCodePoint(ref: string): number | null {
diff --git a/packages/core/src/markdown/wiki-link-micromark.ts b/packages/core/src/markdown/wiki-link-micromark.ts
index afd9936fe..6dad26200 100644
--- a/packages/core/src/markdown/wiki-link-micromark.ts
+++ b/packages/core/src/markdown/wiki-link-micromark.ts
@@ -17,7 +17,6 @@ declare module 'micromark-util-types' {
}
}
-
const CODE_BANG = 33; // !
const CODE_LBRACKET = 91; // [
const CODE_RBRACKET = 93; // ]
@@ -261,7 +260,6 @@ export function wikiLinkSyntax(): Extension {
};
}
-
function enterWikiLink(this: CompileContext, token: Token) {
this.enter(
{
@@ -387,7 +385,6 @@ export const wikiLinkToMarkdown: {
unsafe: [{ character: '[', inConstruct: ['phrasing'] }],
};
-
const MICROMARK_EXT = wikiLinkSyntax();
export function remarkWikiLink(this: Processor) {
diff --git a/packages/server/src/server-observers.test.ts b/packages/server/src/server-observers.test.ts
index 3d6d1c014..ad6abba14 100644
--- a/packages/server/src/server-observers.test.ts
+++ b/packages/server/src/server-observers.test.ts
@@ -1105,11 +1105,11 @@ describe('Server Observer B — error recovery paths', () => {
__resetBridgeWatchdogForTests();
resetMetrics();
- // Beyond-tolerance fixture (a literal NBSP canonicalizes to a plain
- // space), so a coherent witness pair WOULD qualify for the in-sync
- // residual merge.
+ // Beyond-tolerance fixture (an over-indented list continuation
+ // canonicalizes to the two-space continuation indent), so a coherent
+ // witness pair WOULD qualify for the in-sync residual merge.
const ngRaw =
- '---\ntitle: NG recovery fixture\n---\n\n# Hello\n\nKeeps a\u00A0nbsp byte.\n\nBody text stays.\n';
+ '---\ntitle: NG recovery fixture\n---\n\n# Hello\n\n- item\n over-indented cont\n\nBody text stays.\n';
const doc = new Y.Doc();
const xmlFragment = doc.getXmlFragment('default');
const ytext = doc.getText('source');
@@ -1638,15 +1638,14 @@ describe('Observer A routing — Path B fires iff Y.Text holds unabsorbed change
cleanup();
});
- // Beyond-tolerance fixture: a literal NBSP (U+00A0) canonicalizes to a
- // plain space (the patched remark-prosemirror reserves NBSP as its
- // whitespace sentinel) — a byte divergence normalizeBridge does NOT
- // tolerate. Storage never sanitizes: these bytes must survive in-sync
- // fragment settlements. (Prior fixtures — inline-math `$a + b$`, then the
- // lazy blockquote continuation — were each retired when the engine grew
- // byte-faithful for them.)
+ // Beyond-tolerance fixture: an over-indented list continuation line
+ // canonicalizes to the two-space continuation indent — a byte divergence
+ // normalizeBridge does NOT tolerate. Storage never sanitizes: these bytes
+ // must survive in-sync fragment settlements. (Prior fixtures — inline-math
+ // `$a + b$`, the lazy blockquote continuation, then a literal NBSP — were
+ // each retired when the engine grew byte-faithful for them.)
const NG_RAW =
- '---\ntitle: NG routing fixture\n---\n\n# Hello\n\nKeeps a\u00A0nbsp byte.\n\nBody text stays.\n';
+ '---\ntitle: NG routing fixture\n---\n\n# Hello\n\n- item\n over-indented cont\n\nBody text stays.\n';
test('in-sync doc with beyond-tolerance residual: fragment change preserves NG bytes without a Path B fire', () => {
__resetBridgeWatchdogForTests();
@@ -1681,8 +1680,8 @@ describe('Observer A routing — Path B fires iff Y.Text holds unabsorbed change
// raw byte form (no wholesale canonical rewrite of Y.Text).
const finalText = ytext.toString();
expect(finalText).toContain('User WYSIWYG edit.');
- expect(finalText).toContain('Keeps a\u00A0nbsp byte.');
- expect(finalText).not.toContain('Keeps a nbsp byte.');
+ expect(finalText).toContain('\n over-indented cont');
+ expect(finalText).not.toContain('\n over-indented cont');
expect(finalText).toContain('Body text stays.');
cleanup();
@@ -1747,8 +1746,8 @@ describe('Observer A routing — Path B fires iff Y.Text holds unabsorbed change
});
expect(events1).toHaveLength(0);
expect(getMetrics().observerAResidualMergeRuns).toBe(1);
- expect(ytext.toString()).toContain('Keeps a\u00A0nbsp byte.');
- expect(ytext.toString()).not.toContain('Keeps a nbsp byte.');
+ expect(ytext.toString()).toContain('\n over-indented cont');
+ expect(ytext.toString()).not.toContain('\n over-indented cont');
// Second in-sync fragment edit: the post-merge settlement kept the
// witnesses coherent and beyond tolerance, so this must dispatch the
@@ -1763,8 +1762,8 @@ describe('Observer A routing — Path B fires iff Y.Text holds unabsorbed change
const finalText = ytext.toString();
expect(finalText).toContain('First edit.');
expect(finalText).toContain('Second edit.');
- expect(finalText).toContain('Keeps a\u00A0nbsp byte.');
- expect(finalText).not.toContain('Keeps a nbsp byte.');
+ expect(finalText).toContain('\n over-indented cont');
+ expect(finalText).not.toContain('\n over-indented cont');
cleanup();
});
@@ -1790,7 +1789,7 @@ describe('Observer A routing — Path B fires iff Y.Text holds unabsorbed change
// a no-op updateYFragment would never trigger the short-circuit. Mirrors
// an agent write under a paired origin.
const pairedRaw =
- '---\ntitle: NG routing fixture\n---\n\n# Hello\n\nKeeps a\u00A0nbsp byte.\n\nPaired body.\n';
+ '---\ntitle: NG routing fixture\n---\n\n# Hello\n\n- item\n over-indented cont\n\nPaired body.\n';
// Fixture precondition: pairedRaw is also beyond-tolerance, so the
// coherence flag (not residualInTolerance) is what gates the residual
// merge after the paired write.
diff --git a/patches/@handlewithcare%[email protected] b/patches/@handlewithcare%[email protected]
index fbbcdd94d..2033165b3 100644
--- a/patches/@handlewithcare%[email protected]
+++ b/patches/@handlewithcare%[email protected]
@@ -263,7 +263,7 @@ index 8433f31fff4e82e5fbb0fae2bb8ba1f68cc30f35..617679158b4d2bb7dab2505e5a2ade7c
- const result = schema.text(replaceNewlines(trimLines(String(node.value))));
+ const value = replaceNewlines(trimLines(String(node.value)));
+ if (!value) return null;
-+ const result = schema.text(/^\s+$/.test(value) ? value.replace(/ /g, '\u00A0') : value);
++ const result = schema.text(value);
return result;
},
...handlers,