Skip to content

feat: Add markdown editor for description#40

Merged
cballevre merged 1 commit intomainfrom
feat/add-markdown-editor
Nov 11, 2025
Merged

feat: Add markdown editor for description#40
cballevre merged 1 commit intomainfrom
feat/add-markdown-editor

Conversation

@cballevre
Copy link
Copy Markdown
Owner

Fixes #33

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds markdown editing and rendering functionality to description fields in interventions and equipments, replacing plain textarea inputs with a rich markdown editor. The implementation includes two new shared components and updates to both the form and display pages for interventions and equipments.

Key changes:

  • Introduces MarkdownEditor component with toolbar for bold, italic, strikethrough, and link formatting
  • Introduces MarkdownRender component for displaying markdown content on show pages
  • Integrates @uiw/react-md-editor library for the editing experience with live preview

Reviewed Changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/shared/components/markdown-editor.tsx New component providing markdown editing with sanitized preview
src/shared/components/markdown-render.tsx New component for rendering markdown content on read-only pages
src/interventions/components/intervention-form.tsx Replaced Input.TextArea with MarkdownEditor for description field
src/interventions/pages/show.tsx Replaced plain text display with MarkdownRender component, moved description section for better layout
src/equipments/components/equipment-form.tsx Replaced Input.TextArea with MarkdownEditor for description field
src/equipments/pages/show.tsx Replaced plain text display with MarkdownRender component, moved description section for better layout
package.json Added dependencies: @uiw/react-md-editor, react-markdown, rehype-sanitize
yarn.lock Lock file updated with new dependencies and their transitive dependencies

Comment on lines +3 to +9

interface MarkdownRenderProps {
content?: string;
}

const MarkdownRender: React.FC<MarkdownRenderProps> = ({ content }) => {
return <ReactMarkdown>{content}</ReactMarkdown>;
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MarkdownRender component doesn't apply sanitization when rendering markdown content. While the MarkdownEditor uses rehypeSanitize for its preview, the read-only display should also sanitize content for security.

Consider adding rehype-sanitize to the MarkdownRender component:

import ReactMarkdown from 'react-markdown';
import rehypeSanitize from 'rehype-sanitize';

const MarkdownRender: React.FC<MarkdownRenderProps> = ({ content }) => {
  return (
    <ReactMarkdown rehypePlugins={[rehypeSanitize]}>
      {content || ''}
    </ReactMarkdown>
  );
};

This ensures that any markdown content displayed is sanitized, preventing potential XSS attacks from stored content.

Suggested change
interface MarkdownRenderProps {
content?: string;
}
const MarkdownRender: React.FC<MarkdownRenderProps> = ({ content }) => {
return <ReactMarkdown>{content}</ReactMarkdown>;
import rehypeSanitize from 'rehype-sanitize';
interface MarkdownRenderProps {
content?: string;
}
const MarkdownRender: React.FC<MarkdownRenderProps> = ({ content }) => {
return (
<ReactMarkdown rehypePlugins={[rehypeSanitize]}>
{content}
</ReactMarkdown>
);

Copilot uses AI. Check for mistakes.
Comment thread src/shared/components/markdown-render.tsx Outdated
Comment thread src/equipments/pages/show.tsx Outdated
Comment thread package.json
"react-dom": "^18.0.0",
"react-i18next": "^15.6.0",
"react-router": "^7.6.3"
"react-markdown": "^10.1.0",
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The explicit dependency on react-markdown@^10.1.0 may conflict with @uiw/react-md-editor which internally uses react-markdown@~9.0.1 (as seen in yarn.lock line 6787). This could lead to multiple versions of react-markdown being installed.

Consider removing the explicit react-markdown dependency from package.json and rely on the version that comes with @uiw/react-md-editor, or ensure version compatibility. If you need react-markdown@^10.1.0 for the MarkdownRender component separately, document why both versions are needed.

Suggested change
"react-markdown": "^10.1.0",

Copilot uses AI. Check for mistakes.
Comment on lines +12 to +25
<MDEditor
value={value}
onChange={onChange}
data-color-mode="light"
commands={[
commands.bold,
commands.italic,
commands.strikethrough,
commands.link,
]}
previewOptions={{
rehypePlugins: [[rehypeSanitize]],
}}
/>
Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider adding an accessible label or aria-label to the MDEditor component to improve accessibility for screen readers. Since this is used within Form.Item, the label is provided by the form, but for standalone usage or better accessibility, you might want to accept an optional id or aria-label prop:

interface MarkdownEditorProps {
  value?: string;
  onChange?: (value: string | undefined) => void;
  id?: string;
}

const MarkdownEditor: React.FC<MarkdownEditorProps> = ({ value, onChange, id }) => {
  return (
    <MDEditor
      id={id}
      value={value}
      onChange={onChange}
      ...
    />
  );
};

Copilot uses AI. Check for mistakes.
value?: string;
onChange?: (value: string | undefined) => void;
}

Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider adding JSDoc comments to document:

  1. What markdown features are supported (bold, italic, strikethrough, links)
  2. The sanitization being applied via rehypeSanitize
  3. Any usage examples or limitations

Example:

/**
 * A markdown editor component with sanitization support.
 * 
 * Supports the following markdown features:
 * - Bold text
 * - Italic text
 * - Strikethrough
 * - Links
 * 
 * Content is sanitized using rehype-sanitize to prevent XSS attacks.
 */
Suggested change
/**
* A markdown editor component with sanitization support.
*
* Supports the following markdown features:
* - Bold text
* - Italic text
* - Strikethrough
* - Links
*
* Content is sanitized using rehype-sanitize to prevent XSS attacks.
*
* Usage example:
* ```tsx
* <MarkdownEditor value={markdown} onChange={setMarkdown} />
* ```
*
* Limitations:
* - Only the listed markdown features are supported.
* - Other markdown features (e.g., tables, code blocks) may not be available.
*/

Copilot uses AI. Check for mistakes.
interface MarkdownRenderProps {
content?: string;
}

Copy link

Copilot AI Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider adding JSDoc comments to document the component's purpose and any limitations:

/**
 * Renders markdown content as HTML.
 * 
 * @param content - The markdown string to render. Can be undefined.
 * 
 * @remarks
 * This component uses react-markdown to safely parse and render markdown content.
 * It's companion to the MarkdownEditor component.
 */
Suggested change
/**
* Renders markdown content as HTML.
*
* @param content - The markdown string to render. Can be undefined.
*
* @remarks
* This component uses react-markdown to safely parse and render markdown content.
* It's companion to the MarkdownEditor component.
*/

Copilot uses AI. Check for mistakes.
@cballevre cballevre force-pushed the feat/add-markdown-editor branch from 1c1ec8c to dcabbcb Compare November 11, 2025 14:10
@cballevre cballevre merged commit 62b7470 into main Nov 11, 2025
1 check passed
@cballevre cballevre deleted the feat/add-markdown-editor branch November 11, 2025 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

As a user, I want to be able to write markdown into description fields

2 participants