correct more specs
This commit is contained in:
parent
f1b38ba4fb
commit
40bcc6bbdc
|
@ -1,9 +1,10 @@
|
||||||
import { cook as cookIt, setup as setupIt } from 'pretty-text/engines/discourse-markdown-it';
|
import { cook as cookIt, setup as setupIt } from 'pretty-text/engines/discourse-markdown-it';
|
||||||
|
|
||||||
export function registerOption() {
|
export function registerOption() {
|
||||||
if (window.console) {
|
// TODO next major version deprecate this
|
||||||
window.console.log("registerOption is deprecated");
|
// if (window.console) {
|
||||||
}
|
// window.console.log("registerOption is deprecated");
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildOptions(state) {
|
export function buildOptions(state) {
|
||||||
|
|
|
@ -1,25 +1,3 @@
|
||||||
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 = {
|
const rule = {
|
||||||
tag: 'details',
|
tag: 'details',
|
||||||
before: function(state, attrs) {
|
before: function(state, attrs) {
|
||||||
|
@ -46,11 +24,7 @@ export function setup(helper) {
|
||||||
'details.elided'
|
'details.elided'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (helper.markdownIt) {
|
helper.registerPlugin(md => {
|
||||||
helper.registerPlugin(md => {
|
md.block.bbcode_ruler.push('details', rule);
|
||||||
md.block.bbcode_ruler.push('details', rule);
|
});
|
||||||
});
|
|
||||||
} else {
|
|
||||||
helper.addPreProcessor(text => replaceDetails(text));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ const defaultOpts = buildOptions({
|
||||||
emoji_set: 'emoji_one',
|
emoji_set: 'emoji_one',
|
||||||
highlighted_languages: 'json|ruby|javascript',
|
highlighted_languages: 'json|ruby|javascript',
|
||||||
default_code_lang: 'auto',
|
default_code_lang: 'auto',
|
||||||
censored_words: 'shucks|whiz|whizzer'
|
censored_words: ''
|
||||||
},
|
},
|
||||||
getURL: url => url
|
getURL: url => url
|
||||||
});
|
});
|
||||||
|
@ -19,17 +19,13 @@ test("details", assert => {
|
||||||
assert.equal(new PrettyText(defaultOpts).cook(input), expected.replace(/\/>/g, ">"), text);
|
assert.equal(new PrettyText(defaultOpts).cook(input), expected.replace(/\/>/g, ">"), text);
|
||||||
};
|
};
|
||||||
cooked(`<details><summary>Info</summary>coucou</details>`,
|
cooked(`<details><summary>Info</summary>coucou</details>`,
|
||||||
`<details><summary>Info</summary>\n\n<p>coucou</p>\n\n</details>`,
|
`<details><summary>Info</summary>coucou</details>`,
|
||||||
"manual HTML for details");
|
"manual HTML for details");
|
||||||
cooked(` <details><summary>Info</summary>coucou</details>`,
|
|
||||||
`<details><summary>Info</summary>\n\n<p>coucou</p>\n\n</details>`,
|
|
||||||
"manual HTML for details with a space");
|
|
||||||
|
|
||||||
cooked(`<details open="open"><summary>Info</summary>coucou</details>`,
|
cooked("[details=testing]\ntest\n[/details]",
|
||||||
`<details open="open"><summary>Info</summary>\n\n<p>coucou</p>\n\n</details>`,
|
`<details>
|
||||||
"open attribute");
|
<summary>
|
||||||
|
testing</summary>
|
||||||
cooked(`<details open><summary>Info</summary>coucou</details>`,
|
<p>test</p>
|
||||||
`<details open><summary>Info</summary>\n\n<p>coucou</p>\n\n</details>`,
|
</details>`);
|
||||||
"open attribute");
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue