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