Added support for counting sentences #4
This commit is contained in:
parent
d08cf93ee8
commit
bc1879adae
1 changed files with 14 additions and 1 deletions
15
src/main.ts
15
src/main.ts
|
@ -70,6 +70,7 @@ export default class BetterWordCount extends Plugin {
|
||||||
onQuickPreview(file: TFile, contents: string) {
|
onQuickPreview(file: TFile, contents: string) {
|
||||||
this.currentFile = file;
|
this.currentFile = file;
|
||||||
const leaf = this.app.workspace.activeLeaf;
|
const leaf = this.app.workspace.activeLeaf;
|
||||||
|
|
||||||
if (leaf && leaf.view.getViewType() === "markdown") {
|
if (leaf && leaf.view.getViewType() === "markdown") {
|
||||||
this.recentlyTyped = true;
|
this.recentlyTyped = true;
|
||||||
this.updateWordCount(contents);
|
this.updateWordCount(contents);
|
||||||
|
@ -93,6 +94,18 @@ export default class BetterWordCount extends Plugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.statusBar.displayText(`${words} words ` + `${text.length} characters`);
|
// Thanks to Extract Highlights plugin
|
||||||
|
// Also https://stackoverflow.com/questions/5553410
|
||||||
|
const sentences: number = (
|
||||||
|
(text || "").match(
|
||||||
|
/[^.!?\s][^.!?]*(?:[.!?](?!['"]?\s|$)[^.!?]*)*[.!?]?['"]?(?=\s|$)/gm
|
||||||
|
) || []
|
||||||
|
).length;
|
||||||
|
|
||||||
|
this.statusBar.displayText(
|
||||||
|
`${words} words ` +
|
||||||
|
`${text.length} characters ` +
|
||||||
|
`${sentences} sentences`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue