summaryrefslogtreecommitdiff
path: root/ext/fg/js/source.js
diff options
context:
space:
mode:
authorsiikamiika <siikamiika@users.noreply.github.com>2019-08-14 22:54:42 +0300
committersiikamiika <siikamiika@users.noreply.github.com>2019-08-14 22:54:42 +0300
commit658e5ddff13f4ec392dc110004635e22d468525a (patch)
tree731d79146922885e951fbec57a05d6393bcf13f1 /ext/fg/js/source.js
parente23d4b9a82581f3cf1118e31d077fc9cdaff7573 (diff)
ignore zero-width non-joiner
fixes #179
Diffstat (limited to 'ext/fg/js/source.js')
-rw-r--r--ext/fg/js/source.js19
1 files changed, 17 insertions, 2 deletions
diff --git a/ext/fg/js/source.js b/ext/fg/js/source.js
index 664dbec7..cd8f63fd 100644
--- a/ext/fg/js/source.js
+++ b/ext/fg/js/source.js
@@ -16,6 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+// \u200c (Zero-width non-joiner) appears on Google Docs from Chrome 76 onwards
+const IGNORE_TEXT_PATTERN = /\u200c/g;
+
/*
* TextSourceRange
@@ -32,7 +35,13 @@ class TextSourceRange {
}
text() {
- return this.content;
+ let strippedIndices = [];
+ const text = this.content.replace(IGNORE_TEXT_PATTERN, (match, offset) => {
+ strippedIndices.push(offset);
+ return '';
+ });
+
+ return {text, strippedIndices};
}
setEndOffset(length) {
@@ -195,7 +204,13 @@ class TextSourceElement {
}
text() {
- return this.content;
+ let strippedIndices = [];
+ const text = this.content.replace(IGNORE_TEXT_PATTERN, (match, offset) => {
+ strippedIndices.push(offset);
+ return '';
+ });
+
+ return {text, strippedIndices};
}
setEndOffset(length) {