2021-03-28 20:06:49 +11:00
|
|
|
import loadScript from "./load-script";
|
2021-05-05 02:36:01 +05:30
|
|
|
import { default as PrettyText, buildOptions } from "pretty-text/pretty-text";
|
2021-04-12 11:56:22 +05:30
|
|
|
import Handlebars from "handlebars";
|
2021-05-05 02:36:01 +05:30
|
|
|
import getURL from "discourse-common/lib/get-url";
|
|
|
|
import { getOwner } from "discourse-common/lib/get-owner";
|
2018-02-08 12:30:55 +08:00
|
|
|
|
|
|
|
export function cook(text, options) {
|
2021-05-05 02:36:01 +05:30
|
|
|
if (!options) {
|
|
|
|
options = buildOptions({
|
|
|
|
getURL: getURL,
|
|
|
|
siteSettings: getOwner(this).lookup("site-settings:main"),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-02-08 12:30:55 +08: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) {
|
|
|
|
if (Discourse.MarkdownItURL) {
|
|
|
|
return loadScript(Discourse.MarkdownItURL)
|
2021-03-28 20:06:49 +11:00
|
|
|
.then(() => cook(text, options))
|
|
|
|
.catch((e) => Ember.Logger.error(e));
|
2018-02-08 12:30:55 +08:00
|
|
|
} else {
|
|
|
|
return Ember.RSVP.Promise.resolve(cook(text));
|
|
|
|
}
|
|
|
|
}
|