A platform for community discussion. Free, open, simple.
DEV: implements parseAsync in discourse/lib/text (#17899)
Joffrey JAFFEUX7476c22324a2
diff --git a/app/assets/javascripts/discourse/app/lib/text.js b/app/assets/javascripts/discourse/app/lib/text.jsindex 3ee8baea18f..ee0feba09fd 100644--- a/app/assets/javascripts/discourse/app/lib/text.js+++ b/app/assets/javascripts/discourse/app/lib/text.js@@ -68,6 +68,12 @@ export function sanitizeAsync(text, options) {});}+export function parseAsync(md, options) {+ return loadMarkdownIt().then(() => {+ return createPrettyText(options).opts.engine.parse(md);+ });+}+function loadMarkdownIt() {return new Promise((resolve) => {let markdownItURL = Session.currentProp("markdownItURL");diff --git a/app/assets/javascripts/discourse/tests/unit/lib/text-test.js b/app/assets/javascripts/discourse/tests/unit/lib/text-test.jsnew file mode 100644index 00000000000..699effbe537--- /dev/null+++ b/app/assets/javascripts/discourse/tests/unit/lib/text-test.js@@ -0,0 +1,14 @@+import { module, test } from "qunit";+import { parseAsync } from "discourse/lib/text";++module("Unit | Utility | text", function () {+ test("parseAsync", async function (assert) {+ await parseAsync("**test**").then((tokens) => {+ assert.strictEqual(+ tokens[1].children[1].type,+ "strong_open",+ "it parses the raw markdown"+ );+ });+ });+});