Skip to content

[16.0][ADD] web_editor_paste_markdown - #3820

Open
ygol wants to merge 1 commit into
OCA:16.0from
ygol:16.0-add-web_editor_paste_markdown
Open

ygol wants to merge 1 commit into
OCA:16.0from
ygol:16.0-add-web_editor_paste_markdown

Conversation

@ygol

@ygol ygol commented Nov 22, 2026

Copy link
Copy Markdown

Module

web_editor_paste_markdown (Markdown ↔ HTML): two commands for HTML fields; nothing
is stored as Markdown, the field keeps its HTML.

  • "Paste Markdown" in the powerbox (/ menu): a dialog to paste Markdown, with the HTML
    preview; the converted HTML is inserted with inline styles for tables, code and quotes
    (they render the same in the editor and in e-mails). Task lists become Odoo
    checklists.
  • "To Markdown", in the powerbox for the whole field and as a toolbar button for the
    selection: the same dialog filled with the content converted to Markdown. Copy it to
    use it outside Odoo (image paths made absolute, embedded images replaced by their
    text), or edit it and replace the content in one undo step; a warning lists what
    Markdown cannot express (colors, styles, merged cells) before replacing.

Proposed as Alpha. No dependency besides web_editor.

It was first part of #3817, next to web_widget_markdown_editor, whose Toast UI copy it
used. It now ships its own, lighter libraries, so the two modules are proposed
separately.

Origin and third-party code

  • Written by Yves Goldberg (Ygol InternetWork) from December 2025 and used in
    production since then. No code comes from other Odoo modules.
  • static/lib holds, unchanged from their npm packages (source maps removed):
    • markdown-it 15.0.3, browser UMD build,
      (c) Vitaly Puzrin, Alex Kocharin, MIT license;
    • Turndown 7.2.5, browser UMD build, (c) Dom
      Christie, MIT license.
  • The GFM rules for HTML to Markdown (tables with the first row as header, strikethrough,
    task lists, compact list markers, code blocks of the Odoo editor) and the task-list
    rule for markdown-it are written in the module; turndown-plugin-gfm is not used (no
    release since 2018, it leaves tables without th as HTML).
  • Raw HTML in pasted Markdown is rendered only when DOMPurify, loaded with the Odoo
    editor, sanitizes it; otherwise it is inserted as text.

AI assistance

Following the OCA AI policy, the commit carries an Assisted-by: trailer: Claude Code
(Claude Opus 4.5) for the first Paste Markdown command in December 2025, Claude Code
(Claude Opus 5.5) for To Markdown, the move to markdown-it and Turndown, the tests and
the OCA packaging. I reviewed and tested this code, and I take responsibility for every
line.

Tests

QUnit suite run by tests/test_js.py (HttpCase.browser_js), 109 assertions:
Markdown to HTML (headings, tables, code, task lists, raw HTML with and without
DOMPurify, fallback without the library), HTML to Markdown (tables with and without
header cells, escaped pipes, strikethrough, checklists, nested and numbered lists, code
blocks and their language, literal ~~, tags and entities, round trips), selection
handling, lost-formatting detection, copy preparation, and the dialog (copy, replace,
warning, close).

Two commands for the HTML fields, without storing Markdown:

- Paste Markdown (command menu): paste Markdown, preview it, insert the
  converted HTML (tables, code and quotes get inline styles, task lists
  become Odoo checklists).
- To Markdown (command menu for the whole field, toolbar button for the
  selection): the content as Markdown, to copy it or to replace the content
  after editing it, with a warning when formatting would be lost.

The conversions run in the browser with markdown-it 15.0.3 and Turndown
7.2.5 (MIT), shipped in static/lib, plus GFM rules written in the module.

Assisted-by: Claude Code:claude-opus-4-5
Assisted-by: Claude Code:claude-opus-5-5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:web_editor_paste_markdown Module web_editor_paste_markdown series:16.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants