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 { create } from "virtual-dom";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
import Session from "discourse/models/session";
|
import { parseAsync } from "discourse/lib/text";
|
||||||
import loadScript from "discourse/lib/load-script";
|
|
||||||
import PrettyText, { buildOptions } from "pretty-text/pretty-text";
|
|
||||||
import { tokenRange } from "../discourse-table-builder/lib/utilities";
|
import { tokenRange } from "../discourse-table-builder/lib/utilities";
|
||||||
|
|
||||||
export default apiInitializer("0.11.1", (api) => {
|
export default apiInitializer("0.11.1", (api) => {
|
||||||
const site = api.container.lookup("service:site");
|
const site = api.container.lookup("service:site");
|
||||||
const siteSettings = api.container.lookup("service:site-settings");
|
|
||||||
|
|
||||||
function createButton() {
|
function createButton() {
|
||||||
const openPopupBtn = document.createElement("button");
|
const openPopupBtn = document.createElement("button");
|
||||||
|
@ -37,15 +34,8 @@ export default apiInitializer("0.11.1", (api) => {
|
||||||
const tableId = event.target.getAttribute("data-table-id");
|
const tableId = event.target.getAttribute("data-table-id");
|
||||||
|
|
||||||
return ajax(`/posts/${this.id}`, { type: "GET" })
|
return ajax(`/posts/${this.id}`, { type: "GET" })
|
||||||
.then((post) => {
|
.then((post) =>
|
||||||
let markdownItURL = Session.currentProp("markdownItURL");
|
parseAsync(post.raw).then((tokens) => {
|
||||||
|
|
||||||
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 allTables = tokenRange(tokens, "table_open", "table_close");
|
||||||
const tableTokens = allTables[tableId];
|
const tableTokens = allTables[tableId];
|
||||||
|
|
||||||
|
@ -55,9 +45,8 @@ export default apiInitializer("0.11.1", (api) => {
|
||||||
tableId,
|
tableId,
|
||||||
tableTokens,
|
tableTokens,
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
)
|
||||||
.catch(popupAjaxError);
|
.catch(popupAjaxError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue