A platform for community discussion. Free, open, simple.
DEV: cover more scenarios for the unsupported token message (#35909)
Renato Atilio071c280303a8
diff --git a/frontend/discourse/app/static/prosemirror/components/prosemirror-editor.gjs b/frontend/discourse/app/static/prosemirror/components/prosemirror-editor.gjsindex fa5ce1641ca..1255d63c3d6 100644--- a/frontend/discourse/app/static/prosemirror/components/prosemirror-editor.gjs+++ b/frontend/discourse/app/static/prosemirror/components/prosemirror-editor.gjs@@ -266,7 +266,32 @@ export default class ProsemirrorEditor extends Component {@bindconvertFromMarkdown(markdown) {- return this.parser.convert(this.schema, markdown);+ try {+ return this.parser.convert(this.schema, markdown);+ } catch (e) {+ if (e instanceof UnsupportedTokenError) {+ this.dialog.alert({+ message: i18n("composer.unsupported_token"),+ didConfirm: this.args.toggleRichEditor,+ didCancel: this.args.toggleRichEditor,+ });++ return this.schema.nodes.paragraph.create(+ null,+ markdown+ // our html_block avoids double newlines+ // because markdown-it closes the html block parsing at double newlines+ .split("\n\n")+ .filter(Boolean)+ .map((line) =>+ // this creates a dependency on having a html_block in the schema+ this.schema.nodes.html_block.create(null, this.schema.text(line))+ )+ );+ }++ throw e;+ }}@bind@@ -279,7 +304,7 @@ export default class ProsemirrorEditor extends Component {}try {- const doc = this.convertFromMarkdown(value);+ const doc = this.parser.convert(this.schema, value);const tr = this.view.state.tr;tr.replaceWith(0, this.view.state.doc.content.size, doc.content).setMeta(diff --git a/frontend/discourse/app/static/prosemirror/extensions/markdown-paste.js b/frontend/discourse/app/static/prosemirror/extensions/markdown-paste.jsindex 811843d2492..36ee21411d0 100644--- a/frontend/discourse/app/static/prosemirror/extensions/markdown-paste.js+++ b/frontend/discourse/app/static/prosemirror/extensions/markdown-paste.js@@ -1,37 +1,15 @@-import { UnsupportedTokenError } from "discourse/static/prosemirror/core/parser";-import { i18n } from "discourse-i18n";-/** @type {RichEditorExtension} */const extension = {plugins({pmState: { Plugin },pmModel: { Fragment, Slice },- utils: { convertFromMarkdown, toggleRichEditor },- schema,- getContext,+ utils: { convertFromMarkdown },}) {return new Plugin({props: {clipboardTextParser(text) {- try {- const { content } = convertFromMarkdown(text);-- return Slice.maxOpen(Fragment.from(content));- } catch (e) {- if (e instanceof UnsupportedTokenError) {- getContext().dialog.alert({- message: i18n("composer.unsupported_token"),- didConfirm: toggleRichEditor,- didCancel: toggleRichEditor,- });-- return new Fragment([- schema.nodes.html_block.create({}, schema.text(text)),- ]);- }-- throw e;- }+ const doc = convertFromMarkdown(text);+ return Slice.maxOpen(Fragment.from(doc.content));},},});