Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion browser/main/Detail/MarkdownNoteDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ class MarkdownNoteDetail extends React.Component {
exportAsTxt={this.exportAsTxt}
exportAsHtml={this.exportAsHtml}
exportAsPdf={this.exportAsPdf}
wordCount={note.content.split(' ').length}
wordCount={note.content.replace(/\r?\n?\s+/g, ' ').trim().split(' ').length}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello ! :)

I think it can be replaced by:

note.content.trim().split(/\r?\n?\s+/g).length

or even

note.content.trim().split(/\s+/g).length
since \s includes cariage returns and new lines

https://www.w3schools.com/jsref/jsref_regexp_whitespace.asp

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thamara Can you change your code to the above suggestion for more concise code? Thanks.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I'd use the split(/s+/g).

https://repl.it/@alexanderwolf/Word-count-regex

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make the suggested change. Thanks!

letterCount={note.content.replace(/\r?\n/g, '').length}
type={note.type}
print={this.print}
Expand Down