Revert "correct more specs"

This reverts commit 40bcc6bbdc99a33e65af29b7fd789354c84f6fd4.
This commit is contained in:
Sam
2017-07-12 18:10:05 -04:00
parent 8caaa6a56e
commit d609f8a53c
3 changed files with 44 additions and 15 deletions

View File

@ -1,3 +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;
});
const rule = {
tag: 'details',
before: function(state, attrs) {
@ -24,7 +46,11 @@ export function setup(helper) {
'details.elided'
]);
helper.registerPlugin(md => {
md.block.bbcode_ruler.push('details', rule);
});
if (helper.markdownIt) {
helper.registerPlugin(md => {
md.block.bbcode_ruler.push('details', rule);
});
} else {
helper.addPreProcessor(text => replaceDetails(text));
}
}