discourse/plugins/discourse-local-dates
Renato Atilio d62cc48d9c
DEV: to-markdown prosemirror HTML parsing (#35563)
Replaces the custom ~1000-line `to-markdown` converter with ProseMirror's schema-based parsing and serialization pipeline, reusing the same extensions that power the rich editor. The old converter duplicated logic the extensions already implement (image formatting, mention/hashtag serialization, table handling, list nesting, etc.) — a single pipeline means one set of rules, fewer divergence bugs, and plugin extensions work in both directions automatically.

### Core change

- `toMarkdown()` is now async and lazy-loads ProseMirror on first use.
- Cooked→markdown serialization runs through the registered rich-editor extensions, so both conversion directions share one source of truth.

### QuoteState and quote callers

Making `toMarkdown()` async changed the quote flow. `QuoteState` now stores the selection's HTML and exposes an async `markdown()`; `buffer` is the plain-text selection. Every caller that needs markdown was updated to await `markdown()`:

- Topic controller (`selectText`, `replyToPost` including EmbedMode, `replyAsNewTopic`, `buildQuoteMarkdown`).
- Nested controller — forwards the full selection state via the new `copyFrom`.
- Fast-edit modal and `computeSupportsFastEdit`.
- discourse-ai post-helper menu — now sends markdown (not plain text) to the AI endpoints.

`markdown()` snapshots `opts` before awaiting so a concurrent selection change can't mis-pair the result.

### Plugin API

- Removed plugin-specific `addTagDecorateCallback`/`addTextDecorateCallback` usage from local-dates and spoiler-alert (the old APIs are kept as deprecated no-ops). local-dates now uses a `transformParsedHTML` rich-editor extension hook.

### Extractions and sharing

- Word paste handling moved into a dedicated `word-paste.js` extension.
- Quote-selection list-structure preservation moved into `preserve-list-structure.js`.
- `normalizeTable` is shared between the paste plugin and the serializer for consistent table output across editor modes.

### Quoting fix

- `selectedHTML` drops the empty trailing block a triple-click leaves behind. A triple-click extends the selection's end to the start of the following block, so `cloneContents()` would otherwise clone an empty `<blockquote>` that serializes to a stray `> ` in the quote.
2026-05-29 18:14:32 -03:00
..
assets DEV: to-markdown prosemirror HTML parsing (#35563) 2026-05-29 18:14:32 -03:00
config I18N: Update translations (#40300) 2026-05-26 15:25:51 +02:00
db/migrate FEATURE: allow customizing default timezone for email. (#32964) 2025-05-29 14:17:37 +10:00
lib/discourse_local_dates DEV: Clean up scope resolution operators in plugins (#34979) 2025-09-30 14:36:34 +02:00
spec DEV: Update rubocop (#38721) 2026-03-20 00:39:52 +01:00
test/javascripts DEV: to-markdown prosemirror HTML parsing (#35563) 2026-05-29 18:14:32 -03:00
package.json DEV: Add a script for generating external types in discourse-types (#37095) 2026-03-09 20:37:43 +01:00
plugin.rb DEV: Remove unnecessary freeze calls (#35064) 2025-09-30 15:36:16 +02:00
tsconfig.json DEV: Add a script for generating external types in discourse-types (#37095) 2026-03-09 20:37:43 +01:00