Skip to content

Commit

Permalink
fix bugs in entity replacement for emoji, CJK, and html entities
Browse files Browse the repository at this point in the history
  • Loading branch information
kbravh committed Sep 6, 2022
1 parent aec0004 commit 17139f7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
24 changes: 14 additions & 10 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -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 = !(
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion versions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"2.10.3": "0.12.17"
"2.10.4": "0.12.17"
}

0 comments on commit 17139f7

Please sign in to comment.