The word is primarily counted by splitting the text with each space. After that, a few types of content are removed from the count as we do not regard them as words.
For example, spaces at the start and end of the text block, line breaks, double spaces and special characters such as dashes are all removed from the word count.