Giter Club home page Giter Club logo

Comments (3)

lukeleppan avatar lukeleppan commented on August 26, 2024

Will be adding more metrics over time. This included thank you for your suggestion.

from better-word-count.

Gewerd-Strauss avatar Gewerd-Strauss commented on August 26, 2024

+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.

Gewerd-Strauss avatar Gewerd-Strauss commented on August 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.