OleMchls/atom-wordcount

Suggestion: Exclude html comments

Closed this issue ยท 18 comments

I use html comments in Markdown so it would be great if there was an option to exclude words from inside comments.

I'd love to see a PR for this. But please add a single option to exclude comments, and then detect them with a mapping indicated from the file type.

Hello guys! I had the same need to not comment HTML. My friend made a little addition in the code. Do you think it's interesting that I do "pull request"?

@vict0rg sure thing send the PR over. We can discuss actual code/implementation over there. ๐Ÿ‘

@OleMchls I'm totally new on github... Excuse me... I'll post here...

At line 65 of file wordcount-view.cofee (wordcount 2.10.4) I change

codePatterns = [/{3}(.|\s)*?({3}|$)/g, /[ ]{4}.*?$/gm]

to

codePatterns = [/{3}(.|\s)*?({3}|$)/g, /[ ]{4}.*?$/gm, /<!--[\s\S]*?-->/g, /{[\s\S]*?}/g, /#[\s\S]*?/g]

Explanation:

, /<!--[\s\S]*?-->/g # Exclude comment html markup

, /{[\s\S]*?}/g # Exclude all info between { } - Helpfull for those like me that use Zotero Plugin ODF/RTF Scan (These are the markings to Scanable Cite)

, /#[\s\S]*?/g # Will ignore the "#" markdown because it is being counted as a word

@vict0rg don't worry, we all start at some point, here is a great tutorial on how to submit your first PR: https://github.com/CPAN-PRC/resources/wiki/My-first-Pull-Request

@vict0rg - do you still plan on submitting a PR or need help doing so? I'd love to have this feature as well. Was getting ready to fork and work on it when I saw this open issue.

@danielbayley feel free to submit a PR if you wont hear anything back from @vict0rg :)

@OleMchls Wrong d! ๐Ÿ˜‰
@davidldayโ€ฆ

My bad! Sorry

@OleMchls - No worries! I'll wait a little bit longer for a response, then proceed. ty!

I had some well working regexes, put them in and saw how easy the code was to modify. Didn't realise there was a discussion on it until I actually made the PR. Woooops.
Hope no one is offended. @davidlday @vict0rg

I also have a separate option for excluding block quotes (which is helpful in case you need to count your own words rather than other people's words).
#94

@mbroedl - no offense taken! I just want the feature and don't care who implements it.

@davidlday Great. Have you checked out the PR (#94)? :)
Let me know if it causes any issues.
@OleMchls any thought on the PR?

@mbroedl - I took a look at the code (haven't had time to test), and I noted that the options you added seem to conflict with what @OleMchls stated above:

I'd love to see a PR for this. But please add a single option to exclude comments, and then detect them with a mapping indicated from the file type.

Perhaps you can generalize the config options instead of making them specific to Markdown? I think the rest of the code looks good, but as I said, no chance to test yet.

I've thought about it, albeit only now. It does make sense, to have this, but:

Then the settings already have an array containing the file extensions on which the package would be auto-activated. So when implemented properly, there needed to be an input with grammars on which the stripping of text is activated.

I'm not familiar with the individual grammars, but I can't see why the already existing stripping of code blocks is not wrapped in a grammar check, when this would be warranted for html-comments.

Conclusion: Thinking more about it, and looking at other feature requests, maybe it would be actually even more helpful, to instead have a settings object with grammars and regexes that are stripped before counting? This way the individual user has full control over which regex can be used in which grammar?

Either way, it's implemented now. :)

As my personal time is limited and I do not want this project to get stuck in a dead end. We'll move towards a more open contribution model. As the PR provided by @mbroedl added value to the project I am fine merging it. I still think too many options hurt the project. But I or anyone else could always file a PR for that. And I do not want to be a gate keeper to added value for this project.

I think this issue can be closed with that. I will release a new version later today. LMK if you think it should not be closed.