Comments (3)
Will be adding more metrics over time. This included thank you for your suggestion.
from better-word-count.
+1 to whitespace-filtering - spaces, newlines, tabs, all of it. I have a couple of projects to hand in which actually have a minimum character count which is excluding whitespace, citations, references, indices and titles, and the current solution is to copy the manuscripts, strip them of spaces and count that in a manual file - which of course is kind of a terrible solution.
from better-word-count.
It looks like I forgot to make that setting do anything.
lukeleppan, in his comment in #61
That was what made me confused as well when I was going through it for modding purposes.
Short question. As I see it, the # of characters/words to be displayed in status bar are counted by getCharacterCount()
& getWordCount()
, correct?
So the quick'n'dirty, but should-be-working solution for f.e. excluding whitespace would be modding the getCharacterCount()
- function:
function getCharacterCount(text,settings) {
// ~Gw: modifications to this function and its calls to allow for easy exclusion via regex. - 27.01.2023 -
var textcleaned = ""
var initiallength = 0
var cleanedlength = 0
initiallength = text.length
textcleaned = text
if (typeof settings==="object") {
var dontcountWhitespace = settings.dontcountWhitespace
var dontcountHTMLComments = settings.dontcountHTMLComments
}
else {
var dontcountWhitespace = settings // ~Gw: merely here because I have not figured out how to feed the settings to calcTotalCharacters() to be fed in here yet.
}
if (dontcountWhitespace) {
if (textcleaned.match(/\s+/g)){
textcleaned = textcleaned.replace(/\s+/g, '') // ~Gw: replace whitespace
}
}
if (dontcountHTMLComments) {
if (textcleaned.match(/(?=<!--)([\s\S]*?)-->/g)){
textcleaned = textcleaned.replace(/(?=<!--)([\s\S]*?)-->/g, '') // ~Gw: replace HTML comments
}
}
cleanedlength = textcleaned.length
return cleanedlength
}
I made it expandable for now in case I want to add more settings to exclude. What I haven't figured out yet is where/how calcTotalCharacters()
fetches the plugin settings - but I am also not using that feature at all so far, so for now that case just doesn't work.
Then all that needs to be done is add the respective variable to data.json
, modify the class BetterWordCountSettingsTab
to contain a setting for this and be done (I think).
Again, just theorising, reading through the code and looking up a few things online - I don't write in JS at all, so take it with a grain of salt - but this should work.
Further Todo's I'm thinking about would be to add an option to count both, because sometimes you actually want both simultaneously. Maybe make it its own count, or change charactercount into an array and refer to the index of / depending on the respective settings?
Edit: forgot global flags in needle :P
Edit2: slightly reworked function for better expandability.
from better-word-count.
Related Issues (20)
- Status not showing initially
- Only display rounded statistics HOT 1
- Feature request: Character count of current section HOT 5
- Sometimes on New Notes, Daily Word Count does not increment, even while other words counts do increment
- Showing status bar on a new window
- List item prefixes are counted as words
- exclude whitespace HOT 1
- Feature Request: count of current section sticky on the screen
- [Feature Request] Ability to format numbers to show thousand separators
- Setting text fields to nothing in plugin options breaks plugin
- Straight single quote `'` and closing curly quote `’` are counted as one extra word after any dot punctuation `.?!`
- Feature Request: Add support for daily metric in the current note
- Feature Request: Add command to copy the current statistics
- Feature request: Line count
- Feature Request: Print section word-count in PDF export
- stopped working HOT 2
- Suggestion for mobile: Create a command that can be added to ribbon using Commander
- Plugin doesn't update upon viewing a file in Reader View
- Section Word Count, less words.
- Follow developer guidelines for headings in plugin settings
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from better-word-count.