|
14 | 14 | shortcodes = this.settings.l10n.shortcodes; |
15 | 15 |
|
16 | 16 | if ( shortcodes && shortcodes.length ) { |
17 | | - this.settings.shortcodesRegExp = new RegExp( '\\[\\/?(?:' + shortcodes.join( '|' ) + ')[^\\]]*?\\]', 'gi' ); |
| 17 | + this.settings.shortcodesRegExp = new RegExp( '\\[\\/?(?:' + shortcodes.join( '|' ) + ')[^\\]]*?\\]', 'g' ); |
18 | 18 | } |
19 | 19 | } |
20 | 20 |
|
21 | 21 | WordCounter.prototype.settings = { |
22 | 22 | HTMLRegExp: /<\/?[a-z][^>]*?>/gi, |
| 23 | + HTMLcommentRegExp: /<!--[\s\S]*?-->/g, |
23 | 24 | spaceRegExp: / | /gi, |
24 | | - connectorRegExp: /--|\u2014/gi, |
| 25 | + HTMLEntityRegExp: /&\S+?;/g, |
| 26 | + connectorRegExp: /--|\u2014/g, |
25 | 27 | removeRegExp: new RegExp( [ |
26 | 28 | '[', |
27 | 29 | // Basic Latin (extract) |
|
60 | 62 | astralRegExp: /[\uD800-\uDBFF][\uDC00-\uDFFF]/g, |
61 | 63 | wordsRegExp: /\S\s+/g, |
62 | 64 | charactersRegExp: /\S/g, |
63 | | - allRegExp: /[^\f\n\r\t\v\u00ad\u2028\u2029]/g, |
| 65 | + allRegExp: /[^\f\n\r\t\v\u00AD\u2028\u2029]/g, |
64 | 66 | l10n: window.wordCountL10n || {} |
65 | 67 | }; |
66 | 68 |
|
67 | 69 | WordCounter.prototype.count = function( text, type ) { |
68 | 70 | var count = 0; |
69 | 71 |
|
70 | | - type = type || this.settings.l10n.type || 'words'; |
| 72 | + type = type || this.settings.l10n.type; |
| 73 | + |
| 74 | + if ( type !== 'characters' && type !== 'all' ) { |
| 75 | + type = 'words'; |
| 76 | + } |
71 | 77 |
|
72 | 78 | if ( text ) { |
73 | 79 | text = text + '\n'; |
74 | 80 |
|
75 | 81 | text = text.replace( this.settings.HTMLRegExp, '\n' ); |
| 82 | + text = text.replace( this.settings.HTMLcommentRegExp, '' ); |
76 | 83 |
|
77 | 84 | if ( this.settings.shortcodesRegExp ) { |
78 | 85 | text = text.replace( this.settings.shortcodesRegExp, '\n' ); |
|
81 | 88 | text = text.replace( this.settings.spaceRegExp, ' ' ); |
82 | 89 |
|
83 | 90 | if ( type === 'words' ) { |
| 91 | + text = text.replace( this.settings.HTMLEntityRegExp, '' ); |
84 | 92 | text = text.replace( this.settings.connectorRegExp, ' ' ); |
85 | 93 | text = text.replace( this.settings.removeRegExp, '' ); |
86 | 94 | } else { |
| 95 | + text = text.replace( this.settings.HTMLEntityRegExp, 'a' ); |
87 | 96 | text = text.replace( this.settings.astralRegExp, 'a' ); |
88 | 97 | } |
89 | 98 |
|
|
0 commit comments