0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-23 09:50:28 +01:00
discourse-custom-wizard/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({
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
}
}