FIX: ensure [date-range don't clashes with checklist

Adding the "→" was not setting the proper token nesting hierarchy.
This commit is contained in:
Régis Hanol 2024-04-06 22:35:24 +02:00
parent d3f7b3b5f9
commit 36659531f7
2 changed files with 25 additions and 3 deletions

View File

@ -10,7 +10,10 @@ let currentRaw;
async function prepare(raw) { async function prepare(raw) {
const cooked = await cook(raw, { const cooked = await cook(raw, {
siteSettings: { checklist_enabled: true }, siteSettings: {
checklist_enabled: true,
discourse_local_dates_enabled: true,
},
}); });
const widget = { attrs: {}, scheduleRerender() {} }; const widget = { attrs: {}, scheduleRerender() {} };
@ -38,6 +41,23 @@ acceptance("discourse-checklist | checklist", function (needs) {
]); ]);
}); });
test("does not clash with date-range bbcode", async function (assert) {
const [$elem, updated] = await prepare(`
[date-range from=2024-03-22 to=2024-03-23]
[ ] task 1
[ ] task 2
[x] task 3
`);
assert.equal($elem.find(".discourse-local-date").length, 2);
assert.equal($elem.find(".chcklst-box").length, 3);
$elem.find(".chcklst-box")[0].click();
const output = await updated;
assert.ok(output.includes("[x] task 1"));
});
test("does not check an image URL", async function (assert) { test("does not check an image URL", async function (assert) {
const [$elem, updated] = await prepare(` const [$elem, updated] = await prepare(`
![](upload://zLd8FtsWc2ZSg3cZKIhwvhYxTcn.jpg) ![](upload://zLd8FtsWc2ZSg3cZKIhwvhYxTcn.jpg)

View File

@ -115,7 +115,7 @@ function defaultDateConfig() {
} }
function parseTagAttributes(tag) { function parseTagAttributes(tag) {
const matchString = tag.replace(/||||«|»|”/g, '"'); const matchString = tag.replace(/[‘’„“«»”]/g, '"');
return parseBBCodeTag( return parseBBCodeTag(
"[date date" + matchString + "]", "[date date" + matchString + "]",
@ -162,7 +162,9 @@ function addLocalRange(buffer, matches, state) {
addSingleLocalDate(buffer, state, config); addSingleLocalDate(buffer, state, config);
} }
if (config.range) { if (config.range) {
closeBuffer(buffer, state, "→"); const token = new state.Token("text", "", 0);
token.content = "→";
buffer.push(token);
} }
if (parsed.attrs.to) { if (parsed.attrs.to) {
[date, time] = parsed.attrs.to.split("T"); [date, time] = parsed.attrs.to.split("T");