generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
262 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
## Obsidian Pangu Plugin | ||
|
||
A small plugin aims to add space between Chinese Characters and English Alphabet, powered by [pangu.js](https://github.com/vinta/pangu.js). | ||
|
||
For Example: | ||
A small plugin aims to add space between Chinese Characters and English Alphabet, For Example: | ||
|
||
```diff | ||
- 大多数人在20到30岁就已经过完自己的一生;一过了这个年龄段,他们就变成自己的影子。 | ||
+ 大多数人在 20 到 30 岁就已经过完自己的一生;一过了这个年龄段,他们就变成自己的影子。 | ||
``` | ||
### How to use | ||
|
||
- Clone this repo. | ||
- `npm i` or `yarn` to install dependencies | ||
- `npm run dev` to start compilation in watch mode. | ||
## Manual installation | ||
Download zip archive from [GitHub releases page](https://github.com/natumsol/obsidian-pangu/releases). | ||
Extract the archive into `<vault>/.obsidian/plugins`. | ||
|
||
### Manually installing the plugin | ||
Alternatively, using bash: | ||
```bash | ||
OBSIDIAN_VAULT_DIR=/path/to/your/obsidian/vault | ||
mkdir -p $OBSIDIAN_VAULT_DIR/.obsidian/plugins | ||
unzip ~/Downloads/obsidian-pangu_v1.1.0.zip -d $OBSIDIAN_VAULT_DIR/.obsidian/plugins | ||
``` | ||
|
||
- Copy over `main.js`, `styles.css`, `manifest.json` to your vault `VaultFolder/.obsidian/plugins/your-plugin-id/`. | ||
### Thanks | ||
|
||
Thanks to [pangu.vim](https://github.com/hotoo/pangu.vim), [writing4cn](https://marketplace.visualstudio.com/items?itemName=twocucao.writing4cn) and [pangu-markdown-vscode ](https://github.com/zhuyuanxiang/pangu-markdown-vscode) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
export default { | ||
condenseContent(content: string): string { | ||
// 将 制表符 改成 四个空格 | ||
content = content.replace(/\t/g, " "); | ||
|
||
// 删除超过2个的回车 | ||
// Unix 的只有 LF,Windows 的需要 CR LF | ||
content = content.replace(/(\n){3,}/g, "$1$1"); | ||
content = content.replace(/(\r\n){3,}/g, "$1$1"); | ||
return content; | ||
}, | ||
deleteSpaces(content: string): string { | ||
// 去掉「`()[]{}<>'"`」: 前后多余的空格 | ||
content = content.replace(/\s+([\(\)\[\]\{\}<>'":])\s+/g, ' $1 '); | ||
|
||
// 去掉连续括号增加的空格,例如:「` ( [ { < > } ] ) `」 | ||
content = content.replace(/([<\(\{\[])\s([<\(\{\[])\s/g, "$1$2 "); | ||
content = content.replace(/([<\(\{\[])\s([<\(\{\[])\s/g, "$1$2 "); | ||
content = content.replace(/([<\(\{\[])\s([<\(\{\[])\s/g, "$1$2 "); | ||
content = content.replace(/([<\(\{\[])\s([<\(\{\[])\s/g, "$1$2 "); | ||
content = content.replace(/\s([>\)\]\}])\s([>\)\]\}])/g, " $1$2"); | ||
content = content.replace(/\s([>\)\]\}])\s([>\)\]\}])/g, " $1$2"); | ||
content = content.replace(/\s([>\)\]\}])\s([>\)\]\}])/g, " $1$2"); | ||
content = content.replace(/\s([>\)\]\}])\s([>\)\]\}])/g, " $1$2"); | ||
|
||
// 去掉 「`$ () $`」, 「`$ [] $`」, 「`$ {} $`」 里面增加的空格 | ||
// 去掉开始 $ 后面增加的空格,结束 $ 前面增加的空格 | ||
// 去掉包裹代码的符号里面增加的空格 | ||
// 去掉开始 ` 后面增加的空格,结束 ` 前面增加的空格 | ||
content = content.replace(/([`\$])\s*([<\(\[\{])([^\$]*)\s*([`\$])/g, "$1$2$3$4"); | ||
content = content.replace(/([`\$])\s*([^\$]*)([>\)\]\}])\s*([`\$])/g, "$1$2$3$4"); | ||
|
||
// 去掉「`) _`」、「`) ^`」增加的空格 | ||
content = content.replace(/\)\s([_\^])/g, ")$1"); | ||
|
||
// 去掉 [^footnote,2002] 中的空格 | ||
content = content.replace(/\[\s*\^([^\]\s]*)\s*\]/g, "[^$1]"); | ||
|
||
// 将链接的格式中文括号“[]()”改成英文括号“[]()”,去掉增加的空格 | ||
content = content.replace(/\s*\[\s*([^\]]+)\s*\]\s*[((]\s*([^\s\)]*)\s*[))]\s*/g, " [$1]($2) "); | ||
|
||
// 将图片链接的格式中的多余空格“! []()”去掉,变成“![]()” | ||
content = content.replace(/!\s*\[\s*([^\]]+)\s*\]\s*[((]\s*([^\s\)]*)\s*[))]\s*/g, "![$1]($2) "); | ||
|
||
// 将网络地址中“ : // ”符号改成“://” | ||
content = content.replace(/\s*:\s*\/\s*\/\s*/g, "://"); | ||
|
||
// 去掉行末空格 | ||
content = content.replace(/(\S*)\s*$/g, '$1'); | ||
|
||
// 去掉「123 °」和 「15 %」中的空格 | ||
content = content.replace(/([0-9])\s*([°%])/g, '$1$2'); | ||
|
||
// 去掉 2020 - 04 - 20, 08 : 00 : 00 这种日期时间表示的数字内的空格 | ||
content = content.replace(/([0-9])\s*-\s*([0-9])/g, "$1-$2"); | ||
content = content.replace(/([0-9])\s*:\s*([0-9])/g, "$1:$2"); | ||
|
||
// 去掉 1 , 234 , 567 这种千分位表示的数字内的空格 | ||
content = content.replace(/([0-9])\s*,\s*([0-9])/g, "$1,$2"); | ||
|
||
// 全角標點與其他字符之間不加空格 | ||
// 将无序列表的-后面的空格保留 | ||
// 将有序列表的-后面的空格保留 | ||
content = content.replace(/^(?<![-|\d.]\s*)\s*([,。、《》?『』「」;∶【】{}—!@¥%…()])\s*/g, "$1"); | ||
return content; | ||
}, | ||
|
||
insertSpace(content: string): string { | ||
// 在 “中文English” 之间加入空格 “中文 English” | ||
// 在 “中文123” 之间加入空格 “中文 123” | ||
content = content.replace(/([\u4e00-\u9fa5\u3040-\u30FF])([a-zA-Z0-9`])/g, '$1 $2'); | ||
|
||
// 在 “English中文” 之间加入空格 “English 中文” | ||
// 在 “123中文” 之间加入空格 “123 中文” | ||
content = content.replace(/([a-zA-Z0-9%`])([*]*[\u4e00-\u9fa5\u3040-\u30FF])/g, "$1 $2"); | ||
|
||
// 在 「I said:it's a good news」的冒号与英文之间加入空格 「I said: it's a good news」 | ||
content = content.replace(/([:])\s*([a-zA-z])/g, "$1 $2"); | ||
return content; | ||
}, | ||
replacePunctuations(content: string): string { | ||
// `, \ . : ; ? !` 改成 `,、。:;?!` | ||
// 必须在结尾或者有空格的点才被改成句号 | ||
content = content.replace(/([\u4e00-\u9fa5\u3040-\u30FF])\.($|\s*)/g, '$1。'); | ||
content = content.replace(/([\u4e00-\u9fa5\u3040-\u30FF]),/g, '$1,'); | ||
content = content.replace(/([\u4e00-\u9fa5\u3040-\u30FF]);/g, '$1;'); | ||
content = content.replace(/([\u4e00-\u9fa5\u3040-\u30FF])!/g, '$1!'); | ||
content = content.replace(/([\u4e00-\u9fa5\u3040-\u30FF])\?/g, '$1?'); | ||
content = content.replace(/([\u4e00-\u9fa5\u3040-\u30FF])\\/g, '$1、'); | ||
content = content.replace(/([\u4e00-\u9fa5\u3040-\u30FF])\s*\:/g, '$1:'); | ||
|
||
// 簡體中文使用直角引號 | ||
content = content.replace(/‘/g, "『"); | ||
content = content.replace(/’/g, "』"); | ||
content = content.replace(/“/g, "「"); | ||
content = content.replace(/”/g, "」"); | ||
// 括号使用半角标点 | ||
// 半角括号的两边都有空格就不在这里处理了,放到行中处理 | ||
content = content.replace(/\s*[((]\s*/g, " ( "); | ||
content = content.replace(/\s*[))]\s*/g, " ) "); | ||
|
||
// 英文和数字内部的全角标点 `,。;‘’“”:?!@#%&-=+{}【】|\~`改成半角标点 | ||
content = content.replace(/(\w)\s*,\s*(\w)/g, "$1, $2"); | ||
content = content.replace(/(\w)\s*。\s*(\w)/g, "$1. $2"); | ||
content = content.replace(/(\w)\s*;\s*(\w)/g, "$1; $2"); | ||
content = content.replace(/(\w)\s*‘\s*(\w)/g, "$1 '$2"); | ||
content = content.replace(/(\w)\s*’\s*(\w)/g, "$1' $2"); | ||
content = content.replace(/(\w)\s*“\s*(\w)/g, '$1 "$2'); | ||
content = content.replace(/(\w)\s*”\s*(\w)/g, '$1" $2'); | ||
content = content.replace(/(\w)\s*:\s*(\w)/g, "$1: $2"); | ||
content = content.replace(/(\w)\s*?\s*(\w)/g, "$1? $2"); | ||
content = content.replace(/(\w)\s*!\s*(\w)/g, "$1! $2"); | ||
content = content.replace(/(\w)\s*@\s*(\w)/g, "$1@$2"); | ||
content = content.replace(/(\w)\s*#\s*(\w)/g, "$1#$2"); | ||
content = content.replace(/(\w)\s*%\s*(\w)/g, "$1 % $2"); | ||
content = content.replace(/(\w)\s*&\s*(\w)/g, "$1 & $2"); | ||
content = content.replace(/(\w)\s*-\s*(\w)/g, "$1 - $2"); | ||
content = content.replace(/(\w)\s*=\s*(\w)/g, "$1 = $2"); | ||
content = content.replace(/(\w)\s*+\s*(\w)/g, "$1 + $2"); | ||
content = content.replace(/(\w)\s*{\s*(\w)/g, "$1 {$2"); | ||
content = content.replace(/(\w)\s*}\s*(\w)/g, "$1} $2"); | ||
content = content.replace(/(\w)\s*[【\[]\s*(\w)/g, "$1 [$2"); | ||
content = content.replace(/(\w)\s*[】\]]\s*(\w)/g, "$1] $2"); | ||
content = content.replace(/(\w)\s*|\s*(\w)/g, "$1 | $2"); | ||
content = content.replace(/(\w)\s*\\s*(\w)/g, "$1 \ $2"); | ||
content = content.replace(/(\w)\s*~\s*(\w)/g, "$1~$2"); | ||
// 连续三个以上的 `。` 改成 `......` | ||
content = content.replace(/[。]{3,}/g, '……'); | ||
// 截断连续超过一个的 ?和! 为一个,「!?」也算一个 | ||
content = content.replace(/([!?]+)\1{1,}/g, '$1'); | ||
// 截断连续超过一个的 。,;:、“”『』〖〗《》 为一个 | ||
content = content.replace(/([。,;:、“”『』〖〗《》【】])\1{1,}/g, '$1'); | ||
return content; | ||
}, | ||
|
||
replaceFullNumbers(content: string): string { | ||
" 全角数字。"; | ||
content = content.replace(/0/g, "0"); | ||
content = content.replace(/1/g, "1"); | ||
content = content.replace(/2/g, "2"); | ||
content = content.replace(/3/g, "3"); | ||
content = content.replace(/4/g, "4"); | ||
content = content.replace(/5/g, "5"); | ||
content = content.replace(/6/g, "6"); | ||
content = content.replace(/7/g, "7"); | ||
content = content.replace(/8/g, "8"); | ||
content = content.replace(/9/g, "9"); | ||
return content; | ||
}, | ||
|
||
replaceFullChars(content: string): string { | ||
" 全角英文和标点。"; | ||
content = content.replace(/A/g, "A"); | ||
content = content.replace(/B/g, "B"); | ||
content = content.replace(/C/g, "C"); | ||
content = content.replace(/D/g, "D"); | ||
content = content.replace(/E/g, "E"); | ||
content = content.replace(/F/g, "F"); | ||
content = content.replace(/G/g, "G"); | ||
content = content.replace(/H/g, "H"); | ||
content = content.replace(/I/g, "I"); | ||
content = content.replace(/J/g, "J"); | ||
content = content.replace(/K/g, "K"); | ||
content = content.replace(/L/g, "L"); | ||
content = content.replace(/M/g, "M"); | ||
content = content.replace(/N/g, "N"); | ||
content = content.replace(/O/g, "O"); | ||
content = content.replace(/P/g, "P"); | ||
content = content.replace(/Q/g, "Q"); | ||
content = content.replace(/R/g, "R"); | ||
content = content.replace(/S/g, "S"); | ||
content = content.replace(/T/g, "T"); | ||
content = content.replace(/U/g, "U"); | ||
content = content.replace(/V/g, "V"); | ||
content = content.replace(/W/g, "W"); | ||
content = content.replace(/X/g, "X"); | ||
content = content.replace(/Y/g, "Y"); | ||
content = content.replace(/Z/g, "Z"); | ||
content = content.replace(/a/g, "a"); | ||
content = content.replace(/b/g, "b"); | ||
content = content.replace(/c/g, "c"); | ||
content = content.replace(/d/g, "d"); | ||
content = content.replace(/e/g, "e"); | ||
content = content.replace(/f/g, "f"); | ||
content = content.replace(/g/g, "g"); | ||
content = content.replace(/h/g, "h"); | ||
content = content.replace(/i/g, "i"); | ||
content = content.replace(/j/g, "j"); | ||
content = content.replace(/k/g, "k"); | ||
content = content.replace(/l/g, "l"); | ||
content = content.replace(/m/g, "m"); | ||
content = content.replace(/n/g, "n"); | ||
content = content.replace(/o/g, "o"); | ||
content = content.replace(/p/g, "p"); | ||
content = content.replace(/q/g, "q"); | ||
content = content.replace(/r/g, "r"); | ||
content = content.replace(/s/g, "s"); | ||
content = content.replace(/t/g, "t"); | ||
content = content.replace(/u/g, "u"); | ||
content = content.replace(/v/g, "v"); | ||
content = content.replace(/w/g, "w"); | ||
content = content.replace(/x/g, "x"); | ||
content = content.replace(/y/g, "y"); | ||
content = content.replace(/z/g, "z"); | ||
return content; | ||
}, | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,5 @@ | |
"tslib": "^2.0.3", | ||
"typescript": "^4.0.3" | ||
}, | ||
"dependencies": { | ||
"pangu": "^4.0.7" | ||
} | ||
"dependencies": {} | ||
} |