isaaclyman / novel-word-count-obsidian

Obsidian plugin. Displays a word count or other statistic for each file, folder and vault in the File Explorer pane.
https://obsidian.md/plugins?id=novel-word-count
MIT License
86 stars 8 forks source link

Option to ignore "words" in code blocks #74

Closed HoldYourWaffle closed 10 months ago

HoldYourWaffle commented 10 months ago

Problem Code doesn't read the same way as natural language. Programming languages contain lots of small tokens that are counted as individual words, but most of these are merely skimmed by the average reader since they follow the exact same pattern every time.

This skews the estimated reading time :(

Idea An option to ignore text in code blocks surrounded by triple backticks, like the option to ignore comments.

isaaclyman commented 10 months ago

Comments make sense to ignore, since they don't show up in the Reader view. But code does.

Code doesn't read the same way as natural language.

I don't know if I buy this argument. Sure, I skim over curly braces and such when I'm reading code. But even so, do I actually read it faster than English words in sentence form? That's not an immediate yes or no. You have to slow down a bit to read code because it's so dense—in fact, you could argue it actually increases the reading time per word to have code blocks in your notes.

If other users request this, I can give it more thought. But for now this strikes me as mostly opinion, and pretty controversial opinion at that.

Mestru commented 10 months ago

Thanks for pointing out that the duplicate issue already exists. Well for me the problem is a tad different, I don't want to count the reading time but the progress I make in writing within a certain note. Code blocks used for ```dataviewjs scripts skew the number of words and when I create a new note from template I immediately see ~400 words being written in there despite it only being a few dataview scripts.

isaaclyman commented 10 months ago

That's a fair distinction to make, but from the point of view of the plugin, we're either counting code blocks or not. Whether they're shown as "word count" or "page count" or "reading time" is more or less a question of formatting.

Mestru commented 10 months ago

I understand. Where do you stand on this issue design wise?

Would you be willing to consider it if I were to create a PR to implement such functionality? A setting in "Advanced options" allowing for counting/not counting code blocks/code blocks containing dataview scripts?

As I skimmed through the code it seems to be a fairly straight forward thing to add even for a newcomer to the codebase.

isaaclyman commented 10 months ago

Give me a couple days to mull it over. The "dataview" argument is more compelling to me than the "block of readable code" argument, though both produce text that would be seen in Reading Mode.

Can you help me understand your use case? Why do you have a dataview in every note?

Mestru commented 10 months ago

Sure. First of all I'd like to clarify that from what I've gathered, what this plugin counts is the actual code written inside the ```dataviewjs data block and not the rendered text itself. Technically it makes sense but I want to make that distinction. It counts this: image Not this: image

I suppose it makes sense, from plugin's POV we don't know what the dataview plugin will be rendered into so it counts the code but I wanted to make it clear as you spoke about Reading Mode.

As for the use case, I use it to track my weekly progress within a time period (I suppose you might call it a longer version of a sprint). My goals are fetched from a note-mother and my progress is tracked on a weekly basis with each week having a separate note (hence the need for templating). My dataview script tracks the change from the previous weeks and also shows goals I gave myself a week before. What I actually want to track word count wise is what I've written in my weekly summaries and goals I set for the next week.

Specific example: I track a number of books I want to read in a "sprint", in week 7 I completed 38% of my goal and in week 8 my completion went up by 25% to 63%. My dataview script fetches the goal, my completion rate from previous note and current note, and does some calculation to display all my goals in a table. image Also during week 7 I gave myself a goal to read 140 pages which I also see in the week 8 note and I can mark it as completed or edit it from there (it actually references what's written in week 7 note, so it's perfectly ok not to count it wordwise as it would just double what I wrote in the previous note) image

And so instead of having my actual word count that I wrote each week I have inflated numbers that suggest I might've very well written a novel instead of a short summary 😄 image

If you need to know anything else, feel free to ask and no need to rush. Feel free to "mull it over".

isaaclyman commented 10 months ago

Okay, thanks for your patience. I understand your use case and it does seem to be make-or-break for the plugin's overall usefulness. I'll see if an option to ignore code blocks will implement as easily as I'm hoping it will.

Mestru commented 10 months ago

I'm very glad to hear that :) Thank you for your understanding and best of luck in speedy and easy implementation.

isaaclyman commented 10 months ago

Fixed in v3.1.0, now available. Let me know if you see any issues.

Mestru commented 10 months ago

It seems to work great! Thank you for your work, have a good day :)