REFACTOR: Remove `Discourse.SiteSettings` from highlightSyntax

This commit is contained in:
Robin Ward 2020-07-22 14:33:43 -04:00
parent 656abe22c7
commit 98fee7aa50
4 changed files with 13 additions and 7 deletions

View File

@ -6,6 +6,6 @@ export default Component.extend({
@on("didInsertElement")
@observes("code")
_refresh: function() {
highlightSyntax($(this.element));
highlightSyntax($(this.element), this.siteSettings);
}
});

View File

@ -321,7 +321,8 @@ const Theme = RestModel.extend({
}
}
);
highlightSyntax();
// TODO: Models shouldn't be updating the DOM
highlightSyntax(undefined, this.siteSettings);
} else {
return this.save({ remote_update: true }).then(() =>
this.set("changed", false)

View File

@ -9,9 +9,14 @@ export default {
initialize(container) {
withPluginApi("0.1", api => {
const siteSettings = container.lookup("site-settings:main");
api.decorateCooked(highlightSyntax, {
id: "discourse-syntax-highlighting"
});
api.decorateCooked(
elem => {
return highlightSyntax(elem, siteSettings);
},
{
id: "discourse-syntax-highlighting"
}
);
api.decorateCookedElement(
elem => {

View File

@ -3,8 +3,8 @@ let _moreLanguages = [];
import loadScript from "discourse/lib/load-script";
export default function highlightSyntax($elem) {
const selector = Discourse.SiteSettings.autohighlight_all_code
export default function highlightSyntax($elem, siteSettings) {
const selector = siteSettings.autohighlight_all_code
? "pre code"
: "pre code[class]",
path = Discourse.HighlightJSPath;