Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(open-knowledge): preserve line structure in clipboard emission (#2443)

Nick Gomez5973d63aa768
diff --git a/.changeset/clipboard-line-breaks.md b/.changeset/clipboard-line-breaks.md
new file mode 100644
index 000000000..318231ccb
--- /dev/null
+++ b/.changeset/clipboard-line-breaks.md
@@ -0,0 +1,21 @@
+---
+"@inkeep/open-knowledge": patch
+---
+
+Fix copying from the editor dropping line breaks when you paste into other apps.
+
+Soft line breaks — the everyday single-newline wraps inside a paragraph,
+blockquote, or list item — used to be copied as a bare newline whose rendering
+relied on the editor's own styling. Gmail and other rich-text destinations strip
+that styling, so the lines merged into one on paste. They now copy as real line
+breaks that survive everywhere. Copying a partial selection that contained a
+`<br>` line break used to fail silently and paste as raw markdown source
+(pipes, dashes, and literal `<br>` text); those breaks now come through as
+proper line breaks too.
+
+Multi-line table cells also copy correctly to spreadsheets: a cell with an
+in-cell line break is exported as a quoted field so Excel and Google Sheets keep
+both lines in one cell instead of merging them or splitting the row.
+
+Checked items in a task list now keep their checked state when copied, so a
+ticked checkbox no longer pastes as unticked in apps that preserve checkboxes.
diff --git a/packages/app/src/editor/clipboard/clipboard-line-structure.test.ts b/packages/app/src/editor/clipboard/clipboard-line-structure.test.ts
new file mode 100644
index 000000000..79d39097a
--- /dev/null
+++ b/packages/app/src/editor/clipboard/clipboard-line-structure.test.ts
@@ -0,0 +1,779 @@
+/**
+ * Clipboard line-structure contract (WYSIWYG app tier): emission preserves
+ * user-visible line structure in a destination-robust form.
+ *
+ * Domain invariant: every user-visible line break in the editor must be
+ * encoded STRUCTURALLY (a `<br>` element or a block boundary) in the emitted
+ * `text/html`. Foreign destinations (Gmail, Slack/Quill, Docs, Notion) are not
+ * obligated to preserve the editor's inline `white-space` value or a raw `\n`
+ * in character data — both collapse to a single space under default HTML
+ * whitespace folding. The destination-robust carrier is a real `<br>`.
+ *
+ * The oracle here is DESTINATION-robust on purpose. It does NOT assert "the
+ * emitted HTML carries `white-space: break-spaces`" — that would GREEN-wash the
+ * bug, because the whole failure is that destinations drop that style. Instead
+ * `visibleLines()` models default whitespace folding (`white-space: normal`,
+ * ignoring inline styles): text-node whitespace runs collapse to a space,
+ * `<br>` and block boundaries become line breaks. A break "survives" only if
+ * the two user lines land on different visible lines under that model.
+ *
+ * Substrate: this file needs raw DOM globals for a real ProseMirror EditorView
+ * plus the markdown-tier's `DOMParser` — but no React runtime — so it installs
+ * jsdom in beforeAll and RESTORES the previous globals in afterAll (sibling
+ * unit-tier files rely on the no-DOM contract). Same pattern as
+ * `binding-staleness-guard.test.ts`.
+ *
+ * Sites covered:
+ * S1 walker tier — soft breaks (raw `\n` in a paragraph / blockquote / list
+ * item) must not depend on an inline `white-space` style to render, and
+ * code-block newlines must stay verbatim (never promoted to `<br>`).
+ * S3 reachability — the app clipboard emitter must not ship an empty (or
+ * break-dropped) text/html flavor when the markdown tier meets a void
+ * `<br>` (pre-fix `markdownToHtml` crashed / empty-spanned it).
+ * S5 CellSelection text/plain — a multi-line cell must emit a line
+ * separator, not `"line1line2"`; special-character cells follow the
+ * RFC 4180 quoting rules.
+ * S6 non-regression pins (green before and after the fix): whole-table
+ * walker copy keeps `<br>` in cells; paragraph boundaries stay separate
+ * lines (oracle validity).
+ * S7 OK→OK paste round-trip (green before and after the fix) — the
+ * CONSUMER side of the S1/S2 emission fix. A signal-less soft-break
+ * paragraph ("alpha\nbeta") carries no markdown signal, so OK→OK paste
+ * bypasses the markdown-first tiebreak (handle-paste.ts Branch B) and
+ * lands on Branch C: PM-native parse of the emitted `text/html`. The
+ * emission fix changed that `text/html` from a raw `\n` to a real
+ * `<br>`; this pins that the round-trip still preserves the two lines
+ * (PM's clipboard parse turns both the raw `\n` and the `<br>` into a
+ * hardBreak inside the `data-pm-slice` context — verified). No
+ * emission-only test observes the paste side, so an emission change
+ * could silently merge/corrupt the round-trip with nothing noticing.
+ */
+
+import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
+import { MarkdownManager } from '@inkeep/open-knowledge-core';
+import { getSchema } from '@tiptap/core';
+import type { Node as PmNode } from '@tiptap/pm/model';
+import { AllSelection, EditorState, type TextSelection } from '@tiptap/pm/state';
+import { CellSelection, TableMap } from '@tiptap/pm/tables';
+import { EditorView } from '@tiptap/pm/view';
+import { JSDOM } from 'jsdom';
+import { sharedExtensions } from '../extensions/shared';
+import {
+ reflectCheckboxCheckedState,
+ walkLiveDomToInlineStyledFragment,
+} from './clipboard-walker.ts';
+import { detectSource } from './detect-source.ts';
+import { createHandlePaste } from './handle-paste.ts';
+import { isMarkdown } from './is-markdown.ts';
+import {
+ createClipboardHtmlSerializer,
+ createClipboardTextSerializer,
+ serializeCellSelectionAsText,
+} from './serialize.ts';
+import { __resetShiftTrackerForTests } from './shift-tracker.ts';
+
+// ---------------------------------------------------------------------------
+// jsdom substrate (scoped to this file — restored in afterAll)
+// ---------------------------------------------------------------------------
+
+function installDomGlobals(): () => void {
+ const dom = new JSDOM('<!DOCTYPE html><html><head></head><body></body></html>', {
+ url: 'http://localhost:5173',
+ pretendToBeVisual: true,
+ });
+ const win = dom.window as unknown as Window & typeof globalThis;
+ const installed: Record<string, unknown> = {
+ window: win,
+ document: win.document,
+ HTMLElement: win.HTMLElement,
+ Element: win.Element,
+ Node: win.Node,
+ Document: win.Document,
+ DocumentFragment: win.DocumentFragment,
+ Text: win.Text,
+ Range: win.Range,
+ DOMParser: win.DOMParser,
+ MutationObserver: win.MutationObserver,
+ Event: win.Event,
+ CustomEvent: win.CustomEvent,
+ KeyboardEvent: win.KeyboardEvent,
+ MouseEvent: win.MouseEvent,
+ InputEvent: win.InputEvent,
+ CompositionEvent: win.CompositionEvent,
+ FocusEvent: win.FocusEvent,
+ getComputedStyle: win.getComputedStyle.bind(win),
+ requestAnimationFrame: win.requestAnimationFrame.bind(win),
+ cancelAnimationFrame: win.cancelAnimationFrame.bind(win),
+ };
+ const previousDescriptors = new Map<string, PropertyDescriptor | undefined>();
+ const globalRecord = globalThis as unknown as Record<string, unknown>;
+ for (const [key, value] of Object.entries(installed)) {
+ previousDescriptors.set(key, Object.getOwnPropertyDescriptor(globalThis, key));
+ Object.defineProperty(globalThis, key, { value, configurable: true, writable: true });
+ }
+ return () => {
+ for (const [key, descriptor] of previousDescriptors) {
+ if (descriptor) {
+ Object.defineProperty(globalThis, key, descriptor);
+ } else {
+ Reflect.deleteProperty(globalRecord, key);
+ }
+ }
+ dom.window.close();
+ };
+}
+
+let restoreDomGlobals: (() => void) | null = null;
+
+beforeAll(() => {
+ restoreDomGlobals = installDomGlobals();
+});
+
+afterAll(() => {
+ // The S7 tests drive the real paste dispatcher, which lazily attaches the
+ // shift-tracker's singleton listeners to this file's jsdom window. Reset that
+ // shared module state so a sibling clipboard test file (shift-tracker.test.ts)
+ // can re-attach to its own fake window instead of inheriting a dead
+ // attachment (the reset detaches from the exact window it wired).
+ __resetShiftTrackerForTests();
+ restoreDomGlobals?.();
+ restoreDomGlobals = null;
+});
+
+// Silence the structured `clipboard-serialize-failed` telemetry the markdown
+// tier emits when a serialize step throws — the pinned contract is the
+// observable output, not the log line.
+let origWarn: typeof console.warn;
+beforeEach(() => {
+ origWarn = console.warn;
+ console.warn = () => {};
+});
+afterEach(() => {
+ console.warn = origWarn;
+});
+
+// ---------------------------------------------------------------------------
+// Destination-robust oracle: model default HTML whitespace folding
+// ---------------------------------------------------------------------------
+
+const TEXT_NODE = 3;
+const ELEMENT_NODE = 1;
+// Elements that introduce a line boundary in normal flow (a subset sufficient
+// for the constructs under test: paragraphs, blockquotes, lists, tables).
+const BLOCK_TAGS = new Set([
+ 'P',
+ 'DIV',
+ 'LI',
+ 'UL',
+ 'OL',
+ 'BLOCKQUOTE',
+ 'H1',
+ 'H2',
+ 'H3',
+ 'H4',
+ 'H5',
+ 'H6',
+ 'TABLE',
+ 'THEAD',
+ 'TBODY',
+ 'TR',
+ 'TD',
+ 'TH',
+ 'PRE',
+ 'SECTION',
+ 'ARTICLE',
+ 'HR',
+]);
+
+/**
+ * Render `node` the way a destination with default UA styles (and NO honoring
+ * of inline `white-space`) would fold it into visible lines: whitespace runs in
+ * text (including a raw `\n`) collapse to a single space; `<br>` and block
+ * boundaries become newlines. Returns the non-empty, trimmed visible lines.
+ */
+function visibleLines(node: Node): string[] {
+ let buf = '';
+ const walk = (n: Node): void => {
+ if (n.nodeType === TEXT_NODE) {
+ buf += (n.nodeValue ?? '').replace(/[\t\r\n\f ]+/g, ' ');
+ return;
+ }
+ if (n.nodeType === ELEMENT_NODE) {
+ const el = n as Element;
+ if (el.tagName.toUpperCase() === 'BR') {
+ buf += '\n';
+ return;
+ }
+ const isBlock = BLOCK_TAGS.has(el.tagName.toUpperCase());
+ if (isBlock) buf += '\n';
+ for (const child of Array.from(el.childNodes)) walk(child);
+ if (isBlock) buf += '\n';
+ return;
+ }
+ // Container nodes (DocumentFragment / Document) carry no visible text of
+ // their own — descend into their children. The clipboard emitter returns a
+ // DocumentFragment, so the walk root is usually one of these.
+ for (const child of Array.from(n.childNodes)) walk(child);
+ };
+ walk(node);
+ return buf
+ .split('\n')
+ .map((l) => l.trim())
+ .filter((l) => l.length > 0);
+}
+
+/** Assert `first` and `second` render on DIFFERENT visible lines. */
+function expectSeparateLines(root: Node, first: string, second: string): void {
+ const lines = visibleLines(root);
+ const iFirst = lines.findIndex((l) => l.includes(first));
+ const iSecond = lines.findIndex((l) => l.includes(second));
+ // Both lines present…
+ expect(iFirst).toBeGreaterThanOrEqual(0);
+ expect(iSecond).toBeGreaterThanOrEqual(0);
+ // …and `second` renders on a LATER visible line than `first`. A payload
+ // carrying the break as a raw `\n` collapses to a space and both land on
+ // the same line (iSecond === iFirst) — the defect this asserts against.
+ expect(iSecond).toBeGreaterThan(iFirst);
+}
+
+// ---------------------------------------------------------------------------
+// Harness — real schema + real EditorView + the production clipboard serializer
+// ---------------------------------------------------------------------------
+
+const schema = getSchema(sharedExtensions);
+const mdManager = new MarkdownManager({ extensions: sharedExtensions });
+
+/** Parse markdown into a real PM doc node via the canonical manager. */
+function docFromMarkdown(md: string): PmNode {
+ return schema.nodeFromJSON(mdManager.parse(md));
+}
+
+/** Mount a real EditorView for `doc` on a fresh container in document.body. */
+function mountView(doc: PmNode): EditorView {
+ const mount = document.createElement('div');
+ document.body.appendChild(mount);
+ return new EditorView(mount, { state: EditorState.create({ schema, doc }) });
+}
+
+/** Drive the production text/html serializer over a whole-doc selection. */
+function emitClipboardHtml(view: EditorView): DocumentFragment | HTMLElement {
+ const handle = createClipboardHtmlSerializer({ mdManager });
+ handle.setView(view);
+ view.dispatch(view.state.tr.setSelection(new AllSelection(view.state.doc)));
+ const target = document.createDocumentFragment();
+ return handle.serializer.serializeFragment(
+ view.state.selection.content().content,
+ undefined,
+ target,
+ );
+}
+
+describe('S1 — walker tier: soft breaks survive without relying on inline white-space', () => {
+ // Whole-block WYSIWYG selections route to the live-DOM walker. A soft break
+ // (single `\n` in a text node) is cloned verbatim and its rendering rides on
+ // the editor's `white-space` value — which the destination may strip.
+
+ test('a soft-break paragraph keeps its two lines apart in the emitted text/html', () => {
+ const view = mountView(docFromMarkdown('alpha\nbeta'));
+ try {
+ const result = emitClipboardHtml(view);
+ expectSeparateLines(result, 'alpha', 'beta');
+ } finally {
+ view.destroy();
+ }
+ });
+
+ test('a soft break inside a blockquote survives', () => {
+ const view = mountView(docFromMarkdown('> alpha\n> beta'));
+ try {
+ const result = emitClipboardHtml(view);
+ expectSeparateLines(result, 'alpha', 'beta');
+ } finally {
+ view.destroy();
+ }
+ });
+
+ test('a soft break inside a list item survives', () => {
+ const view = mountView(docFromMarkdown('- alpha\n beta'));
+ try {
+ const result = emitClipboardHtml(view);
+ expectSeparateLines(result, 'alpha', 'beta');
+ } finally {
+ view.destroy();
+ }
+ });
+
+ test('inline white-space is NOT destination-robust: break-spaces alone still loses the line', () => {
+ // Anti-GREEN-wash pin. Drive the walker with the PRODUCTION computed value
+ // (`white-space: break-spaces`, as captured from the live editor). The
+ // emitted <p> then literally carries that style AND a raw `\n`. A test that
+ // asserted the style is present would pass — but under default whitespace
+ // folding (a destination that drops the style) the two lines still merge.
+ const view = mountView(docFromMarkdown('alpha\nbeta'));
+ try {
+ view.dispatch(view.state.tr.setSelection(new AllSelection(view.state.doc)));
+ const env = {
+ getComputedStyle: () => ({
+ getPropertyValue: (p: string) => (p === 'white-space' ? 'break-spaces' : ''),
+ }),
+ };
+ const frag = walkLiveDomToInlineStyledFragment(view.state.selection.content(), view, env);
+ expectSeparateLines(frag, 'alpha', 'beta');
+ } finally {
+ view.destroy();
+ }
+ });
+
+ test('code-block newlines are NOT promoted to <br> — significant whitespace stays verbatim', () => {
+ // Boundary of the soft-break promotion: inside `<pre>`/`<code>` a `\n` is
+ // significant whitespace every destination already preserves, and a `<br>`
+ // there is invisible to textContent-based readers — so the walker must
+ // skip those subtrees entirely.
+ const view = mountView(docFromMarkdown('```\nline1\nline2\n```'));
+ try {
+ const result = emitClipboardHtml(view);
+ const wrapper = document.createElement('div');
+ wrapper.appendChild(result);
+ const pre = wrapper.querySelector('pre');
+ expect(pre).not.toBeNull();
+ expect(wrapper.querySelector('pre br')).toBeNull();
+ expect(pre?.textContent ?? '').toContain('line1\nline2');
+ } finally {
+ view.destroy();
+ }
+ });
+});
+
+describe('S3 — reachability: the app emitter never ships a break-dropped text/html on a void <br>', () => {
+ // Partial-block selections / drag-out route to the markdown tier
+ // (`sliceToMarkdown` → `markdownToHtml`). A slice carrying an html-style
+ // hardBreak serializes to a literal `<br>`, which pre-fix made
+ // `markdownToHtml` either crash (unclosed `<br>` → whole flavor swallowed)
+ // or empty-span the break (`<br/>`). The contract is pinned at the emitter
+ // boundary so a change that reroutes the callsite still has to satisfy it.
+
+ test('an unclosed <br> fragment yields a NON-EMPTY text/html with the break intact', () => {
+ const doc = docFromMarkdown('alpha<br>beta');
+ const handle = createClipboardHtmlSerializer({ mdManager });
+ // No view attached → the markdown tier fires (the drag-out / partial path).
+ const target = document.createDocumentFragment();
+ const result = handle.serializer.serializeFragment(doc.content, undefined, target);
+ // Pre-fix: markdownToHtml threw, the catch swallowed it, text/html
+ // shipped empty (childNodes === 0) and destinations fell back to raw
+ // markdown.
+ expect(result.childNodes.length).toBeGreaterThan(0);
+ expectSeparateLines(result, 'alpha', 'beta');
+ // …and the break is a real element, not character-data whitespace.
+ const wrapper = document.createElement('div');
+ wrapper.appendChild(result);
+ expect(wrapper.querySelector('br')).not.toBeNull();
+ });
+
+ test('a self-closing <br/> fragment keeps the break (not an empty mdx-inline span)', () => {
+ const doc = docFromMarkdown('alpha<br/>beta');
+ const handle = createClipboardHtmlSerializer({ mdManager });
+ const target = document.createDocumentFragment();
+ const result = handle.serializer.serializeFragment(doc.content, undefined, target);
+ // Pre-fix: non-empty, but the break rendered as `<span class="mdx-inline"></span>`
+ // — an empty span — so the two lines merged in the destination.
+ expectSeparateLines(result, 'alpha', 'beta');
+ const wrapper = document.createElement('div');
+ wrapper.appendChild(result);
+ expect(wrapper.querySelector('span.mdx-inline:empty')).toBeNull();
+ });
+});
+
+// ---------------------------------------------------------------------------
+// S5 — CellSelection text/plain multi-line cells
+// ---------------------------------------------------------------------------
+
+function cellNode(inline: PmNode[], header = false): PmNode {
+ const cellType = header ? schema.nodes.tableHeader : schema.nodes.tableCell;
+ return cellType.createChecked(null, schema.nodes.paragraph.create(null, inline));
+}
+
+/** Build an EditorState carrying a CellSelection over the given anchor→head cells. */
+function tableStateWithCells(
+ rows: PmNode[][],
+ anchor: [number, number],
+ head: [number, number],
+): EditorState {
+ const table = schema.nodes.table.createChecked(
+ null,
+ rows.map((cells) => schema.nodes.tableRow.createChecked(null, cells)),
+ );
+ const doc = schema.nodes.doc.create(null, table);
+ const state = EditorState.create({ schema, doc });
+ const tableStart = 1;
+ const map = TableMap.get(table);
+ const anchorPos = map.positionAt(anchor[0], anchor[1], table) + tableStart;
+ const headPos = map.positionAt(head[0], head[1], table) + tableStart;
+ const selection = new CellSelection(state.doc.resolve(anchorPos), state.doc.resolve(headPos));
+ return state.apply(state.tr.setSelection(selection as unknown as TextSelection));
+}
+
+/** A multi-line cell body: `line1` + hardBreak + `line2`. */
+function multiLineInline(a: string, b: string): PmNode[] {
+ return [schema.text(a), schema.nodes.hardBreak.create(), schema.text(b)];
+}
+
+describe('serializeCellSelectionAsText — multi-line cells emit a line separator', () => {
+ // The existing suite pins the spreadsheet convention: `\t` between cells,
+ // `\n` between rows, single-line cells UNQUOTED. A cell that itself contains
+ // a line break needs a form whose embedded newline is NOT confused with the
+ // row separator. The defensible, standard encoding is the Excel / Google
+ // Sheets clipboard-TSV rule (RFC 4180 §2.5-2.7 applied with `\t` as the
+ // delimiter): a field containing a newline (or tab, or quote) is wrapped in
+ // double quotes, internal quotes doubled. So `line1<br>line2` → `"line1\nline2"`.
+ // Pre-fix `serializeCellSelectionAsText` pushed bare `cell.textContent`, and
+ // PM renders a hardBreak as the empty string — the two lines
+ // flush-concatenated.
+
+ test('a single multi-line cell is quoted with its embedded newline preserved', () => {
+ const state = tableStateWithCells(
+ [[cellNode([schema.text('H')], true)], [cellNode(multiLineInline('line1', 'line2'))]],
+ [1, 0],
+ [1, 0],
+ );
+ const text = serializeCellSelectionAsText(state.selection as CellSelection);
+ // Pre-fix: "line1line2" (flush-concatenated, break gone).
+ expect(text).toBe('"line1\nline2"');
+ });
+
+ test('a multi-line cell alongside a plain cell stays disambiguated from the row separator', () => {
+ const state = tableStateWithCells(
+ [
+ [cellNode([schema.text('H1')], true), cellNode([schema.text('H2')], true)],
+ [cellNode(multiLineInline('a', 'b')), cellNode([schema.text('plain')])],
+ ],
+ [1, 0],
+ [1, 1],
+ );
+ const text = serializeCellSelectionAsText(state.selection as CellSelection);
+ // The multi-line cell is quoted (its `\n` is not a row break); the plain
+ // cell is unquoted; a tab separates them. Pre-fix: "ab\tplain".
+ expect(text).toBe('"a\nb"\tplain');
+ });
+
+ test('a cell containing a tab is quoted so the tab is not read as a column boundary', () => {
+ const state = tableStateWithCells(
+ [[cellNode([schema.text('H')], true)], [cellNode([schema.text('col1\tcol2')])]],
+ [1, 0],
+ [1, 0],
+ );
+ const text = serializeCellSelectionAsText(state.selection as CellSelection);
+ // Unquoted, the embedded tab would split this one cell across two columns
+ // in every spreadsheet paste handler.
+ expect(text).toBe('"col1\tcol2"');
+ });
+
+ test('a cell containing a double quote is quoted with the quote doubled (RFC 4180 §2.7)', () => {
+ const state = tableStateWithCells(
+ [[cellNode([schema.text('H')], true)], [cellNode([schema.text('say "hi"')])]],
+ [1, 0],
+ [1, 0],
+ );
+ const text = serializeCellSelectionAsText(state.selection as CellSelection);
+ // An undoubled internal quote breaks TSV field-boundary parsing.
+ expect(text).toBe('"say ""hi"""');
+ });
+
+ test('a cell that is a single double quote encodes to the RFC 4180 degenerate quad-quote form', () => {
+ // The minimal quoting boundary: content of exactly one quote wraps in
+ // quotes (2) with the one internal quote doubled (2) = four quotes total.
+ // Guards the encodeTsvField branch against an off-by-one in quote-doubling.
+ const state = tableStateWithCells(
+ [[cellNode([schema.text('H')], true)], [cellNode([schema.text('"')])]],
+ [1, 0],
+ [1, 0],
+ );
+ const text = serializeCellSelectionAsText(state.selection as CellSelection);
+ expect(text).toBe('""""');
+ });
+});
+
+describe('S6 — non-regression pins (green before and after the fix)', () => {
+ test('whole-table walker copy keeps a real <br> inside a multi-line cell', () => {
+ // The whole-table (non-CellSelection) copy routes to the walker, which
+ // clones the live DOM where PM already rendered the hardBreak as `<br>`.
+ // This is correct today and must stay correct.
+ const view = mountView(docFromMarkdown('| a |\n| - |\n| left<br>right |'));
+ try {
+ const result = emitClipboardHtml(view);
+ const wrapper = document.createElement('div');
+ wrapper.appendChild(result);
+ expect(wrapper.querySelector('td br, th br')).not.toBeNull();
+ // And the two in-cell lines are genuinely separate under the oracle.
+ expectSeparateLines(wrapper, 'left', 'right');
+ } finally {
+ view.destroy();
+ }
+ });
+
+ test('oracle validity: a real paragraph boundary already renders as two separate lines', () => {
+ // Guards the oracle itself: two blank-line-separated paragraphs are a
+ // legitimate block boundary and MUST read as separate lines (GREEN). If
+ // this ever went red the oracle would be trivially failing every input.
+ const view = mountView(docFromMarkdown('alpha\n\nbeta'));
+ try {
+ const result = emitClipboardHtml(view);
+ expectSeparateLines(result, 'alpha', 'beta');
+ } finally {
+ view.destroy();
+ }
+ });
+});
+
+// ---------------------------------------------------------------------------
+// S7 — OK→OK paste round-trip (the CONSUMER side of the emission fix)
+// ---------------------------------------------------------------------------
+
+/**
+ * Emit the two clipboard flavors OK actually writes for a whole-doc selection,
+ * exactly as production does:
+ * - `text/html` via the walker-first `clipboardSerializer.serializeFragment`,
+ * then the `data-pm-slice` attribute stamped on the first element the way
+ * PM's `serializeForClipboard` does downstream (see serialize.ts header).
+ * That attribute is what routes an OK→OK paste to Branch C.
+ * - `text/plain` via the production `clipboardTextSerializer` (markdown).
+ */
+function emitFlavors(md: string): { html: string; plain: string } {
+ const view = mountView(docFromMarkdown(md));
+ try {
+ view.dispatch(view.state.tr.setSelection(new AllSelection(view.state.doc)));
+ const slice = view.state.selection.content();
+
+ const htmlHandle = createClipboardHtmlSerializer({ mdManager });
+ htmlHandle.setView(view);
+ const frag = htmlHandle.serializer.serializeFragment(
+ slice.content,
+ undefined,
+ document.createDocumentFragment(),
+ );
+ const holder = document.createElement('div');
+ holder.appendChild(frag as Node);
+ // Reproduce PM's serializeForClipboard: it stamps data-pm-slice on the
+ // first element of whatever the serializer returns. `0 0 []` = a complete
+ // block, no open ends, no surrounding context (a whole-paragraph copy).
+ holder.firstElementChild?.setAttribute('data-pm-slice', '0 0 []');
+ const html = holder.innerHTML;
+
+ const textSerializer = createClipboardTextSerializer({ mdManager });
+ const plain = textSerializer(slice, view);
+ return { html, plain };
+ } finally {
+ view.destroy();
+ }
+}
+
+/**
+ * A DataTransfer/ClipboardEvent stand-in carrying the two flavors. The paste
+ * dispatcher only touches `clipboardData.types` / `.getData(mime)` and
+ * `pasteShiftHeld(event)` (which reads `event.shiftKey` — absent here, so
+ * false), so a plain object is a faithful driver.
+ */
+function fakeClipboardEvent(plain: string, html: string): ClipboardEvent {
+ const dt = {
+ types: ['text/plain', 'text/html'],
+ getData: (mime: string) => (mime === 'text/plain' ? plain : mime === 'text/html' ? html : ''),
+ };
+ return { clipboardData: dt } as unknown as ClipboardEvent;
+}
+
+/** Mount a paste target wired with the production paste dispatcher. */
+function mountPasteTarget(): EditorView {
+ const mount = document.createElement('div');
+ document.body.appendChild(mount);
+ return new EditorView(mount, {
+ state: EditorState.create({ schema, doc: docFromMarkdown('placeholder') }),
+ handlePaste: createHandlePaste({ mdManager }),
+ });
+}
+
+/**
+ * Drive the real OK→OK paste for a signal-less payload. `pasteHTML` runs PM's
+ * `doPaste`: it parses the `text/html` via `parseFromClipboard`, calls the
+ * wired dispatcher (which returns false for Branch C — verified separately),
+ * then inserts the parsed slice. The returned doc is what actually landed.
+ */
+function pasteOkToOk(plain: string, html: string): PmNode {
+ const dest = mountPasteTarget();
+ try {
+ dest.dispatch(dest.state.tr.setSelection(new AllSelection(dest.state.doc)));
+ dest.pasteHTML(html, fakeClipboardEvent(plain, html));
+ return dest.state.doc;
+ } finally {
+ dest.destroy();
+ }
+}
+
+/**
+ * Fold the PASTED PM document into visible lines. Unlike `visibleLines` (which
+ * models a foreign destination folding emitted HTML), this reads the intended
+ * line structure of OK's own doc: a `hardBreak` node AND a literal `\n` inside
+ * a text node BOTH count as a line carrier, and block boundaries separate
+ * lines. So the contract is line structure, not node identity — either carrier
+ * passes; only a merged single text run ("alpha beta" / "alphabeta") fails.
+ */
+function pastedDocLines(doc: PmNode): string[] {
+ const lines: string[] = [];
+ let cur = '';
+ const flush = (): void => {
+ const trimmed = cur.trim();
+ if (trimmed.length > 0) lines.push(trimmed);
+ cur = '';
+ };
+ doc.descendants((node) => {
+ if (node.isText) {
+ const parts = (node.text ?? '').split('\n');
+ cur += parts[0];
+ for (let i = 1; i < parts.length; i++) {
+ flush();
+ cur += parts[i];
+ }
+ return false;
+ }
+ if (node.type.name === 'hardBreak') {
+ flush();
+ return false;
+ }
+ if (node.isBlock) {
+ flush();
+ return true;
+ }
+ return true;
+ });
+ flush();
+ return lines;
+}
+
+/** Assert the pasted doc keeps `first` and `second` on different visible lines. */
+function expectPastedSeparateLines(doc: PmNode, first: string, second: string): void {
+ const lines = pastedDocLines(doc);
+ const iFirst = lines.findIndex((l) => l.includes(first));
+ const iSecond = lines.findIndex((l) => l.includes(second));
+ expect(iFirst).toBeGreaterThanOrEqual(0);
+ expect(iSecond).toBeGreaterThanOrEqual(0);
+ // A merge (`alpha beta` collapsed to one text run) lands both on the same
+ // line (iSecond === iFirst) — the round-trip corruption this pins against.
+ expect(iSecond).toBeGreaterThan(iFirst);
+}
+
+describe('S7 — OK→OK paste round-trip: signal-less soft break (GREEN non-regression pin)', () => {
+ // Green before and after the emission fix, which changed the emitted
+ // `text/html` for a soft break from a raw `\n` to a `<br>`; because a
+ // signal-less soft-break paragraph routes to Branch C (PM-native parse of
+ // that `text/html`), this is the surface where the `<br>` emission is
+ // CONSUMED. Empirically PM's clipboard parse maps BOTH the raw `\n`
+ // (pre-fix) and the `<br>` (post-fix), inside the `data-pm-slice` context,
+ // to a hardBreak — so the two lines survive either way. The pin guards that
+ // an emission change does not silently regress the round-trip (merge lines
+ // / drop the break), which no emission-only test would notice.
+
+ test('routes to Branch C (PM-native), not the markdown tiebreak', () => {
+ // The dispatch decision itself: the payload must be signal-less (so Branch B
+ // does not claim it) yet carry `data-pm-slice` (so Branch C does).
+ const { html, plain } = emitFlavors('alpha\nbeta');
+ const event = fakeClipboardEvent(plain, html);
+ const dt = event.clipboardData as unknown as DataTransfer;
+
+ expect(detectSource(dt)).toBe('pm-origin'); // data-pm-slice present
+ expect(isMarkdown(plain)).toBe(false); // signal-less → the Branch B tiebreak cannot fire
+
+ // Branch C returns false so PM parses the text/html natively. A throwaway
+ // view — the dispatcher does not mutate when it declines.
+ const probe = mountView(docFromMarkdown('placeholder'));
+ try {
+ const handled = createHandlePaste({ mdManager })(probe, event);
+ expect(handled).toBe(false);
+ } finally {
+ probe.destroy();
+ }
+ });
+
+ test('copy→paste keeps the two lines separate (soft break or hardBreak carrier)', () => {
+ const { html, plain } = emitFlavors('alpha\nbeta');
+ const pasted = pasteOkToOk(plain, html);
+
+ // Binding contract: the two lines are NOT merged. Accepts either carrier.
+ expectPastedSeparateLines(pasted, 'alpha', 'beta');
+
+ // Companion observation (non-binding on the contract): a real structural
+ // break carrier exists — a hardBreak node, identical pre- and post-fix.
+ // `textContent` flattens the hardBreak to "" (→ "alphabeta"), so
+ // we assert it did NOT collapse to a single space-joined run ("alpha beta"),
+ // the Branch-D-style merge, and that a carrier node/newline is present.
+ expect(pasted.textContent).not.toBe('alpha beta');
+ let hasCarrier = false;
+ pasted.descendants((node) => {
+ if (node.type.name === 'hardBreak') hasCarrier = true;
+ if (node.isText && (node.text ?? '').includes('\n')) hasCarrier = true;
+ return true;
+ });
+ expect(hasCarrier).toBe(true);
+ });
+});
+
+describe('S10 — task checkbox checked-state survives the walker clone', () => {
+ // The taskItem NodeView sets the checkbox state as a live DOM PROPERTY
+ // (input.checked), never a `checked` attribute — so cloneNode(true), which
+ // copies only attributes, drops it and a checked item pastes unchecked.
+ // reflectCheckboxCheckedState recovers it from the paired live element.
+ //
+ // The reflection is unit-tested directly against a hand-built input rather
+ // than end-to-end through the serializer: the harness mounts a bare
+ // `new EditorView` with no nodeViews, so it renders task items via the
+ // schema's toDOM (which DOES emit the `checked` attribute) — an end-to-end
+ // test would clone the attribute path and green-wash the property-only bug.
+
+ test('a checked checkbox reflects its live property onto the clone attribute', () => {
+ const input = document.createElement('input');
+ input.type = 'checkbox';
+ input.checked = true;
+ const clone = input.cloneNode(true) as HTMLInputElement;
+ // Pre-condition (the bug): the attribute-only clone lost the property state.
+ expect(clone.hasAttribute('checked')).toBe(false);
+
+ reflectCheckboxCheckedState(input, clone);
+ expect(clone.getAttribute('checked')).toBe('');
+ });
+
+ test('an unchecked checkbox leaves no checked attribute on the clone', () => {
+ const input = document.createElement('input');
+ input.type = 'checkbox';
+ input.checked = false;
+ const clone = input.cloneNode(true) as HTMLInputElement;
+ reflectCheckboxCheckedState(input, clone);
+ expect(clone.hasAttribute('checked')).toBe(false);
+ });
+
+ test('an unchecked checkbox removes a pre-existing checked attribute from the clone', () => {
+ const input = document.createElement('input');
+ input.type = 'checkbox';
+ input.checked = false;
+ const clone = input.cloneNode(true) as HTMLInputElement;
+ // Simulate the toDOM path: `checked` emitted as an attribute, but the live
+ // property has since diverged to false — the reflection must REMOVE it.
+ clone.setAttribute('checked', '');
+ expect(clone.hasAttribute('checked')).toBe(true);
+
+ reflectCheckboxCheckedState(input, clone);
+ expect(clone.hasAttribute('checked')).toBe(false);
+ });
+
+ test('a non-checkbox input is left untouched', () => {
+ const input = document.createElement('input');
+ input.type = 'text';
+ input.value = 'hello';
+ const clone = input.cloneNode(true) as HTMLInputElement;
+ reflectCheckboxCheckedState(input, clone);
+ expect(clone.hasAttribute('checked')).toBe(false);
+ });
+
+ test('a non-input element is left untouched', () => {
+ const div = document.createElement('div');
+ const clone = div.cloneNode(true) as HTMLElement;
+ reflectCheckboxCheckedState(div, clone);
+ expect(clone.hasAttribute('checked')).toBe(false);
+ });
+});
diff --git a/packages/app/src/editor/clipboard/clipboard-walker.ts b/packages/app/src/editor/clipboard/clipboard-walker.ts
index c985ee049..0c9ab1649 100644
--- a/packages/app/src/editor/clipboard/clipboard-walker.ts
+++ b/packages/app/src/editor/clipboard/clipboard-walker.ts
@@ -24,10 +24,14 @@
* on its React render root. The walker drops that subtree from the output.
*
* Cardinality discipline: the style allowlist is hand-curated to email-safe
- * properties (Notion / Slack / Gmail rich-paste profiles all preserve them).
- * The class blocklist strips selection halo / drag chrome / ProseMirror
- * internals. The attribute blocklist strips `contenteditable` and PM-internal
- * markers so destinations don't see editor-only state.
+ * properties that survive at least one mainstream rich-paste profile (Notion /
+ * Slack / Gmail / GitHub). Not every property survives every destination —
+ * `white-space` in particular is dropped by Slack (stock Quill) and Gmail-class
+ * sanitizers, so line structure is NOT left to ride on it: soft breaks are
+ * promoted to structural `<br>` elements (`promoteSoftBreaksToBr`) before
+ * emission. The class blocklist strips selection halo / drag chrome /
+ * ProseMirror internals. The attribute blocklist strips `contenteditable` and
+ * PM-internal markers so destinations don't see editor-only state.
*/
import { normalizeNullableString, wikiLinkHref } from '@inkeep/open-knowledge-core';
@@ -63,9 +67,12 @@ import { nonPortableRenderSourceFallback } from './non-portable-render-source-fa
/**
* CSS properties copied inline from the live element to the clone. Curated for
* the Slack / Notion / Gmail / GitHub rich-paste profiles — everything in this
- * list survives at least one of the four. Layout / transform / animation
- * properties are intentionally excluded: destinations rebuild layout, and
- * inlining them across an arbitrary snippet would yield broken visuals.
+ * list survives at least one of the four. `white-space` is kept for visual
+ * fidelity but is NOT relied on for line structure (several destinations drop
+ * it — see header); soft breaks are carried structurally by `<br>` instead
+ * (`promoteSoftBreaksToBr`). Layout / transform / animation properties are
+ * intentionally excluded: destinations rebuild layout, and inlining them across
+ * an arbitrary snippet would yield broken visuals.
*/
export const STYLE_ALLOWLIST = [
'color',
@@ -378,9 +385,51 @@ function cloneAndStyle(live: Element, env: WalkerEnv): Element {
// every SVG above, so defense-in-depth on stray `lucide-` SVGs is
// preserved regardless of the lucide-replace position.
replaceLucideIconsWithGlyphs(clone);
+ // Structuralize soft line breaks LAST, after every source-fallback pass has
+ // synthesized its `mdx-inline` spans (single-line source text) and `<pre>`
+ // source blocks — running last means those already exist, the `<pre>`/`<code>`
+ // guard skips the source blocks, and a just-inserted `<br>` can't be flattened
+ // by the earlier wiki-link `textContent` copy.
+ promoteSoftBreaksToBr(clone);
return clone;
}
+/**
+ * Promote soft line breaks (a literal `\n` inside a cloned text node) to real
+ * `<br>` elements. PM renders these `\n`-carried breaks visually only via the
+ * editor's `white-space` CSS, which mainstream destinations drop (see header) —
+ * folding the `\n` to a space and merging the two lines. A `<br>` is
+ * destination-robust. `<pre>` / `<code>` subtrees are skipped: there the `\n`
+ * is significant whitespace the destination preserves verbatim (a PM code block
+ * renders it directly), so converting would double the break. Hard breaks are
+ * already real `<br>` elements in the live DOM, so they pass through untouched —
+ * only `\n`-in-text is rewritten, never an existing `<br>`.
+ */
+function promoteSoftBreaksToBr(root: Element): void {
+ const doc = root.ownerDocument;
+ const visit = (el: Element): void => {
+ const tag = el.tagName.toUpperCase();
+ if (tag === 'PRE' || tag === 'CODE') return;
+ // Snapshot children — the loop mutates `el`'s child list via `replaceWith`.
+ for (const child of Array.from(el.childNodes)) {
+ if (child.nodeType === Node.TEXT_NODE) {
+ const value = child.nodeValue ?? '';
+ if (!value.includes('\n')) continue;
+ const parts = value.split('\n');
+ const replacement = doc.createDocumentFragment();
+ for (let i = 0; i < parts.length; i++) {
+ if (i > 0) replacement.appendChild(doc.createElement('br'));
+ if (parts[i].length > 0) replacement.appendChild(doc.createTextNode(parts[i]));
+ }
+ child.replaceWith(replacement);
+ } else if (child.nodeType === Node.ELEMENT_NODE) {
+ visit(child as Element);
+ }
+ }
+ };
+ visit(root);
+}
+
/**
* Walk the cloned subtree for non-portable inline PM atoms and replace
* each with a `<span class="mdx-inline">{markdown source}</span>`
@@ -566,6 +615,28 @@ function replaceLucideIconsWithGlyphs(root: Element): void {
}
}
+/**
+ * Reflect a checkbox's live `checked` DOM PROPERTY onto the clone as the
+ * `checked` ATTRIBUTE. Task-list items carry their checkbox state as a
+ * property (the taskItem NodeView sets `input.checked`, never the attribute),
+ * and `cloneNode(true)` copies only attributes — so without this the cloned
+ * `<input>` loses its state and a CHECKED task item pastes UNCHECKED.
+ *
+ * Payoff is bounded: most paste destinations (Gmail / Slack / Notion / Google
+ * Docs) strip `<input>` outright, so this only helps destinations that keep
+ * form controls (Outlook web / roosterjs). Emitting a destination-surviving
+ * `[x]` / glyph convention instead is a separate, larger change.
+ *
+ * Exported for unit-test reach; the production caller is `walkPair`.
+ */
+export function reflectCheckboxCheckedState(live: Element, clone: Element): void {
+ if (live.tagName.toUpperCase() !== 'INPUT') return;
+ const input = live as HTMLInputElement;
+ if (input.type !== 'checkbox') return;
+ if (input.checked) clone.setAttribute('checked', '');
+ else clone.removeAttribute('checked');
+}
+
function walkPair(live: Element, clone: Element, env: WalkerEnv): void {
// Inline computed styles via the allowlist.
const styleStr = buildInlineStyleFrom(env.getComputedStyle(live));
@@ -644,6 +715,10 @@ function walkPair(live: Element, clone: Element, env: WalkerEnv): void {
}
}
+ // Recover the checkbox `checked` state that cloneNode(true) drops (it lives
+ // as a live DOM property, not an attribute) — see reflectCheckboxCheckedState.
+ reflectCheckboxCheckedState(live, clone);
+
// Recurse pairwise.
const liveKids = Array.from(live.children);
const cloneKids = Array.from(clone.children);
diff --git a/packages/app/src/editor/clipboard/serialize.ts b/packages/app/src/editor/clipboard/serialize.ts
index c8fc7597a..4799deafa 100644
--- a/packages/app/src/editor/clipboard/serialize.ts
+++ b/packages/app/src/editor/clipboard/serialize.ts
@@ -116,12 +116,48 @@ export function serializeCellSelectionAsText(selection: CellSelection): string {
currentRow = [];
currentRowTop = rowTop;
}
- currentRow.push(cell.textContent);
+ currentRow.push(encodeTsvField(cellText(cell)));
});
if (currentRow.length > 0) rows.push(currentRow);
return rows.map((r) => r.join('\t')).join('\n');
}
+/**
+ * A cell's text with its internal line breaks preserved. PM's `textContent`
+ * renders a `hardBreak` leaf as the empty string, so `line1<br>line2` would
+ * flush-concatenate to `"line1line2"`. `textBetween` with a block separator of
+ * `\n` (between paragraphs) and a `hardBreak` leafText of `\n` keeps every
+ * in-cell break as a real newline.
+ */
+function cellText(cell: Node): string {
+ return cell.textBetween(0, cell.content.size, '\n', (leaf) =>
+ leaf.type.name === 'hardBreak' ? '\n' : '',
+ );
+}
+
+/**
+ * Encode one TSV field per the Excel / Google Sheets clipboard convention
+ * (RFC 4180 §2.5-2.7 with a tab delimiter): a field containing a newline, a
+ * tab, or a double quote is wrapped in double quotes with internal quotes
+ * doubled, so its embedded newline is not confused with the row separator.
+ * Single-line cells with no special character stay unquoted — byte-identical to
+ * the prior `textContent` output.
+ *
+ * Spreadsheet formula injection (a cell starting with `=` / `+` / `-` / `@`)
+ * is deliberately NOT neutralized here — an accepted risk, not an oversight.
+ * This is clipboard copy-out consumed by every destination, not a CSV file
+ * export: the classic `'`-prefix mitigation would visibly corrupt legitimate
+ * cells (negative numbers, `+3%` deltas, list-style text) pasted into
+ * editors, chat, or OK itself, and RFC 4180 quoting alone never disarms a
+ * formula (`"=1+1"` still evaluates after unquoting). OWASP's CSV-injection
+ * guidance concedes no producer-side encoding is safe for every consumer, so
+ * the pasting spreadsheet is the enforcement point; cell bytes ship verbatim.
+ */
+function encodeTsvField(value: string): string {
+ if (!/["\t\n]/.test(value)) return value;
+ return `"${value.replaceAll('"', '""')}"`;
+}
+
/**
* Build an object that matches PM's expected `clipboardSerializer` shape.
*
diff --git a/packages/app/src/editor/clipboard/shift-tracker.ts b/packages/app/src/editor/clipboard/shift-tracker.ts
index 49625a9e9..e28194a2d 100644
--- a/packages/app/src/editor/clipboard/shift-tracker.ts
+++ b/packages/app/src/editor/clipboard/shift-tracker.ts
@@ -24,6 +24,9 @@
let shiftHeldLatch = false;
let listenersAttached = false;
+// The window the listeners were attached to, so a test reset can detach from
+// the exact window it wired (windows are swapped in/out across test files).
+let attachedWindow: Window | null = null;
function onKeyDown(e: KeyboardEvent): void {
shiftHeldLatch = e.shiftKey;
@@ -50,9 +53,28 @@ function ensureAttached(): void {
window.addEventListener('keydown', onKeyDown, true);
window.addEventListener('keyup', onKeyUp, true);
window.addEventListener('blur', onBlur, true);
+ attachedWindow = window;
listenersAttached = true;
}
+/**
+ * Detach the listeners and clear the latch. Test-only: the attach state is a
+ * module singleton, so a test file that wires the tracker to one `window` (e.g.
+ * a jsdom instance) would otherwise leave the guard set and block a sibling
+ * test file from re-attaching to its own window. Production never swaps
+ * `window`, so it never calls this.
+ */
+export function __resetShiftTrackerForTests(): void {
+ if (attachedWindow) {
+ attachedWindow.removeEventListener('keydown', onKeyDown, true);
+ attachedWindow.removeEventListener('keyup', onKeyUp, true);
+ attachedWindow.removeEventListener('blur', onBlur, true);
+ attachedWindow = null;
+ }
+ listenersAttached = false;
+ shiftHeldLatch = false;
+}
+
/**
* Install the shift listeners. Safe to call many times — the listeners
* are attached once. Call this at editor-creation time so the very first
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/merge-three-way.ts b/packages/core/src/bridge/merge-three-way.ts
index 864bc7245..b0a80fbd9 100644
--- a/packages/core/src/bridge/merge-three-way.ts
+++ b/packages/core/src/bridge/merge-three-way.ts
@@ -37,7 +37,6 @@ function mergeThreeWayImpl(baseline: string, userText: string, agentText: string
return parts.join('\n');
}
-
export type BridgeMergeContentLossSide = 'user' | 'agent';
export type BridgeMergeContentLossWhich = 'substring' | 'order';
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/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 064fa0773..58a810193 100644
--- a/packages/core/src/markdown/index.ts
+++ b/packages/core/src/markdown/index.ts
@@ -1,4 +1,3 @@
-
import {
type FromProseMirrorOptions,
fromPmMark,
@@ -165,7 +164,6 @@ export class MarkdownManager {
}
}
-
const registry = createRegistry();
function destructureAttrs(
@@ -214,7 +212,6 @@ function destructureAttrs(
return result;
}
-
function hasDirtyDescendant(node: PmNode): boolean {
let found = false;
node.descendants((child) => {
@@ -233,7 +230,6 @@ function effectiveDirty(node: PmNode): boolean {
return node.attrs.sourceDirty || hasDirtyDescendant(node);
}
-
function isEmptyMdastParagraph(node: MdastNodes): boolean {
if (node.type !== 'paragraph') return false;
const children = node.children ?? [];
@@ -302,7 +298,6 @@ function extractTextFromMdastNodes(nodes: MdastNodes[]): string {
return out;
}
-
import {
AUDIO_EXTENSIONS,
FILE_ATTACHMENT_EXTENSIONS,
@@ -552,7 +547,6 @@ function buildMdastToPmHandlers(
}));
}
-
if (m.emphasis) {
handlers.emphasis = toPmMark(m.emphasis, (node: Emphasis) => ({
sourceDelimiter: node.data?.sourceDelimiter ?? '*',
@@ -632,7 +626,6 @@ function buildMdastToPmHandlers(
}));
}
-
if (m.link) {
const sourceLiteralMark = m.sourceLiteral;
handlers.link = (node: Link, _parent: MdastParent, state: MdastToPmState) => {
@@ -911,7 +904,6 @@ function buildMdastToPmHandlers(
};
}
-
const blockUnknownHandler = (node: {
type: string;
position?: { start: { offset: number }; end: { offset: number } };
@@ -1037,7 +1029,6 @@ function buildMdastToPmHandlers(
return handlers as RemarkProseMirrorOptions['handlers'];
}
-
function buildPmToMdastHandlers(schema: Schema): {
nodeHandlers: FromProseMirrorOptions<string, string>['nodeHandlers'];
markHandlers: FromProseMirrorOptions<string, string>['markHandlers'];
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 153fdc1d8..8ce2b2492 100644
--- a/packages/core/src/markdown/mdast-to-html.ts
+++ b/packages/core/src/markdown/mdast-to-html.ts
@@ -1,6 +1,6 @@
-
-import type { Element, Root as HastRoot } from 'hast';
-import type { Root as MdastRoot } from 'mdast';
+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';
import { normalizeUri } from 'micromark-util-sanitize-uri';
import rehypeStringify from 'rehype-stringify';
import remarkFrontmatter from 'remark-frontmatter';
@@ -9,10 +9,13 @@ import remarkParse from 'remark-parse';
import remarkRehype from 'remark-rehype';
import { type Plugin, unified } from 'unified';
import { visit } from 'unist-util-visit';
+import { protectFromMdx, restoreFromMdx } from './autolink-void-html-guard.ts';
+import { encodeBackslashEscapes, restoreBackslashEscapesPlugin } from './backslash-escape-guard.ts';
import { decodeEntityRefs } from './entity-ref-guard.ts';
import { customNodeHandlers } from './mdast-to-hast-handlers.ts';
import { remarkMdxAgnostic } from './remark-mdx-agnostic.ts';
import { isSafeUrl } from './safe-url.ts';
+import { voidBrPromoterPlugin } from './void-br-promoter.ts';
import { remarkWikiLink } from './wiki-link-micromark.ts';
const DANGEROUS_STYLE_URL_RE = /url\s*\(\s*['"]?\s*(?:javascript|vbscript|data)\s*:/i;
@@ -150,6 +153,47 @@ export function mdastToHtml(tree: MdastRoot): string {
return String(processor.stringify(hast));
}
+function trimLinesInline(value: string): string {
+ const search = /\r?\n|\r/g;
+ const segments: string[] = [];
+ let last = 0;
+ let match = search.exec(value);
+ while (match !== null) {
+ segments.push(trimLineEdges(value.slice(last, match.index), last > 0, true), match[0]);
+ last = match.index + match[0].length;
+ match = search.exec(value);
+ }
+ segments.push(trimLineEdges(value.slice(last), last > 0, false));
+ return segments.join('');
+}
+
+function trimLineEdges(line: string, trimStart: boolean, trimEnd: boolean): string {
+ let start = 0;
+ let end = line.length;
+ const isSpaceOrTab = (code: number): boolean => code === 9 || code === 32;
+ while (trimStart && start < end && isSpaceOrTab(line.charCodeAt(start))) start++;
+ while (trimEnd && end > start && isSpaceOrTab(line.charCodeAt(end - 1))) end--;
+ return end > start ? line.slice(start, end) : '';
+}
+
+const LINE_BREAK_RE = /\r?\n|\r/;
+
+const softBreakTextHandler: Handler = (state, node) => {
+ const value = trimLinesInline(String((node as MdastText).value));
+ if (!LINE_BREAK_RE.test(value)) {
+ const result: HastText = { type: 'text', value };
+ state.patch(node, result);
+ return state.applyData(node, result);
+ }
+ const parts = value.split(LINE_BREAK_RE);
+ const out: Array<Element | HastText> = [];
+ for (let i = 0; i < parts.length; i++) {
+ if (i > 0) out.push({ type: 'element', tagName: 'br', properties: {}, children: [] });
+ if (parts[i].length > 0) out.push({ type: 'text', value: parts[i] });
+ }
+ return out;
+};
+
export function markdownToHtml(md: string): string {
const processor = unified()
.use(remarkParse)
@@ -157,9 +201,12 @@ export function markdownToHtml(md: string): string {
.use(remarkMdxAgnostic)
.use(remarkGfm)
.use(remarkWikiLink)
- .use(remarkRehype, { handlers: customNodeHandlers })
+ .use(restoreFromMdx)
+ .use(voidBrPromoterPlugin)
+ .use(restoreBackslashEscapesPlugin)
+ .use(remarkRehype, { handlers: { ...customNodeHandlers, text: softBreakTextHandler } })
.use(rehypeDecodeSourcePreservedAttrs)
.use(rehypeSanitizeUrls)
.use(rehypeStringify);
- return String(processor.processSync(md));
+ return String(processor.processSync(protectFromMdx(encodeBackslashEscapes(md))));
}
diff --git a/packages/core/src/markdown/merged-walker.ts b/packages/core/src/markdown/merged-walker.ts
index a58f8c720..35d74b85e 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 4ac5731e7..248685cfe 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 240be90e6..50a193a16 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';
@@ -467,8 +466,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 e1161455b..1a2fb5d50 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';
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..a100cad76 100644
--- a/packages/core/src/markdown/whitespace-char-ref.ts
+++ b/packages/core/src/markdown/whitespace-char-ref.ts
@@ -1,4 +1,3 @@
-
const INLINE_WHITESPACE_BY_CODE: ReadonlyMap<number, string> = new Map([
[0x20, ' '],
[0x09, '\t'],
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) {