mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 04:03:57 -06:00
DEV: implements parseAsync in discourse/lib/text (#17899)
`parseAsync` allows to parse a block of markdown into tokens. Usage: ```javascript import { parseAsync } from "discourse/lib/text"; // ... await parseAsync("**test**").then((tokens) => { console.log(tokens); }) ```
This commit is contained in:
parent
3dac4fe075
commit
7476c22324
@ -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");
|
||||
|
14
app/assets/javascripts/discourse/tests/unit/lib/text-test.js
Normal file
14
app/assets/javascripts/discourse/tests/unit/lib/text-test.js
Normal file
@ -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"
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user