Skip to content

feat: add Chinese line break restoration for highlight text#333

Open
ProudBenzene wants to merge 4 commits into
hadynz:masterfrom
ProudBenzene:Linebreak
Open

feat: add Chinese line break restoration for highlight text#333
ProudBenzene wants to merge 4 commits into
hadynz:masterfrom
ProudBenzene:Linebreak

Conversation

@ProudBenzene
Copy link
Copy Markdown

Kindle strips original line breaks from highlight text and replaces them with spaces. In Chinese text, a space after sentence-ending punctuation (。!?…」) is a reliable signal of an original line break, since Chinese text normally has no inter-sentence spaces.

  • Add restoreChineseLineBreaks() function in parseBooks.ts
  • Apply restoration during highlight text processing when enabled
  • Add settings toggle (disabled by default)
image

Kindle strips original line breaks from highlight text and replaces
them with spaces. In Chinese text, a space after sentence-ending
punctuation (。!?…」』)】) is a reliable signal of an original
line break, since Chinese text normally has no inter-sentence spaces.

- Add restoreChineseLineBreaks() function in parseBooks.ts
- Apply restoration during highlight text processing when enabled
- Add settings toggle (disabled by default)
Copilot AI review requested due to automatic review settings February 19, 2026 10:58
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a feature to restore line breaks in Chinese highlight text that Kindle strips out during the export process. When Kindle exports highlights, it replaces original line breaks with spaces. In Chinese text, this creates an unusual pattern where spaces appear after sentence-ending punctuation (。!?…」』)】), which normally don't have spaces between them. The feature detects these patterns and restores the line breaks.

Changes:

  • Added restoreChineseLineBreaks() function to detect and restore line breaks in Chinese text based on punctuation patterns
  • Added a new boolean setting restoreChineseLineBreaks (disabled by default) to the settings store
  • Added a toggle in the settings UI to enable/disable the feature

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
src/sync/syncClippings/parseBooks.ts Implements the Chinese line break restoration function and integrates it into the highlight text processing pipeline
src/store/settingsStore.ts Adds the restoreChineseLineBreaks setting field, default value, and setter function
src/settings/index.ts Adds the UI toggle for the new setting in the settings panel

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/sync/syncClippings/parseBooks.ts Outdated
Comment thread src/sync/syncClippings/parseBooks.ts Outdated
Comment thread src/sync/syncClippings/parseBooks.ts Outdated
Comment thread src/sync/syncClippings/parseBooks.ts Outdated
Document that the feature is an opt-in punctuation heuristic, keep it from rewriting existing newlines, and extend tests around mixed CJK content and preserved line breaks.
Rename the line break restoration setting, store field, utility, and tests to use CJK terminology and clarify the user-facing description accordingly.
@ProudBenzene
Copy link
Copy Markdown
Author

I pushed a small follow-up update here as well.

Default behavior is still unchanged unless the setting is enabled. The following options have been added to the settings panel:

image

In addition, I think it is necessary to clarify that the rules here are not limited to CJK languages, but theoretically apply to any language that uses "。" as a period. My code works by triggering a newline replacement if it encounters full-width sentence-ending punctuation such as 。!? followed immediately by a space or tab.

Therefore, this feature is not actually tied to CJK; it is just that in most cases, only CJK languages use these full-width punctuation marks. To help users quickly understand whether they need this feature, I added the "CJK" qualifier and provided a detailed explanation in the settings panel notes.

Do you accept this explanation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants