mirror of
https://github.com/discourse/discourse.git
synced 2024-12-21 21:34:19 +08:00
54a518b21d
This commit allows quoting of discourse-local-date elements and converts the quoted tags back into bbcode so that the rendered quote will also render the discourse-local-date HTML. This works on single dates as well as date ranges, and supports all of the options used by discourse-local-date. This also necessitated adding addTextDecorateCallback to the to-markdown core lib (similar to addBlockDecorateCallback and addTagDecorateCallback) to transform the text nodes between date ranges to remove the -> in the final quote. c.f. https://meta.discourse.org/t/quotes-that-contain-date-time/101999
59 lines
1.3 KiB
JavaScript
59 lines
1.3 KiB
JavaScript
import { isEmpty } from "@ember/utils";
|
|
|
|
export default function generateDateMarkup(
|
|
fromDateTime,
|
|
options,
|
|
isRange,
|
|
toDateTime
|
|
) {
|
|
let text = ``;
|
|
|
|
if (isRange) {
|
|
let from = [fromDateTime.date, fromDateTime.time]
|
|
.filter((element) => !isEmpty(element))
|
|
.join("T");
|
|
let to = [toDateTime.date, toDateTime.time]
|
|
.filter((element) => !isEmpty(element))
|
|
.join("T");
|
|
text += `[date-range from=${from} to=${to}`;
|
|
} else {
|
|
text += `[date=${fromDateTime.date}`;
|
|
}
|
|
|
|
if (fromDateTime.time && !isRange) {
|
|
text += ` time=${fromDateTime.time}`;
|
|
}
|
|
|
|
if (fromDateTime.format && fromDateTime.format.length) {
|
|
text += ` format="${fromDateTime.format}"`;
|
|
}
|
|
|
|
if (options.timezone) {
|
|
text += ` timezone="${options.timezone}"`;
|
|
}
|
|
|
|
if (options.countdown) {
|
|
text += ` countdown="${options.countdown}"`;
|
|
}
|
|
|
|
if (options.displayedTimezone) {
|
|
text += ` displayedTimezone="${options.displayedTimezone}"`;
|
|
}
|
|
|
|
if (options.timezones && options.timezones.length) {
|
|
if (Array.isArray(options.timezones)) {
|
|
text += ` timezones="${options.timezones.join("|")}"`;
|
|
} else {
|
|
text += ` timezones="${options.timezones}"`;
|
|
}
|
|
}
|
|
|
|
if (options.recurring && !isRange) {
|
|
text += ` recurring="${options.recurring}"`;
|
|
}
|
|
|
|
text += `]`;
|
|
|
|
return text;
|
|
}
|