mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 05:11:20 +08:00
FIX: Remove magic time ranges (#19477)
In #15474 we introduced dedicated support for date ranges. As part of that change we added a fallback of "magic" date ranges, which treats dates in any paragraph with exactly two dates as a range. There were discussions about migrating all such paragraphs to use the new date range element, but it was ultimately decided against. This change removes the fallback and, as a bonus, adds support for multiple date ranges in the same paragraph.
This commit is contained in:
@ -124,18 +124,24 @@ function _rangeElements(element) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// TODO: element.parentElement.children.length !== 2 is a fallback to old solution for ranges
|
||||
// Condition can be removed after migration to [date-range]
|
||||
if (
|
||||
element.dataset.range !== "true" &&
|
||||
element.parentElement.children.length !== 2
|
||||
) {
|
||||
return [element];
|
||||
if (element.dataset.range) {
|
||||
return _partitionedRanges(element).find((pair) => pair.includes(element));
|
||||
}
|
||||
|
||||
return Array.from(element.parentElement.children).filter(
|
||||
(span) => span.dataset.date
|
||||
return [element];
|
||||
}
|
||||
|
||||
function _partitionedRanges(element) {
|
||||
const partitions = [];
|
||||
const ranges = Array.from(element.parentElement.children).filter(
|
||||
(span) => span.dataset.range
|
||||
);
|
||||
|
||||
while (ranges.length > 0) {
|
||||
partitions.push(ranges.splice(0, 2));
|
||||
}
|
||||
|
||||
return partitions;
|
||||
}
|
||||
|
||||
function initializeDiscourseLocalDates(api) {
|
||||
|
Reference in New Issue
Block a user