From bca416f407a9cf7aaf8f6feedb7b41b688907b41 Mon Sep 17 00:00:00 2001 From: invstia Date: Tue, 17 Sep 2024 23:34:22 +0200 Subject: [PATCH] Fix: Replace Node.js Buffer with TextEncoder/TextDecoder for mobile compatibility - Replaced the use of Buffer with TextEncoder and TextDecoder in the pretty function. - Added comments explaining that Buffer is not compatible with mobile versions of Obsidian due to reliance on Node.js-specific APIs. - Ensures UTF-8 encoding is maintained without breaking compatibility across different environments. --- src/IcalService.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/IcalService.ts b/src/IcalService.ts index c11bc75..d8b1f94 100644 --- a/src/IcalService.ts +++ b/src/IcalService.ts @@ -194,10 +194,17 @@ export class IcalService { calendar = calendar.replace('~(*BSR_ANYCRLF)\R~', '\r\n'); // Line length should not be longer than 75 characters (https://icalendar.org/iCalendar-RFC-5545/3-1-content-lines.html) - //#TODO I can't be bothered implementing this *should* requirement + //#TODO I can't be bothered implementing this *should* requirement + + // Buffer is not used here because it relies on Node.js-specific APIs like Buffer.from and Buffer.toString, + // which are not available in environments like mobile versions of Obsidian. + // Instead, TextEncoder and TextDecoder are used for compatibility. // Ensure we are UTF-8 - calendar = Buffer.from(calendar, 'utf8').toString('utf8'); + const encoder = new TextEncoder(); + const decoder = new TextDecoder('utf-8'); + const encoded = encoder.encode(calendar); + calendar = decoder.decode(encoded); return calendar; }