Merge pull request #378 from Nico-J/bugfix/remove-fancy-html
(Conditionally) remove HTML from event description
This commit is contained in:
commit
ca5fac4203
3 changed files with 23 additions and 3 deletions
|
@ -86,4 +86,13 @@ export default class CalEventParser {
|
||||||
eventCopy.description = this.getRichDescriptionHtml();
|
eventCopy.description = this.getRichDescriptionHtml();
|
||||||
return eventCopy;
|
return eventCopy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a calendar event with rich description as plain text.
|
||||||
|
*/
|
||||||
|
public asRichEventPlain(): CalendarEvent {
|
||||||
|
const eventCopy: CalendarEvent = { ...this.calEvent };
|
||||||
|
eventCopy.description = this.getRichDescription();
|
||||||
|
return eventCopy;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -508,7 +508,12 @@ const listCalendars = (withCredentials) =>
|
||||||
const createEvent = async (credential: Credential, calEvent: CalendarEvent): Promise<unknown> => {
|
const createEvent = async (credential: Credential, calEvent: CalendarEvent): Promise<unknown> => {
|
||||||
const parser: CalEventParser = new CalEventParser(calEvent);
|
const parser: CalEventParser = new CalEventParser(calEvent);
|
||||||
const uid: string = parser.getUid();
|
const uid: string = parser.getUid();
|
||||||
const richEvent: CalendarEvent = parser.asRichEvent();
|
/*
|
||||||
|
* Matching the credential type is a workaround because the office calendar simply strips away newlines (\n and \r).
|
||||||
|
* We need HTML there. Google Calendar understands newlines and Apple Calendar cannot show HTML, so no HTML should
|
||||||
|
* be used for Google and Apple Calendar.
|
||||||
|
*/
|
||||||
|
const richEvent: CalendarEvent = parser.asRichEventPlain();
|
||||||
|
|
||||||
const creationResult = credential ? await calendars([credential])[0].createEvent(richEvent) : null;
|
const creationResult = credential ? await calendars([credential])[0].createEvent(richEvent) : null;
|
||||||
|
|
||||||
|
@ -555,7 +560,7 @@ const updateEvent = async (
|
||||||
): Promise<unknown> => {
|
): Promise<unknown> => {
|
||||||
const parser: CalEventParser = new CalEventParser(calEvent);
|
const parser: CalEventParser = new CalEventParser(calEvent);
|
||||||
const newUid: string = parser.getUid();
|
const newUid: string = parser.getUid();
|
||||||
const richEvent: CalendarEvent = parser.asRichEvent();
|
const richEvent: CalendarEvent = parser.asRichEventPlain();
|
||||||
|
|
||||||
const updateResult = credential
|
const updateResult = credential
|
||||||
? await calendars([credential])[0].updateEvent(uidToUpdate, richEvent)
|
? await calendars([credential])[0].updateEvent(uidToUpdate, richEvent)
|
||||||
|
|
|
@ -25,5 +25,11 @@ export function getFormattedMeetingId(videoCallData: VideoCallData): string {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function stripHtml(html: string): string {
|
export function stripHtml(html: string): string {
|
||||||
return html.replace("<br />", "\n").replace(/<[^>]+>/g, "");
|
const aMailToRegExp = /<a[\s\w="_:#;]*href="mailto:([^<>"]*)"[\s\w="_:#;]*>([^<>]*)<\/a>/g;
|
||||||
|
const aLinkRegExp = /<a[\s\w="_:#;]*href="([^<>"]*)"[\s\w="_:#;]*>([^<>]*)<\/a>/g;
|
||||||
|
return html
|
||||||
|
.replace(/<br\s?\/>/g, "\n")
|
||||||
|
.replace(aMailToRegExp, "$1")
|
||||||
|
.replace(aLinkRegExp, "$2: $1")
|
||||||
|
.replace(/<[^>]+>/g, "");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue