Skip to content

Fully autonomous AI Agents system capable of performing complex penetration testing tasks

refactor(markdown-editor): fix false comments, simplify setContent, dedup wrapper (L2/L4/L5/L6/F9)

Sergey Kozyrenko0d862d1e18e5
diff --git a/frontend/src/components/shared/markdown-editor/index.ts b/frontend/src/components/shared/markdown-editor/index.ts
index 26616d05..4398f1d7 100644
--- a/frontend/src/components/shared/markdown-editor/index.ts
+++ b/frontend/src/components/shared/markdown-editor/index.ts
@@ -1,5 +1,5 @@
export { MarkdownEditor } from './markdown-editor';
-export type { MarkdownEditorHandle, MarkdownEditorProps } from './markdown-editor';
+export type { MarkdownEditorHandle } from './markdown-editor';
export { findVariableUseRanges, VARIABLE_RE, variableProbe } from './markdown-editor-variable-highlight';
export { EditorViewModeToggle } from './markdown-editor-view-mode';
export type { EditorViewMode } from './markdown-editor-view-mode';
diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor-marked.ts b/frontend/src/components/shared/markdown-editor/markdown-editor-marked.ts
index 9c950745..52021b99 100644
--- a/frontend/src/components/shared/markdown-editor/markdown-editor-marked.ts
+++ b/frontend/src/components/shared/markdown-editor/markdown-editor-marked.ts
@@ -82,9 +82,11 @@ const FaithfulMarkdownText = Extension.create({
});
// @tiptap/extension-table's renderTableToMarkdown is alignment-aware but never escapes pipes, so a literal
-// `|` in a cell (even inside inline code) re-parses as a column delimiter on the next save and drops cells
-// (tiptap PR #7884, still open). renderTableToMarkdown only emits cell content via h.renderChildren, so
-// wrapping that one call to escape pipes is enough — and it stays on the official, alignment-aware renderer.
+// `|` a cell emits (even from inside inline code) would re-parse as a column delimiter on the next SAVE and
+// drop cells (tiptap PR #7884). renderTableToMarkdown emits cell content only via h.renderChildren, so wrapping
+// that one call to escape pipes fixes the save side, on the official alignment-aware renderer.
+// This does NOT (and cannot) help the LOAD side: a raw `|` inside inline code arriving in external markdown is
+// split by marked's GFM table tokenizer BEFORE the inline-code tokenizer runs — a marked limitation.
type RenderHelpers = { renderChildren: (nodes: JSONContent | JSONContent[], separator?: string) => string };
export const MarkdownTable = Table.extend({
diff --git a/frontend/src/components/shared/markdown-editor/markdown-editor.tsx b/frontend/src/components/shared/markdown-editor/markdown-editor.tsx
index da4b413c..2851fb88 100644
--- a/frontend/src/components/shared/markdown-editor/markdown-editor.tsx
+++ b/frontend/src/components/shared/markdown-editor/markdown-editor.tsx
@@ -37,7 +37,7 @@ export interface MarkdownEditorHandle {
insertAtCursor: (text: string) => void;
}
-export interface MarkdownEditorProps {
+interface MarkdownEditorProps {
autoFocus?: boolean;
className?: string;
contentClassName?: string;
@@ -92,6 +92,10 @@ interface MarkdownEditorToolbarProps {
editor: Editor;
}
+// Shared by the loading shell and the mounted editor so the two wrappers cannot drift.
+const WRAPPER_CLASS =
+ 'border-input dark:bg-input/30 group/markdown-editor flex w-full flex-col overflow-hidden rounded-md border shadow-2xs outline-hidden transition-[color,box-shadow]';
+
function MarkdownEditor({
autoFocus,
className,
@@ -214,13 +218,8 @@ function MarkdownEditor({
const shouldExternalSync = current !== value;
if (shouldExternalSync) {
- // @tiptap/markdown only wires `contentType: 'markdown'` into the initial
- // content + insertContent — NOT setContent — so parse the markdown explicitly.
- const parsed = editor.markdown?.parse(value);
-
- if (parsed) {
- editor.commands.setContent(parsed, { emitUpdate: false });
- }
+ // emitUpdate:false — an external sync (form.reset) is not a user edit, so it must not fire onChange.
+ editor.commands.setContent(value, { contentType: 'markdown', emitUpdate: false });
}
// Seed with the editor's serialized markdown, not the raw `value` — else the first user keystroke
@@ -263,11 +262,7 @@ function MarkdownEditor({
return (
<div
aria-busy="true"
- className={cn(
- 'border-input dark:bg-input/30 group/markdown-editor flex w-full flex-col overflow-hidden rounded-md border shadow-2xs outline-hidden transition-[color,box-shadow]',
- disabled && 'pointer-events-none opacity-60',
- className,
- )}
+ className={cn(WRAPPER_CLASS, disabled && 'pointer-events-none opacity-60', className)}
data-slot="markdown-editor"
/>
);
@@ -276,7 +271,7 @@ function MarkdownEditor({
return (
<div
className={cn(
- 'border-input dark:bg-input/30 group/markdown-editor flex w-full flex-col overflow-hidden rounded-md border shadow-2xs outline-hidden transition-[color,box-shadow]',
+ WRAPPER_CLASS,
'focus-within:ring-ring focus-within:ring-1',
disabled && 'pointer-events-none opacity-60',
className,
@@ -301,8 +296,9 @@ function MarkdownEditor({
);
}
-// The Image extension (unlike Link) doesn't validate the src protocol, so reject non-http(s)/non-image-data
-// URLs (javascript:, data:text/html, …) before they're stored — defense-in-depth for saved content.
+// The Image extension doesn't validate the src protocol, so the toolbar Insert-image button rejects
+// non-http(s)/non-image-data URLs (javascript:, data:text/html, …). Guards ONLY that button — images entering
+// via markdown load/paste bypass it (inert in an <img src>; the read-only viewer sanitizes protocols on render).
export const isSafeImageSrc = (url: string): boolean => {
try {
const { protocol } = new URL(url, window.location.href);