From 20bcb382493c4c8cc2ed3b1c44509175d44f9044 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Sat, 13 Aug 2022 15:14:21 +0200 Subject: [PATCH] FIX: prevents markdown error by using new core parseAsync (#21) Prior to this fix markdown-it was not correctly initialised and would cause an error when having to parse an URL for example. --- .../api-initializers/table-editor.js | 35 +++++++------------ 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/javascripts/discourse/api-initializers/table-editor.js b/javascripts/discourse/api-initializers/table-editor.js index f2205dc..76c1ea7 100644 --- a/javascripts/discourse/api-initializers/table-editor.js +++ b/javascripts/discourse/api-initializers/table-editor.js @@ -6,14 +6,11 @@ import { iconNode } from "discourse-common/lib/icon-library"; import { create } from "virtual-dom"; import { ajax } from "discourse/lib/ajax"; import { popupAjaxError } from "discourse/lib/ajax-error"; -import Session from "discourse/models/session"; -import loadScript from "discourse/lib/load-script"; -import PrettyText, { buildOptions } from "pretty-text/pretty-text"; +import { parseAsync } from "discourse/lib/text"; import { tokenRange } from "../discourse-table-builder/lib/utilities"; export default apiInitializer("0.11.1", (api) => { const site = api.container.lookup("service:site"); - const siteSettings = api.container.lookup("service:site-settings"); function createButton() { const openPopupBtn = document.createElement("button"); @@ -37,27 +34,19 @@ export default apiInitializer("0.11.1", (api) => { const tableId = event.target.getAttribute("data-table-id"); return ajax(`/posts/${this.id}`, { type: "GET" }) - .then((post) => { - let markdownItURL = Session.currentProp("markdownItURL"); + .then((post) => + parseAsync(post.raw).then((tokens) => { + const allTables = tokenRange(tokens, "table_open", "table_close"); + const tableTokens = allTables[tableId]; - if (markdownItURL) { - loadScript(markdownItURL).then(() => { - const prettyText = new PrettyText(buildOptions({ siteSettings })); - const tokens = prettyText.opts.engine.parse(post.raw, { - references: {}, - }); - const allTables = tokenRange(tokens, "table_open", "table_close"); - const tableTokens = allTables[tableId]; - - showModal("insert-table-modal", { - model: post, - }).setProperties({ - tableId, - tableTokens, - }); + showModal("insert-table-modal", { + model: post, + }).setProperties({ + tableId, + tableTokens, }); - } - }) + }) + ) .catch(popupAjaxError); }