mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 07:53:49 +08:00
FIX: Quoting local dates bbcode regeneration (#17141)
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
This commit is contained in:
@ -0,0 +1,58 @@
|
||||
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;
|
||||
}
|
Reference in New Issue
Block a user