Skip to content

Commit c8c4580

Browse files
committed
refactor(rich-markdown-editor): hoist paste-strip regex, cross-ref block-mover
/simplify pass follow-ups: hoist the <style>/<script> strip regex to module scope (matches the file's other module-level pattern consts, avoids re-alloc per paste), and note the Mod-Shift-Arrow block-reorder chords in the keymap doc so arrow handling is discoverable across the two files. No behavior change.
1 parent 6528a83 commit c8c4580

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/keymap.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ function selectAdjacentSelectedLeaf(editor: Editor, direction: 'up' | 'down'): b
128128
* same scoped behavior as a code editor.
129129
* - **ArrowUp/ArrowDown** select an adjacent divider or image, whether arrowing off a textblock edge
130130
* ({@link selectAdjacentLeaf}) or stepping from one already-selected leaf to the next
131-
* ({@link selectAdjacentSelectedLeaf}).
131+
* ({@link selectAdjacentSelectedLeaf}). (The `Mod-Shift-Arrow` block-reorder chords live separately
132+
* in `./block-mover.ts`.)
132133
*
133134
* Plus a plugin that (a) highlights dividers/images falling inside a range selection (e.g. select-all),
134135
* which the browser's native text highlight skips because leaves carry no text, and (b) flags the

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/markdown-paste.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,17 @@ function parseVscodeLanguage(data: string | undefined): string {
6262
}
6363
}
6464

65+
/** `<style>`/`<script>` elements (with their content), matched as a pair via the tag backreference. */
66+
const NON_CONTENT_HTML = /<(style|script)\b[\s\S]*?<\/\1>/gi
67+
6568
/**
6669
* Strips `<style>`/`<script>` elements from pasted HTML. Google Sheets and Word prepend a `<style>`
6770
* block of CSS (and Sheets a `<google-sheets-html-origin>` wrapper); ProseMirror's DOM parser has no
6871
* rule for `<style>`, so it would walk the element's CSS text into the document as literal paragraphs.
6972
* Removing these before parsing keeps the pasted content clean (PM already discards unknown wrappers).
7073
*/
7174
function stripNonContentHtml(html: string): string {
72-
return html.replace(/<(style|script)\b[\s\S]*?<\/\1>/gi, '')
75+
return html.replace(NON_CONTENT_HTML, '')
7376
}
7477

7578
/**

0 commit comments

Comments
 (0)