mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 03:21:12 +08:00
REFACTOR: Migrate markdown functionality in ES6
This commit is contained in:
@ -1,28 +0,0 @@
|
||||
(function() {
|
||||
|
||||
function insertDetails(_, summary, details) {
|
||||
return "<details><summary>" + summary + "</summary>" + details + "</details>";
|
||||
}
|
||||
|
||||
// replace all [details] BBCode with HTML 5.1 equivalent
|
||||
function replaceDetails(text) {
|
||||
text = text || "";
|
||||
|
||||
while (text !== (text = text.replace(/\[details=([^\]]+)\]((?:(?!\[details=[^\]]+\]|\[\/details\])[\S\s])*)\[\/details\]/ig, insertDetails)));
|
||||
|
||||
// add new lines to make sure we *always* have a <p> element after </summary> and around </details>
|
||||
// otherwise we can't hide the content since we can't target text nodes via CSS
|
||||
return text.replace(/<\/summary>/ig, "</summary>\n\n")
|
||||
.replace(/<\/details>/ig, "\n\n</details>\n\n");
|
||||
}
|
||||
|
||||
Discourse.Dialect.addPreProcessor(function(text) {
|
||||
if (Discourse.SiteSettings.details_enabled) {
|
||||
text = replaceDetails(text);
|
||||
}
|
||||
return text;
|
||||
});
|
||||
|
||||
Discourse.Markdown.whiteListTag("details", "class", "elided");
|
||||
|
||||
})();
|
@ -1,5 +1,4 @@
|
||||
import { withPluginApi } from 'discourse/lib/plugin-api';
|
||||
import ComposerController from 'discourse/controllers/composer';
|
||||
|
||||
function initializeDetails(api) {
|
||||
api.decorateCooked($elem => $("details", $elem).details());
|
||||
@ -12,6 +11,7 @@ function initializeDetails(api) {
|
||||
};
|
||||
});
|
||||
|
||||
const ComposerController = api.container.lookup("controller:composer");
|
||||
ComposerController.reopen({
|
||||
actions: {
|
||||
insertDetails() {
|
||||
@ -27,6 +27,7 @@ function initializeDetails(api) {
|
||||
|
||||
export default {
|
||||
name: "apply-details",
|
||||
after: 'inject-objects',
|
||||
|
||||
initialize() {
|
||||
withPluginApi('0.5', initializeDetails);
|
||||
|
@ -0,0 +1,25 @@
|
||||
import { registerOption } from 'pretty-text/pretty-text';
|
||||
|
||||
function insertDetails(_, summary, details) {
|
||||
return `<details><summary>${summary}</summary>${details}</details>`;
|
||||
}
|
||||
|
||||
// replace all [details] BBCode with HTML 5.1 equivalent
|
||||
function replaceDetails(text) {
|
||||
text = text || "";
|
||||
|
||||
while (text !== (text = text.replace(/\[details=([^\]]+)\]((?:(?!\[details=[^\]]+\]|\[\/details\])[\S\s])*)\[\/details\]/ig, insertDetails)));
|
||||
|
||||
// add new lines to make sure we *always* have a <p> element after </summary> and around </details>
|
||||
// otherwise we can't hide the content since we can't target text nodes via CSS
|
||||
return text.replace(/<\/summary>/ig, "</summary>\n\n").replace(/<\/details>/ig, "\n\n</details>\n\n");
|
||||
}
|
||||
|
||||
registerOption((siteSettings, opts) => {
|
||||
opts.features.details = true;
|
||||
});
|
||||
|
||||
export function setup(helper) {
|
||||
helper.whiteList('details.elided');
|
||||
helper.addPreProcessor(text => replaceDetails(text));
|
||||
}
|
@ -7,8 +7,6 @@
|
||||
enabled_site_setting :details_enabled
|
||||
|
||||
register_asset "javascripts/details.js"
|
||||
register_asset "javascripts/details_dialect.js", :server_side
|
||||
|
||||
register_asset "stylesheets/details.scss"
|
||||
|
||||
after_initialize do
|
||||
|
Reference in New Issue
Block a user