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.
This commit is contained in:
Joffrey JAFFEUX 2022-08-13 15:14:21 +02:00 committed by GitHub
parent f68a599e87
commit 20bcb38249
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 23 deletions

View File

@ -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);
}