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:
parent
f68a599e87
commit
20bcb38249
|
@ -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,15 +34,8 @@ 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");
|
||||
|
||||
if (markdownItURL) {
|
||||
loadScript(markdownItURL).then(() => {
|
||||
const prettyText = new PrettyText(buildOptions({ siteSettings }));
|
||||
const tokens = prettyText.opts.engine.parse(post.raw, {
|
||||
references: {},
|
||||
});
|
||||
.then((post) =>
|
||||
parseAsync(post.raw).then((tokens) => {
|
||||
const allTables = tokenRange(tokens, "table_open", "table_close");
|
||||
const tableTokens = allTables[tableId];
|
||||
|
||||
|
@ -55,9 +45,8 @@ export default apiInitializer("0.11.1", (api) => {
|
|||
tableId,
|
||||
tableTokens,
|
||||
});
|
||||
});
|
||||
}
|
||||
})
|
||||
)
|
||||
.catch(popupAjaxError);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue