FEATURE: date-range tag for local dates (#15474)

New range tag for local dates with syntax like:
```
[date-range from=2022-01-06T13:00 to=2022-01-08 timezone=Australia/Sydney]
```

Previously, 2 dates in one line were considered as range. It was hard to decide if 2 dates are range when they were in separate lines or have some content between them.

New explicit tag should clearly distinguish between single date and range.

Common code from `addLocalDate` is extracted to `addSingleLocalDate`.

Both `addLocalDate` and new `addLocalRange` are using `addSingleLocalDate`.

Also, `defaultDateConfig` was extracted to have one place for all possible parameters.
This commit is contained in:
Krzysztof Kotlarek
2022-01-10 08:02:36 +01:00
committed by GitHub
parent fff8b98485
commit 17ec3bc5b9
4 changed files with 151 additions and 42 deletions

View File

@ -69,6 +69,16 @@ function _rangeElements(element) {
if (!element.parentElement) {
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];
}
return Array.from(element.parentElement.children).filter(
(span) => span.dataset.date
);