mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 16:21:18 +08:00
DEV: remove markdown-it-bundle and custom build code (#23859)
With Embroider, we can rely on async `import()` to do the splitting for us. This commit extracts from `pretty-text` all the parts that are meant to be loaded async into a new `discourse-markdown-it` package that is also a V2 addon (meaning that all files are presumed unused until they are imported, aka "static"). Mostly I tried to keep the very discourse specific stuff (accessing site settings and loading plugin features) inside discourse proper, while the new package aims to have some resembalance of a general purpose library, a MarkdownIt++ if you will. It is far from perfect because of how all the "options" stuff work but I think it's a good start for more refactorings (clearing up the interfaces) to happen later. With this, pretty-text and app/lib/text are mostly a kitchen sink of loosely related text processing utilities. After the refactor, a lot more code related to setting up the engine are now loaded lazily, which should be a pretty nice win. I also noticed that we are currently pulling in the `xss` library at initial load to power the "sanitize" stuff, but I suspect with a similar refactoring effort those usages can be removed too. (See also #23790). This PR does not attempt to fix the sanitize issue, but I think it sets things up on the right trajectory for that to happen later. Co-authored-by: David Taylor <david@taylorhq.com>
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import PrettyText, { buildOptions } from "pretty-text/pretty-text";
|
||||
import { module, test } from "qunit";
|
||||
import { cook } from "discourse/lib/text";
|
||||
|
||||
const defaultOpts = buildOptions({
|
||||
const opts = {
|
||||
siteSettings: {
|
||||
enable_emoji: true,
|
||||
emoji_set: "twitter",
|
||||
@ -10,24 +10,21 @@ const defaultOpts = buildOptions({
|
||||
},
|
||||
censoredWords: "shucks|whiz|whizzer",
|
||||
getURL: (url) => url,
|
||||
});
|
||||
};
|
||||
|
||||
module("lib:details-cooked-test", function () {
|
||||
test("details", function (assert) {
|
||||
const cooked = (input, expected, text) => {
|
||||
assert.strictEqual(
|
||||
new PrettyText(defaultOpts).cook(input),
|
||||
expected.replace(/\/>/g, ">"),
|
||||
text
|
||||
);
|
||||
test("details", async function (assert) {
|
||||
const testCooked = async (input, expected, text) => {
|
||||
const cooked = (await cook(input, opts)).toString();
|
||||
assert.strictEqual(cooked, expected, text);
|
||||
};
|
||||
cooked(
|
||||
await testCooked(
|
||||
`<details><summary>Info</summary>coucou</details>`,
|
||||
`<details><summary>Info</summary>coucou</details>`,
|
||||
"manual HTML for details"
|
||||
);
|
||||
|
||||
cooked(
|
||||
await testCooked(
|
||||
"[details=testing]\ntest\n[/details]",
|
||||
`<details>
|
||||
<summary>
|
||||
|
Reference in New Issue
Block a user