Skip to content

Readwise 1.1.5: Fix formatting of tags #600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions aaronpoweruser.ReadwiseUnofficial/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

See Plugin [README](https://github.com/NotePlan/plugins/blob/main/aaronpoweruser.ReadwiseUnofficial/README.md) for details on available commands and use case.

## [1.1.5] Readwise 2024-10-28 (@aaronpoweruser)

- Fix formatting of Readwise tags containing spaces or '&' characters.

## [1.1.4] Readwise 2024-05-28 (@aaronpoweruser)

- Add a setting for paragraph type.
Expand Down
4 changes: 2 additions & 2 deletions aaronpoweruser.ReadwiseUnofficial/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"noteplan.minAppVersion": "3.4.0",
"plugin.id": "aaronpoweruser.ReadwiseUnofficial",
"plugin.name": "📚 Readwise Unofficial",
"plugin.version": "1.1.4",
"plugin.lastUpdateInfo": "Added paragraph type setting. Fixed links to highlights on web.\nFix sync log dates being wrong.\nAdd a sync log note. \nAdd support for daily reviews via templates",
"plugin.version": "1.1.5",
"plugin.lastUpdateInfo": "fix formatting of tags containing spaces.\nAdded paragraph type setting. Fixed links to highlights on web.\nFix sync log dates being wrong.\nAdd a sync log note. \nAdd support for daily reviews via templates",
"plugin.description": "A sync plugin for Readwise",
"plugin.author": "aaronpoweruser",
"plugin.dependencies": [],
Expand Down
9 changes: 3 additions & 6 deletions aaronpoweruser.ReadwiseUnofficial/src/NPReadwiseHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,9 @@ export function buildReadwiseMetadataHeading(source: any): string {
*/
function formatTag(tag: string): string {
const prefix = DataStore.settings.tagPrefix ?? ''
if (prefix === '') {
return `#${tag}`
} else {
return `#${prefix}/${tag}`
}
}
return `#${prefix ? `${prefix}/` : ''}${tag}`
.replace(/ /g, '_')
.replace(/&/g, 'and')}

/**
* Remove all newline characters from a string
Expand Down
4 changes: 2 additions & 2 deletions aaronpoweruser.ReadwiseUnofficial/src/NPReadwiseNotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export async function parseHighlightsAndWriteToNote(highlightSource: any): Promi
}
}
if (outputNote) {
await writeReadwiseSyncLogLine(noteTitle, highlightSource.highlights.length)
await highlightSource.highlights.map((highlight) => appendHighlightToNote(outputNote, highlight, highlightSource.source, highlightSource.asin))
await writeReadwiseSyncLogLine(noteTitle, highlightSource.highlights.length)
}
} catch (error) {
logError(pluginJson, error)
Expand All @@ -77,7 +77,7 @@ function appendHighlightToNote(outputNote: TNote, highlight: any, category: stri

if (highlight.tags !== null && highlight.tags !== '') {
for (const tag of highlight.tags) {
if (tag.name !== null && tag.name !== '' && tag.name.toLowerCase().startsWith('h') && tag.name.length === 2) {
if (tag.name !== null && tag.name !== '' && tag.name.toLowerCase().startsWith('h') && tag.name.trim().length === 2) {
const headingLevel = parseInt(tag.name.substring(1)) + 1
if (headingLevel <= 8) {
outputNote.insertHeading(removeNewlines(highlight.text), findEndOfActivePartOfNote(outputNote) + 1, headingLevel)
Expand Down
Loading