From 17139f7b62d360cb6efa548bbc3d2166e9dda03c Mon Sep 17 00:00:00 2001 From: Karey Higuera Date: Mon, 5 Sep 2022 20:46:17 -0400 Subject: [PATCH] fix bugs in entity replacement for emoji, CJK, and html entities --- manifest.json | 2 +- package.json | 2 +- src/util.ts | 24 ++++++++++++++---------- versions.json | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/manifest.json b/manifest.json index 15fd099..6f3902b 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-tweet-to-markdown", "name": "Tweet to Markdown", - "version": "2.10.3", + "version": "2.10.4", "minAppVersion": "0.12.17", "description": "Save tweets as Markdown files, along with their images, polls, etc.", "author": "kbravh", diff --git a/package.json b/package.json index b70f337..535dcbe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-tweet-to-markdown", - "version": "2.10.3", + "version": "2.10.4", "description": "Save tweets as beautiful markdown files in Obsidian (https://obsidian.md)", "main": "main.js", "engines": { diff --git a/src/util.ts b/src/util.ts index 95125e2..ed6ba5a 100644 --- a/src/util.ts +++ b/src/util.ts @@ -355,10 +355,11 @@ export const replaceEntities = (entities: Entities, text: string): string => { }) for (const entity of allEntities) { + const chars = [...text] text = - text.substring(0, entity.start) + + chars.slice(0, entity.start).join('') + entity.replacement + - text.substring(entity.end) + chars.slice(entity.end).join('') } urls.forEach(url => { @@ -386,7 +387,17 @@ export const buildMarkdown = async ( throw new Error('A thread tweet must have a previous author') } - let text = decode(tweet.data.text) + let text = tweet.data.text + + /** + * replace entities with markdown links + */ + if (tweet.data?.entities && plugin.settings.includeLinks) { + text = replaceEntities(tweet.data.entities, text) + } + + text = decode(text) + const user = tweet.includes.users[0] const isCondensedThreadTweet = !( @@ -404,13 +415,6 @@ export const buildMarkdown = async ( `replies: ${tweet.data.public_metrics.reply_count}`, ] - /** - * replace entities with markdown links - */ - if (tweet.data?.entities && plugin.settings.includeLinks) { - text = replaceEntities(tweet.data.entities, text) - } - const date = formatTimestamp(tweet.data.created_at, { locale: plugin.settings.dateLocale, format: plugin.settings.dateFormat, diff --git a/versions.json b/versions.json index 19f2beb..cd1c672 100644 --- a/versions.json +++ b/versions.json @@ -1,3 +1,3 @@ { - "2.10.3": "0.12.17" + "2.10.4": "0.12.17" }