1
0
Fork 0
discourse-custom-wizard-unl.../assets/javascripts/wizard/lib/text-lite.js.es6

35 Zeilen
1 KiB
Text

import loadScript from "./load-script";
import { default as PrettyText, buildOptions } from "pretty-text/pretty-text";
import Handlebars from "handlebars";
import getURL from "discourse-common/lib/get-url";
import { getOwner } from "discourse-common/lib/get-owner";
import { Promise } from "rsvp";
import Session from "discourse/models/session";
2018-02-08 05:30:55 +01:00
export function cook(text, options) {
if (!options) {
options = buildOptions({
2021-10-27 16:05:09 +02:00
getURL,
siteSettings: getOwner(this).lookup("site-settings:main"),
});
}
2018-02-08 05:30:55 +01:00
return new Handlebars.SafeString(new PrettyText(options).cook(text));
}
// everything should eventually move to async API and this should be renamed
// cook
export function cookAsync(text, options) {
let markdownItURL = Session.currentProp("markdownItURL");
if (markdownItURL) {
return (
loadScript(markdownItURL)
.then(() => cook(text, options))
// eslint-disable-next-line no-console
.catch((e) => console.error(e))
);
2018-02-08 05:30:55 +01:00
} else {
return Promise.resolve(cook(text));
2018-02-08 05:30:55 +01:00
}
}