Skip to content

Commit

Permalink
release: 0.39.22
Browse files Browse the repository at this point in the history
  • Loading branch information
RyotaUshio committed Apr 24, 2024
1 parent 6f93d3d commit f22f07f
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 37 deletions.
2 changes: 1 addition & 1 deletion manifest-beta.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "pdf-plus",
"name": "PDF++",
"version": "0.39.21",
"version": "0.39.22",
"minAppVersion": "1.4.16",
"description": "The most Obsidian-native PDF annotation tool ever.",
"author": "Ryota Ushio",
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "pdf-plus",
"name": "PDF++",
"version": "0.39.21",
"version": "0.39.22",
"minAppVersion": "1.4.16",
"description": "The most Obsidian-native PDF annotation tool ever.",
"author": "Ryota Ushio",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-pdf-plus",
"version": "0.39.21",
"version": "0.39.22",
"description": "The most Obsidian-native PDF annotation tool ever.",
"scripts": {
"dev": "node esbuild.config.mjs",
Expand Down
1 change: 1 addition & 0 deletions release
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ if __name__ == '__main__':

old_version = manifest['version']
diff = subprocess.run(['git', 'diff', f'{old_version}..', 'src', 'styles.css'], capture_output=True, text=True).stdout
diff = diff or subprocess.run(['git', 'diff', '--cached', 'src', 'styles.css'], capture_output=True, text=True).stdout
if not diff:
print('No changes to release. Perhaps you forgot to merge the dev branch?', file=sys.stderr)
exit(1)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,6 @@ export class PDFPlusLib {

/** Process (possibly) multiline strings cleverly to convert it into a single line string. */
toSingleLine(str: string): string {
return toSingleLine(str, this.plugin.settings.removeWhitespaceBetweenCJKChars);
return toSingleLine(str, this.plugin.settings.removeWhitespaceBetweenCJChars);
}
}
2 changes: 2 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ export default class PDFPlus extends Plugin {
this.renameSetting('selectToCopyToggleRibbonIcon', 'autoCopyToggleRibbonIcon');
this.renameCommand('pdf-plus:toggle-select-to-copy', `${this.manifest.id}:toggle-auto-copy`);

this.renameSetting('removeWhitespaceBetweenCJKChars', 'removeWhitespaceBetweenCJChars');

this.loadContextMenuConfig();
}

Expand Down
8 changes: 4 additions & 4 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export interface PDFPlusSettings {
enableBibInEmbed: boolean;
enableBibInHoverPopover: boolean;
enableBibInCanvas: boolean;
removeWhitespaceBetweenCJKChars: boolean;
removeWhitespaceBetweenCJChars: boolean;
vim: boolean;
}

Expand Down Expand Up @@ -513,7 +513,7 @@ export const DEFAULT_SETTINGS: PDFPlusSettings = {
enableBibInEmbed: false,
enableBibInHoverPopover: false,
enableBibInCanvas: true,
removeWhitespaceBetweenCJKChars: true,
removeWhitespaceBetweenCJChars: true,
vim: false,
};

Expand Down Expand Up @@ -2826,8 +2826,8 @@ export class PDFPlusSettingTab extends PluginSettingTab {
'This is a temporary fix for the issue that PDF.js (the library Obsidian\'s PDF viewer is based on) does not fulfill the PDF specification in that it renders reply annotations as if a standalone annotation.',
], setting.descEl);
});
this.addToggleSetting('removeWhitespaceBetweenCJKChars')
.setName('Remove half-width whitespace between two CJK characters when copying text')
this.addToggleSetting('removeWhitespaceBetweenCJChars')
.setName('Remove half-width whitespace between two Chinese/Japanese characters when copying text')
.setDesc('Such whitespace can be introduced as a result of poor post-processing of OCR (optical character recognition). Enable this option to remove it when copying links to text selections.');
this.addToggleSetting('vim')
.setName('Enable Vim key bindings (experimental)')
Expand Down
61 changes: 34 additions & 27 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,50 +244,57 @@ export function isAncestorOf<TreeNode extends { children: TreeNode[], parent: Tr
return false;
}

export function getCJKRegexp() {
export function getCJKRegexp(options?: Partial<{ japanese: boolean, korean: boolean }>) {
options = { japanese: true, korean: true, ...options };
let pattern = ''

// CJK Unified Ideographs
pattern += '\\u4e00-\\u9fff';
// CJK Unified Ideographs Extension A
pattern += '\\u3400-\\u4dbf';

// Hiragana
pattern += '\\u3040-\\u309F';
// Katakana
pattern += '\\u30A0-\\u30FF';
// Half-width Katakana
pattern += '\\uFF65-\\uFF9F';
// Katakana Phonetic Extensions
pattern += '\\u31F0-\\u31FF';
// Japanese Punctuation
pattern += '\\u3000-\\u303F';

// Hangul Jamo
pattern += '\\u1100-\\u11FF';
// Hangul Jamo Extended-A
pattern += '\\uA960-\\uA97F';
// Hangul Jamo Extended-B
pattern += '\\uD7B0-\\uD7FF';
// Hangul Compatibility Jamo
pattern += '\\u3130-\\u318F';
// Hangul Syllables
pattern += '\\uAC00-\\uD7AF';
if (options.japanese) {
// Hiragana
pattern += '\\u3040-\\u309F';
// Katakana
pattern += '\\u30A0-\\u30FF';
// Half-width Katakana
pattern += '\\uFF65-\\uFF9F';
// Katakana Phonetic Extensions
pattern += '\\u31F0-\\u31FF';
// Japanese Punctuation
pattern += '\\u3000-\\u303F';
}

if (options.korean) {
// Hangul Jamo
pattern += '\\u1100-\\u11FF';
// Hangul Jamo Extended-A
pattern += '\\uA960-\\uA97F';
// Hangul Jamo Extended-B
pattern += '\\uD7B0-\\uD7FF';
// Hangul Compatibility Jamo
pattern += '\\u3130-\\u318F';
// Hangul Syllables
pattern += '\\uAC00-\\uD7AF';
}

const regexp = new RegExp(`[${pattern}]`);
return regexp;
}

/** Process (possibly) multiline strings cleverly to convert it into a single line string. */
export function toSingleLine(str: string, removeWhitespaceBetweenCJKChars = false): string {
const cjkRegexp = getCJKRegexp();
export function toSingleLine(str: string, removeWhitespaceBetweenCJChars = false): string {
// Korean characters should be excluded because whitespace has a meaning in Korean.
// https://github.com/RyotaUshio/obsidian-pdf-plus/issues/173
const cjRegexp = getCJKRegexp({ korean: false });
str = str.replace(/(.?)([\r\n]+)(.?)/g, (match, prev, br, next) => {
if (cjkRegexp.test(prev) && cjkRegexp.test(next)) return prev + next;
if (cjRegexp.test(prev) && cjRegexp.test(next)) return prev + next;
if (prev === '-' && next.match(/[a-zA-Z]/)) return next;
return prev + ' ' + next;
});
if (removeWhitespaceBetweenCJKChars) {
str = str.replace(new RegExp(`(${cjkRegexp.source}) (?=${cjkRegexp.source})`, 'g'), '$1');
if (removeWhitespaceBetweenCJChars) {
str = str.replace(new RegExp(`(${cjRegexp.source}) (?=${cjRegexp.source})`, 'g'), '$1');
}
return window.pdfjsViewer.removeNullCharacters(window.pdfjsLib.normalizeUnicode(str));
}
Expand Down

0 comments on commit f22f07f

Please sign in to comment.