diff --git a/src/article_maker.cc b/src/article_maker.cc
index b7febc78..2bc1a774 100644
--- a/src/article_maker.cc
+++ b/src/article_maker.cc
@@ -141,6 +141,7 @@ std::string ArticleMaker::makeHtmlHeader( QString const & word, QString const &
.toStdString();
result += R"()";
+ result += R"()";
if ( GlobalBroadcaster::instance()->getPreference()->darkReaderMode ) {
//only enable this darkmode on modern style.
diff --git a/src/scripts/mark.js b/src/scripts/mark.js
new file mode 100644
index 00000000..b42f2e97
--- /dev/null
+++ b/src/scripts/mark.js
@@ -0,0 +1,1241 @@
+/*!***************************************************
+* mark.js v9.0.0
+* https://markjs.io/
+* Copyright (c) 2014–2018, Julian Kühnel
+* Released under the MIT license https://git.io/vwTVl
+*****************************************************/
+
+(function (global, factory) {
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
+ typeof define === 'function' && define.amd ? define(factory) :
+ (global.Mark = factory());
+}(this, (function () {
+ 'use strict';
+
+ function _typeof(obj) {
+ if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
+ _typeof = function (obj) {
+ return typeof obj;
+ };
+ } else {
+ _typeof = function (obj) {
+ return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
+ };
+ }
+
+ return _typeof(obj);
+ }
+
+ function _classCallCheck(instance, Constructor) {
+ if (!(instance instanceof Constructor)) {
+ throw new TypeError("Cannot call a class as a function");
+ }
+ }
+
+ function _defineProperties(target, props) {
+ for (var i = 0; i < props.length; i++) {
+ var descriptor = props[i];
+ descriptor.enumerable = descriptor.enumerable || false;
+ descriptor.configurable = true;
+ if ("value" in descriptor) descriptor.writable = true;
+ Object.defineProperty(target, descriptor.key, descriptor);
+ }
+ }
+
+ function _createClass(Constructor, protoProps, staticProps) {
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
+ if (staticProps) _defineProperties(Constructor, staticProps);
+ return Constructor;
+ }
+
+ function _extends() {
+ _extends = Object.assign || function (target) {
+ for (var i = 1; i < arguments.length; i++) {
+ var source = arguments[i];
+
+ for (var key in source) {
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
+ target[key] = source[key];
+ }
+ }
+ }
+
+ return target;
+ };
+
+ return _extends.apply(this, arguments);
+ }
+
+ var DOMIterator =
+ /*#__PURE__*/
+ function () {
+ function DOMIterator(ctx) {
+ var iframes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
+ var exclude = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
+ var iframesTimeout = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 5000;
+
+ _classCallCheck(this, DOMIterator);
+
+ this.ctx = ctx;
+ this.iframes = iframes;
+ this.exclude = exclude;
+ this.iframesTimeout = iframesTimeout;
+ }
+
+ _createClass(DOMIterator, [{
+ key: "getContexts",
+ value: function getContexts() {
+ var ctx,
+ filteredCtx = [];
+
+ if (typeof this.ctx === 'undefined' || !this.ctx) {
+ ctx = [];
+ } else if (NodeList.prototype.isPrototypeOf(this.ctx)) {
+ ctx = Array.prototype.slice.call(this.ctx);
+ } else if (Array.isArray(this.ctx)) {
+ ctx = this.ctx;
+ } else if (typeof this.ctx === 'string') {
+ ctx = Array.prototype.slice.call(document.querySelectorAll(this.ctx));
+ } else {
+ ctx = [this.ctx];
+ }
+
+ ctx.forEach(function (ctx) {
+ var isDescendant = filteredCtx.filter(function (contexts) {
+ return contexts.contains(ctx);
+ }).length > 0;
+
+ if (filteredCtx.indexOf(ctx) === -1 && !isDescendant) {
+ filteredCtx.push(ctx);
+ }
+ });
+ return filteredCtx;
+ }
+ }, {
+ key: "getIframeContents",
+ value: function getIframeContents(ifr, successFn) {
+ var errorFn = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {
+ };
+ var doc;
+
+ try {
+ var ifrWin = ifr.contentWindow;
+ doc = ifrWin.document;
+
+ if (!ifrWin || !doc) {
+ throw new Error('iframe inaccessible');
+ }
+ } catch (e) {
+ errorFn();
+ }
+
+ if (doc) {
+ successFn(doc);
+ }
+ }
+ }, {
+ key: "isIframeBlank",
+ value: function isIframeBlank(ifr) {
+ var bl = 'about:blank',
+ src = ifr.getAttribute('src').trim(),
+ href = ifr.contentWindow.location.href;
+ return href === bl && src !== bl && src;
+ }
+ }, {
+ key: "observeIframeLoad",
+ value: function observeIframeLoad(ifr, successFn, errorFn) {
+ var _this = this;
+
+ var called = false,
+ tout = null;
+
+ var listener = function listener() {
+ if (called) {
+ return;
+ }
+
+ called = true;
+ clearTimeout(tout);
+
+ try {
+ if (!_this.isIframeBlank(ifr)) {
+ ifr.removeEventListener('load', listener);
+
+ _this.getIframeContents(ifr, successFn, errorFn);
+ }
+ } catch (e) {
+ errorFn();
+ }
+ };
+
+ ifr.addEventListener('load', listener);
+ tout = setTimeout(listener, this.iframesTimeout);
+ }
+ }, {
+ key: "onIframeReady",
+ value: function onIframeReady(ifr, successFn, errorFn) {
+ try {
+ if (ifr.contentWindow.document.readyState === 'complete') {
+ if (this.isIframeBlank(ifr)) {
+ this.observeIframeLoad(ifr, successFn, errorFn);
+ } else {
+ this.getIframeContents(ifr, successFn, errorFn);
+ }
+ } else {
+ this.observeIframeLoad(ifr, successFn, errorFn);
+ }
+ } catch (e) {
+ errorFn();
+ }
+ }
+ }, {
+ key: "waitForIframes",
+ value: function waitForIframes(ctx, done) {
+ var _this2 = this;
+
+ var eachCalled = 0;
+ this.forEachIframe(ctx, function () {
+ return true;
+ }, function (ifr) {
+ eachCalled++;
+
+ _this2.waitForIframes(ifr.querySelector('html'), function () {
+ if (!--eachCalled) {
+ done();
+ }
+ });
+ }, function (handled) {
+ if (!handled) {
+ done();
+ }
+ });
+ }
+ }, {
+ key: "forEachIframe",
+ value: function forEachIframe(ctx, filter, each) {
+ var _this3 = this;
+
+ var end = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : function () {
+ };
+ var ifr = ctx.querySelectorAll('iframe'),
+ open = ifr.length,
+ handled = 0;
+ ifr = Array.prototype.slice.call(ifr);
+
+ var checkEnd = function checkEnd() {
+ if (--open <= 0) {
+ end(handled);
+ }
+ };
+
+ if (!open) {
+ checkEnd();
+ }
+
+ ifr.forEach(function (ifr) {
+ if (DOMIterator.matches(ifr, _this3.exclude)) {
+ checkEnd();
+ } else {
+ _this3.onIframeReady(ifr, function (con) {
+ if (filter(ifr)) {
+ handled++;
+ each(con);
+ }
+
+ checkEnd();
+ }, checkEnd);
+ }
+ });
+ }
+ }, {
+ key: "createIterator",
+ value: function createIterator(ctx, whatToShow, filter) {
+ return document.createNodeIterator(ctx, whatToShow, filter, false);
+ }
+ }, {
+ key: "createInstanceOnIframe",
+ value: function createInstanceOnIframe(contents) {
+ return new DOMIterator(contents.querySelector('html'), this.iframes);
+ }
+ }, {
+ key: "compareNodeIframe",
+ value: function compareNodeIframe(node, prevNode, ifr) {
+ var compCurr = node.compareDocumentPosition(ifr),
+ prev = Node.DOCUMENT_POSITION_PRECEDING;
+
+ if (compCurr & prev) {
+ if (prevNode !== null) {
+ var compPrev = prevNode.compareDocumentPosition(ifr),
+ after = Node.DOCUMENT_POSITION_FOLLOWING;
+
+ if (compPrev & after) {
+ return true;
+ }
+ } else {
+ return true;
+ }
+ }
+
+ return false;
+ }
+ }, {
+ key: "getIteratorNode",
+ value: function getIteratorNode(itr) {
+ var prevNode = itr.previousNode();
+ var node;
+
+ if (prevNode === null) {
+ node = itr.nextNode();
+ } else {
+ node = itr.nextNode() && itr.nextNode();
+ }
+
+ return {
+ prevNode: prevNode,
+ node: node
+ };
+ }
+ }, {
+ key: "checkIframeFilter",
+ value: function checkIframeFilter(node, prevNode, currIfr, ifr) {
+ var key = false,
+ handled = false;
+ ifr.forEach(function (ifrDict, i) {
+ if (ifrDict.val === currIfr) {
+ key = i;
+ handled = ifrDict.handled;
+ }
+ });
+
+ if (this.compareNodeIframe(node, prevNode, currIfr)) {
+ if (key === false && !handled) {
+ ifr.push({
+ val: currIfr,
+ handled: true
+ });
+ } else if (key !== false && !handled) {
+ ifr[key].handled = true;
+ }
+
+ return true;
+ }
+
+ if (key === false) {
+ ifr.push({
+ val: currIfr,
+ handled: false
+ });
+ }
+
+ return false;
+ }
+ }, {
+ key: "handleOpenIframes",
+ value: function handleOpenIframes(ifr, whatToShow, eCb, fCb) {
+ var _this4 = this;
+
+ ifr.forEach(function (ifrDict) {
+ if (!ifrDict.handled) {
+ _this4.getIframeContents(ifrDict.val, function (con) {
+ _this4.createInstanceOnIframe(con).forEachNode(whatToShow, eCb, fCb);
+ });
+ }
+ });
+ }
+ }, {
+ key: "iterateThroughNodes",
+ value: function iterateThroughNodes(whatToShow, ctx, eachCb, filterCb, doneCb) {
+ var _this5 = this;
+
+ var itr = this.createIterator(ctx, whatToShow, filterCb);
+
+ var ifr = [],
+ elements = [],
+ node,
+ prevNode,
+ retrieveNodes = function retrieveNodes() {
+ var _this5$getIteratorNod = _this5.getIteratorNode(itr);
+
+ prevNode = _this5$getIteratorNod.prevNode;
+ node = _this5$getIteratorNod.node;
+ return node;
+ };
+
+ while (retrieveNodes()) {
+ if (this.iframes) {
+ this.forEachIframe(ctx, function (currIfr) {
+ return _this5.checkIframeFilter(node, prevNode, currIfr, ifr);
+ }, function (con) {
+ _this5.createInstanceOnIframe(con).forEachNode(whatToShow, function (ifrNode) {
+ return elements.push(ifrNode);
+ }, filterCb);
+ });
+ }
+
+ elements.push(node);
+ }
+
+ elements.forEach(function (node) {
+ eachCb(node);
+ });
+
+ if (this.iframes) {
+ this.handleOpenIframes(ifr, whatToShow, eachCb, filterCb);
+ }
+
+ doneCb();
+ }
+ }, {
+ key: "forEachNode",
+ value: function forEachNode(whatToShow, each, filter) {
+ var _this6 = this;
+
+ var done = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : function () {
+ };
+ var contexts = this.getContexts();
+ var open = contexts.length;
+
+ if (!open) {
+ done();
+ }
+
+ contexts.forEach(function (ctx) {
+ var ready = function ready() {
+ _this6.iterateThroughNodes(whatToShow, ctx, each, filter, function () {
+ if (--open <= 0) {
+ done();
+ }
+ });
+ };
+
+ if (_this6.iframes) {
+ _this6.waitForIframes(ctx, ready);
+ } else {
+ ready();
+ }
+ });
+ }
+ }], [{
+ key: "matches",
+ value: function matches(element, selector) {
+ var selectors = typeof selector === 'string' ? [selector] : selector,
+ fn = element.matches || element.matchesSelector || element.msMatchesSelector || element.mozMatchesSelector || element.oMatchesSelector || element.webkitMatchesSelector;
+
+ if (fn) {
+ var match = false;
+ selectors.every(function (sel) {
+ if (fn.call(element, sel)) {
+ match = true;
+ return false;
+ }
+
+ return true;
+ });
+ return match;
+ } else {
+ return false;
+ }
+ }
+ }]);
+
+ return DOMIterator;
+ }();
+
+ var RegExpCreator =
+ /*#__PURE__*/
+ function () {
+ function RegExpCreator(options) {
+ _classCallCheck(this, RegExpCreator);
+
+ this.opt = _extends({}, {
+ 'diacritics': true,
+ 'synonyms': {},
+ 'accuracy': 'partially',
+ 'caseSensitive': false,
+ 'ignoreJoiners': false,
+ 'ignorePunctuation': [],
+ 'wildcards': 'disabled'
+ }, options);
+ }
+
+ _createClass(RegExpCreator, [{
+ key: "create",
+ value: function create(str) {
+ if (this.opt.wildcards !== 'disabled') {
+ str = this.setupWildcardsRegExp(str);
+ }
+
+ str = this.escapeStr(str);
+
+ if (Object.keys(this.opt.synonyms).length) {
+ str = this.createSynonymsRegExp(str);
+ }
+
+ if (this.opt.ignoreJoiners || this.opt.ignorePunctuation.length) {
+ str = this.setupIgnoreJoinersRegExp(str);
+ }
+
+ if (this.opt.diacritics) {
+ str = this.createDiacriticsRegExp(str);
+ }
+
+ str = this.createMergedBlanksRegExp(str);
+
+ if (this.opt.ignoreJoiners || this.opt.ignorePunctuation.length) {
+ str = this.createJoinersRegExp(str);
+ }
+
+ if (this.opt.wildcards !== 'disabled') {
+ str = this.createWildcardsRegExp(str);
+ }
+
+ str = this.createAccuracyRegExp(str);
+ return new RegExp(str, "gm".concat(this.opt.caseSensitive ? '' : 'i'));
+ }
+ }, {
+ key: "sortByLength",
+ value: function sortByLength(arry) {
+ return arry.sort(function (a, b) {
+ return a.length === b.length ? a > b ? 1 : -1 : b.length - a.length;
+ });
+ }
+ }, {
+ key: "escapeStr",
+ value: function escapeStr(str) {
+ return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
+ }
+ }, {
+ key: "createSynonymsRegExp",
+ value: function createSynonymsRegExp(str) {
+ var _this = this;
+
+ var syn = this.opt.synonyms,
+ sens = this.opt.caseSensitive ? '' : 'i',
+ joinerPlaceholder = this.opt.ignoreJoiners || this.opt.ignorePunctuation.length ? "\0" : '';
+
+ for (var index in syn) {
+ if (syn.hasOwnProperty(index)) {
+ var keys = Array.isArray(syn[index]) ? syn[index] : [syn[index]];
+ keys.unshift(index);
+ keys = this.sortByLength(keys).map(function (key) {
+ if (_this.opt.wildcards !== 'disabled') {
+ key = _this.setupWildcardsRegExp(key);
+ }
+
+ key = _this.escapeStr(key);
+ return key;
+ }).filter(function (k) {
+ return k !== '';
+ });
+
+ if (keys.length > 1) {
+ str = str.replace(new RegExp("(".concat(keys.map(function (k) {
+ return _this.escapeStr(k);
+ }).join('|'), ")"), "gm".concat(sens)), joinerPlaceholder + "(".concat(keys.map(function (k) {
+ return _this.processSynonyms(k);
+ }).join('|'), ")") + joinerPlaceholder);
+ }
+ }
+ }
+
+ return str;
+ }
+ }, {
+ key: "processSynonyms",
+ value: function processSynonyms(str) {
+ if (this.opt.ignoreJoiners || this.opt.ignorePunctuation.length) {
+ str = this.setupIgnoreJoinersRegExp(str);
+ }
+
+ return str;
+ }
+ }, {
+ key: "setupWildcardsRegExp",
+ value: function setupWildcardsRegExp(str) {
+ str = str.replace(/(?:\\)*\?/g, function (val) {
+ return val.charAt(0) === '\\' ? '?' : "\x01";
+ });
+ return str.replace(/(?:\\)*\*/g, function (val) {
+ return val.charAt(0) === '\\' ? '*' : "\x02";
+ });
+ }
+ }, {
+ key: "createWildcardsRegExp",
+ value: function createWildcardsRegExp(str) {
+ var spaces = this.opt.wildcards === 'withSpaces';
+ return str.replace(/\u0001/g, spaces ? '[\\S\\s]?' : '\\S?').replace(/\u0002/g, spaces ? '[\\S\\s]*?' : '\\S*');
+ }
+ }, {
+ key: "setupIgnoreJoinersRegExp",
+ value: function setupIgnoreJoinersRegExp(str) {
+ return str.replace(/[^(|)\\]/g, function (val, indx, original) {
+ var nextChar = original.charAt(indx + 1);
+
+ if (/[(|)\\]/.test(nextChar) || nextChar === '') {
+ return val;
+ } else {
+ return val + "\0";
+ }
+ });
+ }
+ }, {
+ key: "createJoinersRegExp",
+ value: function createJoinersRegExp(str) {
+ var joiner = [];
+ var ignorePunctuation = this.opt.ignorePunctuation;
+
+ if (Array.isArray(ignorePunctuation) && ignorePunctuation.length) {
+ joiner.push(this.escapeStr(ignorePunctuation.join('')));
+ }
+
+ if (this.opt.ignoreJoiners) {
+ joiner.push("\\u00ad\\u200b\\u200c\\u200d");
+ }
+
+ return joiner.length ? str.split(/\u0000+/).join("[".concat(joiner.join(''), "]*")) : str;
+ }
+ }, {
+ key: "createDiacriticsRegExp",
+ value: function createDiacriticsRegExp(str) {
+ var sens = this.opt.caseSensitive ? '' : 'i',
+ dct = this.opt.caseSensitive ? ['aàáảãạăằắẳẵặâầấẩẫậäåāą', 'AÀÁẢÃẠĂẰẮẲẴẶÂẦẤẨẪẬÄÅĀĄ', 'cçćč', 'CÇĆČ', 'dđď', 'DĐĎ', 'eèéẻẽẹêềếểễệëěēę', 'EÈÉẺẼẸÊỀẾỂỄỆËĚĒĘ', 'iìíỉĩịîïī', 'IÌÍỈĨỊÎÏĪ', 'lł', 'LŁ', 'nñňń', 'NÑŇŃ', 'oòóỏõọôồốổỗộơởỡớờợöøō', 'OÒÓỎÕỌÔỒỐỔỖỘƠỞỠỚỜỢÖØŌ', 'rř', 'RŘ', 'sšśșş', 'SŠŚȘŞ', 'tťțţ', 'TŤȚŢ', 'uùúủũụưừứửữựûüůū', 'UÙÚỦŨỤƯỪỨỬỮỰÛÜŮŪ', 'yýỳỷỹỵÿ', 'YÝỲỶỸỴŸ', 'zžżź', 'ZŽŻŹ'] : ['aàáảãạăằắẳẵặâầấẩẫậäåāąAÀÁẢÃẠĂẰẮẲẴẶÂẦẤẨẪẬÄÅĀĄ', 'cçćčCÇĆČ', 'dđďDĐĎ', 'eèéẻẽẹêềếểễệëěēęEÈÉẺẼẸÊỀẾỂỄỆËĚĒĘ', 'iìíỉĩịîïīIÌÍỈĨỊÎÏĪ', 'lłLŁ', 'nñňńNÑŇŃ', 'oòóỏõọôồốổỗộơởỡớờợöøōOÒÓỎÕỌÔỒỐỔỖỘƠỞỠỚỜỢÖØŌ', 'rřRŘ', 'sšśșşSŠŚȘŞ', 'tťțţTŤȚŢ', 'uùúủũụưừứửữựûüůūUÙÚỦŨỤƯỪỨỬỮỰÛÜŮŪ', 'yýỳỷỹỵÿYÝỲỶỸỴŸ', 'zžżźZŽŻŹ'];
+ var handled = [];
+ str.split('').forEach(function (ch) {
+ dct.every(function (dct) {
+ if (dct.indexOf(ch) !== -1) {
+ if (handled.indexOf(dct) > -1) {
+ return false;
+ }
+
+ str = str.replace(new RegExp("[".concat(dct, "]"), "gm".concat(sens)), "[".concat(dct, "]"));
+ handled.push(dct);
+ }
+
+ return true;
+ });
+ });
+ return str;
+ }
+ }, {
+ key: "createMergedBlanksRegExp",
+ value: function createMergedBlanksRegExp(str) {
+ return str.replace(/[\s]+/gmi, '[\\s]+');
+ }
+ }, {
+ key: "createAccuracyRegExp",
+ value: function createAccuracyRegExp(str) {
+ var _this2 = this;
+
+ var chars = '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~¡¿';
+ var acc = this.opt.accuracy,
+ val = typeof acc === 'string' ? acc : acc.value,
+ ls = typeof acc === 'string' ? [] : acc.limiters,
+ lsJoin = '';
+ ls.forEach(function (limiter) {
+ lsJoin += "|".concat(_this2.escapeStr(limiter));
+ });
+
+ switch (val) {
+ case 'partially':
+ default:
+ return "()(".concat(str, ")");
+
+ case 'complementary':
+ lsJoin = '\\s' + (lsJoin ? lsJoin : this.escapeStr(chars));
+ return "()([^".concat(lsJoin, "]*").concat(str, "[^").concat(lsJoin, "]*)");
+
+ case 'exactly':
+ return "(^|\\s".concat(lsJoin, ")(").concat(str, ")(?=$|\\s").concat(lsJoin, ")");
+ }
+ }
+ }]);
+
+ return RegExpCreator;
+ }();
+
+ var Mark =
+ /*#__PURE__*/
+ function () {
+ function Mark(ctx) {
+ _classCallCheck(this, Mark);
+
+ this.ctx = ctx;
+ this.ie = false;
+ var ua = window.navigator.userAgent;
+
+ if (ua.indexOf('MSIE') > -1 || ua.indexOf('Trident') > -1) {
+ this.ie = true;
+ }
+ }
+
+ _createClass(Mark, [{
+ key: "log",
+ value: function log(msg) {
+ var level = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'debug';
+ var log = this.opt.log;
+
+ if (!this.opt.debug) {
+ return;
+ }
+
+ if (_typeof(log) === 'object' && typeof log[level] === 'function') {
+ log[level]("mark.js: ".concat(msg));
+ }
+ }
+ }, {
+ key: "getSeparatedKeywords",
+ value: function getSeparatedKeywords(sv) {
+ var _this = this;
+
+ var stack = [];
+ sv.forEach(function (kw) {
+ if (!_this.opt.separateWordSearch) {
+ if (kw.trim() && stack.indexOf(kw) === -1) {
+ stack.push(kw);
+ }
+ } else {
+ kw.split(' ').forEach(function (kwSplitted) {
+ if (kwSplitted.trim() && stack.indexOf(kwSplitted) === -1) {
+ stack.push(kwSplitted);
+ }
+ });
+ }
+ });
+ return {
+ 'keywords': stack.sort(function (a, b) {
+ return b.length - a.length;
+ }),
+ 'length': stack.length
+ };
+ }
+ }, {
+ key: "isNumeric",
+ value: function isNumeric(value) {
+ return Number(parseFloat(value)) == value;
+ }
+ }, {
+ key: "checkRanges",
+ value: function checkRanges(array) {
+ var _this2 = this;
+
+ if (!Array.isArray(array) || Object.prototype.toString.call(array[0]) !== '[object Object]') {
+ this.log('markRanges() will only accept an array of objects');
+ this.opt.noMatch(array);
+ return [];
+ }
+
+ var stack = [];
+ var last = 0;
+ array.sort(function (a, b) {
+ return a.start - b.start;
+ }).forEach(function (item) {
+ var _this2$callNoMatchOnI = _this2.callNoMatchOnInvalidRanges(item, last),
+ start = _this2$callNoMatchOnI.start,
+ end = _this2$callNoMatchOnI.end,
+ valid = _this2$callNoMatchOnI.valid;
+
+ if (valid) {
+ item.start = start;
+ item.length = end - start;
+ stack.push(item);
+ last = end;
+ }
+ });
+ return stack;
+ }
+ }, {
+ key: "callNoMatchOnInvalidRanges",
+ value: function callNoMatchOnInvalidRanges(range, last) {
+ var start,
+ end,
+ valid = false;
+
+ if (range && typeof range.start !== 'undefined') {
+ start = parseInt(range.start, 10);
+ end = start + parseInt(range.length, 10);
+
+ if (this.isNumeric(range.start) && this.isNumeric(range.length) && end - last > 0 && end - start > 0) {
+ valid = true;
+ } else {
+ this.log('Ignoring invalid or overlapping range: ' + "".concat(JSON.stringify(range)));
+ this.opt.noMatch(range);
+ }
+ } else {
+ this.log("Ignoring invalid range: ".concat(JSON.stringify(range)));
+ this.opt.noMatch(range);
+ }
+
+ return {
+ start: start,
+ end: end,
+ valid: valid
+ };
+ }
+ }, {
+ key: "checkWhitespaceRanges",
+ value: function checkWhitespaceRanges(range, originalLength, string) {
+ var end,
+ valid = true,
+ max = string.length,
+ offset = originalLength - max,
+ start = parseInt(range.start, 10) - offset;
+ start = start > max ? max : start;
+ end = start + parseInt(range.length, 10);
+
+ if (end > max) {
+ end = max;
+ this.log("End range automatically set to the max value of ".concat(max));
+ }
+
+ if (start < 0 || end - start < 0 || start > max || end > max) {
+ valid = false;
+ this.log("Invalid range: ".concat(JSON.stringify(range)));
+ this.opt.noMatch(range);
+ } else if (string.substring(start, end).replace(/\s+/g, '') === '') {
+ valid = false;
+ this.log('Skipping whitespace only range: ' + JSON.stringify(range));
+ this.opt.noMatch(range);
+ }
+
+ return {
+ start: start,
+ end: end,
+ valid: valid
+ };
+ }
+ }, {
+ key: "getTextNodes",
+ value: function getTextNodes(cb) {
+ var _this3 = this;
+
+ var val = '',
+ nodes = [];
+ this.iterator.forEachNode(NodeFilter.SHOW_TEXT, function (node) {
+ nodes.push({
+ start: val.length,
+ end: (val += node.textContent).length,
+ node: node
+ });
+ }, function (node) {
+ if (_this3.matchesExclude(node.parentNode)) {
+ return NodeFilter.FILTER_REJECT;
+ } else {
+ return NodeFilter.FILTER_ACCEPT;
+ }
+ }, function () {
+ cb({
+ value: val,
+ nodes: nodes
+ });
+ });
+ }
+ }, {
+ key: "matchesExclude",
+ value: function matchesExclude(el) {
+ return DOMIterator.matches(el, this.opt.exclude.concat(['script', 'style', 'title', 'head', 'html']));
+ }
+ }, {
+ key: "wrapRangeInTextNode",
+ value: function wrapRangeInTextNode(node, start, end) {
+ var hEl = !this.opt.element ? 'mark' : this.opt.element,
+ startNode = node.splitText(start),
+ ret = startNode.splitText(end - start);
+ var repl = document.createElement(hEl);
+ repl.setAttribute('data-markjs', 'true');
+
+ if (this.opt.className) {
+ repl.setAttribute('class', this.opt.className);
+ }
+
+ repl.textContent = startNode.textContent;
+ startNode.parentNode.replaceChild(repl, startNode);
+ return ret;
+ }
+ }, {
+ key: "wrapRangeInMappedTextNode",
+ value: function wrapRangeInMappedTextNode(dict, start, end, filterCb, eachCb) {
+ var _this4 = this;
+
+ dict.nodes.every(function (n, i) {
+ var sibl = dict.nodes[i + 1];
+
+ if (typeof sibl === 'undefined' || sibl.start > start) {
+ if (!filterCb(n.node)) {
+ return false;
+ }
+
+ var s = start - n.start,
+ e = (end > n.end ? n.end : end) - n.start,
+ startStr = dict.value.substr(0, n.start),
+ endStr = dict.value.substr(e + n.start);
+ n.node = _this4.wrapRangeInTextNode(n.node, s, e);
+ dict.value = startStr + endStr;
+ dict.nodes.forEach(function (k, j) {
+ if (j >= i) {
+ if (dict.nodes[j].start > 0 && j !== i) {
+ dict.nodes[j].start -= e;
+ }
+
+ dict.nodes[j].end -= e;
+ }
+ });
+ end -= e;
+ eachCb(n.node.previousSibling, n.start);
+
+ if (end > n.end) {
+ start = n.end;
+ } else {
+ return false;
+ }
+ }
+
+ return true;
+ });
+ }
+ }, {
+ key: "wrapGroups",
+ value: function wrapGroups(node, pos, len, eachCb) {
+ node = this.wrapRangeInTextNode(node, pos, pos + len);
+ eachCb(node.previousSibling);
+ return node;
+ }
+ }, {
+ key: "separateGroups",
+ value: function separateGroups(node, match, matchIdx, filterCb, eachCb) {
+ var matchLen = match.length;
+
+ for (var i = 1; i < matchLen; i++) {
+ var pos = node.textContent.indexOf(match[i]);
+
+ if (match[i] && pos > -1 && filterCb(match[i], node)) {
+ node = this.wrapGroups(node, pos, match[i].length, eachCb);
+ }
+ }
+
+ return node;
+ }
+ }, {
+ key: "wrapMatches",
+ value: function wrapMatches(regex, ignoreGroups, filterCb, eachCb, endCb) {
+ var _this5 = this;
+
+ var matchIdx = ignoreGroups === 0 ? 0 : ignoreGroups + 1;
+ this.getTextNodes(function (dict) {
+ dict.nodes.forEach(function (node) {
+ node = node.node;
+ var match;
+
+ while ((match = regex.exec(node.textContent)) !== null && match[matchIdx] !== '') {
+ if (_this5.opt.separateGroups) {
+ node = _this5.separateGroups(node, match, matchIdx, filterCb, eachCb);
+ } else {
+ if (!filterCb(match[matchIdx], node)) {
+ continue;
+ }
+
+ var pos = match.index;
+
+ if (matchIdx !== 0) {
+ for (var i = 1; i < matchIdx; i++) {
+ pos += match[i].length;
+ }
+ }
+
+ node = _this5.wrapGroups(node, pos, match[matchIdx].length, eachCb);
+ }
+
+ regex.lastIndex = 0;
+ }
+ });
+ endCb();
+ });
+ }
+ }, {
+ key: "wrapMatchesAcrossElements",
+ value: function wrapMatchesAcrossElements(regex, ignoreGroups, filterCb, eachCb, endCb) {
+ var _this6 = this;
+
+ var matchIdx = ignoreGroups === 0 ? 0 : ignoreGroups + 1;
+ this.getTextNodes(function (dict) {
+ var match;
+
+ while ((match = regex.exec(dict.value)) !== null && match[matchIdx] !== '') {
+ var start = match.index;
+
+ if (matchIdx !== 0) {
+ for (var i = 1; i < matchIdx; i++) {
+ start += match[i].length;
+ }
+ }
+
+ var end = start + match[matchIdx].length;
+
+ _this6.wrapRangeInMappedTextNode(dict, start, end, function (node) {
+ return filterCb(match[matchIdx], node);
+ }, function (node, lastIndex) {
+ regex.lastIndex = lastIndex;
+ eachCb(node);
+ });
+ }
+
+ endCb();
+ });
+ }
+ }, {
+ key: "wrapRangeFromIndex",
+ value: function wrapRangeFromIndex(ranges, filterCb, eachCb, endCb) {
+ var _this7 = this;
+
+ this.getTextNodes(function (dict) {
+ var originalLength = dict.value.length;
+ ranges.forEach(function (range, counter) {
+ var _this7$checkWhitespac = _this7.checkWhitespaceRanges(range, originalLength, dict.value),
+ start = _this7$checkWhitespac.start,
+ end = _this7$checkWhitespac.end,
+ valid = _this7$checkWhitespac.valid;
+
+ if (valid) {
+ _this7.wrapRangeInMappedTextNode(dict, start, end, function (node) {
+ return filterCb(node, range, dict.value.substring(start, end), counter);
+ }, function (node) {
+ eachCb(node, range);
+ });
+ }
+ });
+ endCb();
+ });
+ }
+ }, {
+ key: "unwrapMatches",
+ value: function unwrapMatches(node) {
+ var parent = node.parentNode;
+ var docFrag = document.createDocumentFragment();
+
+ while (node.firstChild) {
+ docFrag.appendChild(node.removeChild(node.firstChild));
+ }
+
+ parent.replaceChild(docFrag, node);
+
+ if (!this.ie) {
+ parent.normalize();
+ } else {
+ this.normalizeTextNode(parent);
+ }
+ }
+ }, {
+ key: "normalizeTextNode",
+ value: function normalizeTextNode(node) {
+ if (!node) {
+ return;
+ }
+
+ if (node.nodeType === 3) {
+ while (node.nextSibling && node.nextSibling.nodeType === 3) {
+ node.nodeValue += node.nextSibling.nodeValue;
+ node.parentNode.removeChild(node.nextSibling);
+ }
+ } else {
+ this.normalizeTextNode(node.firstChild);
+ }
+
+ this.normalizeTextNode(node.nextSibling);
+ }
+ }, {
+ key: "markRegExp",
+ value: function markRegExp(regexp, opt) {
+ var _this8 = this;
+
+ this.opt = opt;
+ this.log("Searching with expression \"".concat(regexp, "\""));
+ var totalMatches = 0,
+ fn = 'wrapMatches';
+
+ var eachCb = function eachCb(element) {
+ totalMatches++;
+
+ _this8.opt.each(element);
+ };
+
+ if (this.opt.acrossElements) {
+ fn = 'wrapMatchesAcrossElements';
+ }
+
+ this[fn](regexp, this.opt.ignoreGroups, function (match, node) {
+ return _this8.opt.filter(node, match, totalMatches);
+ }, eachCb, function () {
+ if (totalMatches === 0) {
+ _this8.opt.noMatch(regexp);
+ }
+
+ _this8.opt.done(totalMatches);
+ });
+ }
+ }, {
+ key: "mark",
+ value: function mark(sv, opt) {
+ var _this9 = this;
+
+ this.opt = opt;
+ var totalMatches = 0,
+ fn = 'wrapMatches';
+
+ var _this$getSeparatedKey = this.getSeparatedKeywords(typeof sv === 'string' ? [sv] : sv),
+ kwArr = _this$getSeparatedKey.keywords,
+ kwArrLen = _this$getSeparatedKey.length,
+ handler = function handler(kw) {
+ var regex = new RegExpCreator(_this9.opt).create(kw);
+ var matches = 0;
+
+ _this9.log("Searching with expression \"".concat(regex, "\""));
+
+ _this9[fn](regex, 1, function (term, node) {
+ return _this9.opt.filter(node, kw, totalMatches, matches);
+ }, function (element) {
+ matches++;
+ totalMatches++;
+
+ _this9.opt.each(element);
+ }, function () {
+ if (matches === 0) {
+ _this9.opt.noMatch(kw);
+ }
+
+ if (kwArr[kwArrLen - 1] === kw) {
+ _this9.opt.done(totalMatches);
+ } else {
+ handler(kwArr[kwArr.indexOf(kw) + 1]);
+ }
+ });
+ };
+
+ if (this.opt.acrossElements) {
+ fn = 'wrapMatchesAcrossElements';
+ }
+
+ if (kwArrLen === 0) {
+ this.opt.done(totalMatches);
+ } else {
+ handler(kwArr[0]);
+ }
+ }
+ }, {
+ key: "markRanges",
+ value: function markRanges(rawRanges, opt) {
+ var _this10 = this;
+
+ this.opt = opt;
+ var totalMatches = 0,
+ ranges = this.checkRanges(rawRanges);
+
+ if (ranges && ranges.length) {
+ this.log('Starting to mark with the following ranges: ' + JSON.stringify(ranges));
+ this.wrapRangeFromIndex(ranges, function (node, range, match, counter) {
+ return _this10.opt.filter(node, range, match, counter);
+ }, function (element, range) {
+ totalMatches++;
+
+ _this10.opt.each(element, range);
+ }, function () {
+ _this10.opt.done(totalMatches);
+ });
+ } else {
+ this.opt.done(totalMatches);
+ }
+ }
+ }, {
+ key: "unmark",
+ value: function unmark(opt) {
+ var _this11 = this;
+
+ this.opt = opt;
+ var sel = this.opt.element ? this.opt.element : '*';
+ sel += '[data-markjs]';
+
+ if (this.opt.className) {
+ sel += ".".concat(this.opt.className);
+ }
+
+ this.log("Removal selector \"".concat(sel, "\""));
+ this.iterator.forEachNode(NodeFilter.SHOW_ELEMENT, function (node) {
+ _this11.unwrapMatches(node);
+ }, function (node) {
+ var matchesSel = DOMIterator.matches(node, sel),
+ matchesExclude = _this11.matchesExclude(node);
+
+ if (!matchesSel || matchesExclude) {
+ return NodeFilter.FILTER_REJECT;
+ } else {
+ return NodeFilter.FILTER_ACCEPT;
+ }
+ }, this.opt.done);
+ }
+ }, {
+ key: "opt",
+ set: function set(val) {
+ this._opt = _extends({}, {
+ 'element': '',
+ 'className': '',
+ 'exclude': [],
+ 'iframes': false,
+ 'iframesTimeout': 5000,
+ 'separateWordSearch': true,
+ 'acrossElements': false,
+ 'ignoreGroups': 0,
+ 'each': function each() {
+ },
+ 'noMatch': function noMatch() {
+ },
+ 'filter': function filter() {
+ return true;
+ },
+ 'done': function done() {
+ },
+ 'debug': false,
+ 'log': window.console
+ }, val);
+ },
+ get: function get() {
+ return this._opt;
+ }
+ }, {
+ key: "iterator",
+ get: function get() {
+ return new DOMIterator(this.ctx, this.opt.iframes, this.opt.exclude, this.opt.iframesTimeout);
+ }
+ }]);
+
+ return Mark;
+ }();
+
+ function Mark$1(ctx) {
+ var _this = this;
+
+ var instance = new Mark(ctx);
+
+ this.mark = function (sv, opt) {
+ instance.mark(sv, opt);
+ return _this;
+ };
+
+ this.markRegExp = function (sv, opt) {
+ instance.markRegExp(sv, opt);
+ return _this;
+ };
+
+ this.markRanges = function (sv, opt) {
+ instance.markRanges(sv, opt);
+ return _this;
+ };
+
+ this.unmark = function (opt) {
+ instance.unmark(opt);
+ return _this;
+ };
+
+ return this;
+ }
+
+ return Mark$1;
+
+})));
diff --git a/src/scripts/mark.min.js b/src/scripts/mark.min.js
new file mode 100644
index 00000000..5608e6bb
--- /dev/null
+++ b/src/scripts/mark.min.js
@@ -0,0 +1,13 @@
+/*!***************************************************
+* mark.js v9.0.0
+* https://markjs.io/
+* Copyright (c) 2014–2018, Julian Kühnel
+* Released under the MIT license https://git.io/vwTVl
+*****************************************************/
+!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.Mark=t()}(this,function(){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function n(e,t){for(var n=0;n1&&void 0!==arguments[1])||arguments[1],o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:5e3;t(this,e),this.ctx=n,this.iframes=r,this.exclude=o,this.iframesTimeout=i}return r(e,[{key:"getContexts",value:function(){var e=[];return(void 0!==this.ctx&&this.ctx?NodeList.prototype.isPrototypeOf(this.ctx)?Array.prototype.slice.call(this.ctx):Array.isArray(this.ctx)?this.ctx:"string"==typeof this.ctx?Array.prototype.slice.call(document.querySelectorAll(this.ctx)):[this.ctx]:[]).forEach(function(t){var n=e.filter(function(e){return e.contains(t)}).length>0;-1!==e.indexOf(t)||n||e.push(t)}),e}},{key:"getIframeContents",value:function(e,t){var n,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){};try{var o=e.contentWindow;if(n=o.document,!o||!n)throw new Error("iframe inaccessible")}catch(e){r()}n&&t(n)}},{key:"isIframeBlank",value:function(e){var t="about:blank",n=e.getAttribute("src").trim();return e.contentWindow.location.href===t&&n!==t&&n}},{key:"observeIframeLoad",value:function(e,t,n){var r=this,o=!1,i=null,a=function a(){if(!o){o=!0,clearTimeout(i);try{r.isIframeBlank(e)||(e.removeEventListener("load",a),r.getIframeContents(e,t,n))}catch(e){n()}}};e.addEventListener("load",a),i=setTimeout(a,this.iframesTimeout)}},{key:"onIframeReady",value:function(e,t,n){try{"complete"===e.contentWindow.document.readyState?this.isIframeBlank(e)?this.observeIframeLoad(e,t,n):this.getIframeContents(e,t,n):this.observeIframeLoad(e,t,n)}catch(e){n()}}},{key:"waitForIframes",value:function(e,t){var n=this,r=0;this.forEachIframe(e,function(){return!0},function(e){r++,n.waitForIframes(e.querySelector("html"),function(){--r||t()})},function(e){e||t()})}},{key:"forEachIframe",value:function(t,n,r){var o=this,i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:function(){},a=t.querySelectorAll("iframe"),s=a.length,c=0;a=Array.prototype.slice.call(a);var u=function(){--s<=0&&i(c)};s||u(),a.forEach(function(t){e.matches(t,o.exclude)?u():o.onIframeReady(t,function(e){n(t)&&(c++,r(e)),u()},u)})}},{key:"createIterator",value:function(e,t,n){return document.createNodeIterator(e,t,n,!1)}},{key:"createInstanceOnIframe",value:function(t){return new e(t.querySelector("html"),this.iframes)}},{key:"compareNodeIframe",value:function(e,t,n){if(e.compareDocumentPosition(n)&Node.DOCUMENT_POSITION_PRECEDING){if(null===t)return!0;if(t.compareDocumentPosition(n)&Node.DOCUMENT_POSITION_FOLLOWING)return!0}return!1}},{key:"getIteratorNode",value:function(e){var t=e.previousNode();return{prevNode:t,node:null===t?e.nextNode():e.nextNode()&&e.nextNode()}}},{key:"checkIframeFilter",value:function(e,t,n,r){var o=!1,i=!1;return r.forEach(function(e,t){e.val===n&&(o=t,i=e.handled)}),this.compareNodeIframe(e,t,n)?(!1!==o||i?!1===o||i||(r[o].handled=!0):r.push({val:n,handled:!0}),!0):(!1===o&&r.push({val:n,handled:!1}),!1)}},{key:"handleOpenIframes",value:function(e,t,n,r){var o=this;e.forEach(function(e){e.handled||o.getIframeContents(e.val,function(e){o.createInstanceOnIframe(e).forEachNode(t,n,r)})})}},{key:"iterateThroughNodes",value:function(e,t,n,r,o){for(var i,a,s,c=this,u=this.createIterator(t,e,r),l=[],h=[];s=void 0,s=c.getIteratorNode(u),a=s.prevNode,i=s.node;)this.iframes&&this.forEachIframe(t,function(e){return c.checkIframeFilter(i,a,e,l)},function(t){c.createInstanceOnIframe(t).forEachNode(e,function(e){return h.push(e)},r)}),h.push(i);h.forEach(function(e){n(e)}),this.iframes&&this.handleOpenIframes(l,e,n,r),o()}},{key:"forEachNode",value:function(e,t,n){var r=this,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:function(){},i=this.getContexts(),a=i.length;a||o(),i.forEach(function(i){var s=function(){r.iterateThroughNodes(e,i,t,n,function(){--a<=0&&o()})};r.iframes?r.waitForIframes(i,s):s()})}}],[{key:"matches",value:function(e,t){var n="string"==typeof t?[t]:t,r=e.matches||e.matchesSelector||e.msMatchesSelector||e.mozMatchesSelector||e.oMatchesSelector||e.webkitMatchesSelector;if(r){var o=!1;return n.every(function(t){return!r.call(e,t)||(o=!0,!1)}),o}return!1}}]),e}(),a=
+/* */
+function(){function e(n){t(this,e),this.opt=o({},{diacritics:!0,synonyms:{},accuracy:"partially",caseSensitive:!1,ignoreJoiners:!1,ignorePunctuation:[],wildcards:"disabled"},n)}return r(e,[{key:"create",value:function(e){return"disabled"!==this.opt.wildcards&&(e=this.setupWildcardsRegExp(e)),e=this.escapeStr(e),Object.keys(this.opt.synonyms).length&&(e=this.createSynonymsRegExp(e)),(this.opt.ignoreJoiners||this.opt.ignorePunctuation.length)&&(e=this.setupIgnoreJoinersRegExp(e)),this.opt.diacritics&&(e=this.createDiacriticsRegExp(e)),e=this.createMergedBlanksRegExp(e),(this.opt.ignoreJoiners||this.opt.ignorePunctuation.length)&&(e=this.createJoinersRegExp(e)),"disabled"!==this.opt.wildcards&&(e=this.createWildcardsRegExp(e)),e=this.createAccuracyRegExp(e),new RegExp(e,"gm".concat(this.opt.caseSensitive?"":"i"))}},{key:"sortByLength",value:function(e){return e.sort(function(e,t){return e.length===t.length?e>t?1:-1:t.length-e.length})}},{key:"escapeStr",value:function(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}},{key:"createSynonymsRegExp",value:function(e){var t=this,n=this.opt.synonyms,r=this.opt.caseSensitive?"":"i",o=this.opt.ignoreJoiners||this.opt.ignorePunctuation.length?"\0":"";for(var i in n)if(n.hasOwnProperty(i)){var a=Array.isArray(n[i])?n[i]:[n[i]];a.unshift(i),(a=this.sortByLength(a).map(function(e){return"disabled"!==t.opt.wildcards&&(e=t.setupWildcardsRegExp(e)),e=t.escapeStr(e)}).filter(function(e){return""!==e})).length>1&&(e=e.replace(new RegExp("(".concat(a.map(function(e){return t.escapeStr(e)}).join("|"),")"),"gm".concat(r)),o+"(".concat(a.map(function(e){return t.processSynonyms(e)}).join("|"),")")+o))}return e}},{key:"processSynonyms",value:function(e){return(this.opt.ignoreJoiners||this.opt.ignorePunctuation.length)&&(e=this.setupIgnoreJoinersRegExp(e)),e}},{key:"setupWildcardsRegExp",value:function(e){return(e=e.replace(/(?:\\)*\?/g,function(e){return"\\"===e.charAt(0)?"?":""})).replace(/(?:\\)*\*/g,function(e){return"\\"===e.charAt(0)?"*":""})}},{key:"createWildcardsRegExp",value:function(e){var t="withSpaces"===this.opt.wildcards;return e.replace(/\u0001/g,t?"[\\S\\s]?":"\\S?").replace(/\u0002/g,t?"[\\S\\s]*?":"\\S*")}},{key:"setupIgnoreJoinersRegExp",value:function(e){return e.replace(/[^(|)\\]/g,function(e,t,n){var r=n.charAt(t+1);return/[(|)\\]/.test(r)||""===r?e:e+"\0"})}},{key:"createJoinersRegExp",value:function(e){var t=[],n=this.opt.ignorePunctuation;return Array.isArray(n)&&n.length&&t.push(this.escapeStr(n.join(""))),this.opt.ignoreJoiners&&t.push("\\u00ad\\u200b\\u200c\\u200d"),t.length?e.split(/\u0000+/).join("[".concat(t.join(""),"]*")):e}},{key:"createDiacriticsRegExp",value:function(e){var t=this.opt.caseSensitive?"":"i",n=this.opt.caseSensitive?["aàáảãạăằắẳẵặâầấẩẫậäåāą","AÀÁẢÃẠĂẰẮẲẴẶÂẦẤẨẪẬÄÅĀĄ","cçćč","CÇĆČ","dđď","DĐĎ","eèéẻẽẹêềếểễệëěēę","EÈÉẺẼẸÊỀẾỂỄỆËĚĒĘ","iìíỉĩịîïī","IÌÍỈĨỊÎÏĪ","lł","LŁ","nñňń","NÑŇŃ","oòóỏõọôồốổỗộơởỡớờợöøō","OÒÓỎÕỌÔỒỐỔỖỘƠỞỠỚỜỢÖØŌ","rř","RŘ","sšśșş","SŠŚȘŞ","tťțţ","TŤȚŢ","uùúủũụưừứửữựûüůū","UÙÚỦŨỤƯỪỨỬỮỰÛÜŮŪ","yýỳỷỹỵÿ","YÝỲỶỸỴŸ","zžżź","ZŽŻŹ"]:["aàáảãạăằắẳẵặâầấẩẫậäåāąAÀÁẢÃẠĂẰẮẲẴẶÂẦẤẨẪẬÄÅĀĄ","cçćčCÇĆČ","dđďDĐĎ","eèéẻẽẹêềếểễệëěēęEÈÉẺẼẸÊỀẾỂỄỆËĚĒĘ","iìíỉĩịîïīIÌÍỈĨỊÎÏĪ","lłLŁ","nñňńNÑŇŃ","oòóỏõọôồốổỗộơởỡớờợöøōOÒÓỎÕỌÔỒỐỔỖỘƠỞỠỚỜỢÖØŌ","rřRŘ","sšśșşSŠŚȘŞ","tťțţTŤȚŢ","uùúủũụưừứửữựûüůūUÙÚỦŨỤƯỪỨỬỮỰÛÜŮŪ","yýỳỷỹỵÿYÝỲỶỸỴŸ","zžżźZŽŻŹ"],r=[];return e.split("").forEach(function(o){n.every(function(n){if(-1!==n.indexOf(o)){if(r.indexOf(n)>-1)return!1;e=e.replace(new RegExp("[".concat(n,"]"),"gm".concat(t)),"[".concat(n,"]")),r.push(n)}return!0})}),e}},{key:"createMergedBlanksRegExp",value:function(e){return e.replace(/[\s]+/gim,"[\\s]+")}},{key:"createAccuracyRegExp",value:function(e){var t=this,n=this.opt.accuracy,r="string"==typeof n?n:n.value,o="string"==typeof n?[]:n.limiters,i="";switch(o.forEach(function(e){i+="|".concat(t.escapeStr(e))}),r){case"partially":default:return"()(".concat(e,")");case"complementary":return i="\\s"+(i||this.escapeStr("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~¡¿")),"()([^".concat(i,"]*").concat(e,"[^").concat(i,"]*)");case"exactly":return"(^|\\s".concat(i,")(").concat(e,")(?=$|\\s").concat(i,")")}}}]),e}(),s=
+/* */
+function(){function n(e){t(this,n),this.ctx=e,this.ie=!1;var r=window.navigator.userAgent;(r.indexOf("MSIE")>-1||r.indexOf("Trident")>-1)&&(this.ie=!0)}return r(n,[{key:"log",value:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"debug",r=this.opt.log;this.opt.debug&&"object"===e(r)&&"function"==typeof r[n]&&r[n]("mark.js: ".concat(t))}},{key:"getSeparatedKeywords",value:function(e){var t=this,n=[];return e.forEach(function(e){t.opt.separateWordSearch?e.split(" ").forEach(function(e){e.trim()&&-1===n.indexOf(e)&&n.push(e)}):e.trim()&&-1===n.indexOf(e)&&n.push(e)}),{keywords:n.sort(function(e,t){return t.length-e.length}),length:n.length}}},{key:"isNumeric",value:function(e){return Number(parseFloat(e))==e}},{key:"checkRanges",value:function(e){var t=this;if(!Array.isArray(e)||"[object Object]"!==Object.prototype.toString.call(e[0]))return this.log("markRanges() will only accept an array of objects"),this.opt.noMatch(e),[];var n=[],r=0;return e.sort(function(e,t){return e.start-t.start}).forEach(function(e){var o=t.callNoMatchOnInvalidRanges(e,r),i=o.start,a=o.end;o.valid&&(e.start=i,e.length=a-i,n.push(e),r=a)}),n}},{key:"callNoMatchOnInvalidRanges",value:function(e,t){var n,r,o=!1;return e&&void 0!==e.start?(r=(n=parseInt(e.start,10))+parseInt(e.length,10),this.isNumeric(e.start)&&this.isNumeric(e.length)&&r-t>0&&r-n>0?o=!0:(this.log("Ignoring invalid or overlapping range: "+"".concat(JSON.stringify(e))),this.opt.noMatch(e))):(this.log("Ignoring invalid range: ".concat(JSON.stringify(e))),this.opt.noMatch(e)),{start:n,end:r,valid:o}}},{key:"checkWhitespaceRanges",value:function(e,t,n){var r,o=!0,i=n.length,a=t-i,s=parseInt(e.start,10)-a;return(r=(s=s>i?i:s)+parseInt(e.length,10))>i&&(r=i,this.log("End range automatically set to the max value of ".concat(i))),s<0||r-s<0||s>i||r>i?(o=!1,this.log("Invalid range: ".concat(JSON.stringify(e))),this.opt.noMatch(e)):""===n.substring(s,r).replace(/\s+/g,"")&&(o=!1,this.log("Skipping whitespace only range: "+JSON.stringify(e)),this.opt.noMatch(e)),{start:s,end:r,valid:o}}},{key:"getTextNodes",value:function(e){var t=this,n="",r=[];this.iterator.forEachNode(NodeFilter.SHOW_TEXT,function(e){r.push({start:n.length,end:(n+=e.textContent).length,node:e})},function(e){return t.matchesExclude(e.parentNode)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT},function(){e({value:n,nodes:r})})}},{key:"matchesExclude",value:function(e){return i.matches(e,this.opt.exclude.concat(["script","style","title","head","html"]))}},{key:"wrapRangeInTextNode",value:function(e,t,n){var r=this.opt.element?this.opt.element:"mark",o=e.splitText(t),i=o.splitText(n-t),a=document.createElement(r);return a.setAttribute("data-markjs","true"),this.opt.className&&a.setAttribute("class",this.opt.className),a.textContent=o.textContent,o.parentNode.replaceChild(a,o),i}},{key:"wrapRangeInMappedTextNode",value:function(e,t,n,r,o){var i=this;e.nodes.every(function(a,s){var c=e.nodes[s+1];if(void 0===c||c.start>t){if(!r(a.node))return!1;var u=t-a.start,l=(n>a.end?a.end:n)-a.start,h=e.value.substr(0,a.start),f=e.value.substr(l+a.start);if(a.node=i.wrapRangeInTextNode(a.node,u,l),e.value=h+f,e.nodes.forEach(function(t,n){n>=s&&(e.nodes[n].start>0&&n!==s&&(e.nodes[n].start-=l),e.nodes[n].end-=l)}),n-=l,o(a.node.previousSibling,a.start),!(n>a.end))return!1;t=a.end}return!0})}},{key:"wrapGroups",value:function(e,t,n,r){return r((e=this.wrapRangeInTextNode(e,t,t+n)).previousSibling),e}},{key:"separateGroups",value:function(e,t,n,r,o){for(var i=t.length,a=1;a-1&&r(t[a],e)&&(e=this.wrapGroups(e,s,t[a].length,o))}return e}},{key:"wrapMatches",value:function(e,t,n,r,o){var i=this,a=0===t?0:t+1;this.getTextNodes(function(t){t.nodes.forEach(function(t){var o;for(t=t.node;null!==(o=e.exec(t.textContent))&&""!==o[a];){if(i.opt.separateGroups)t=i.separateGroups(t,o,a,n,r);else{if(!n(o[a],t))continue;var s=o.index;if(0!==a)for(var c=1;cjquery-3.6.0.slim.min.js
popper.min.js
tippy.min.js
+ mark.min.js
diff --git a/src/ui/articleview.cc b/src/ui/articleview.cc
index 7e5f42a4..7acd93bb 100644
--- a/src/ui/articleview.cc
+++ b/src/ui/articleview.cc
@@ -477,8 +477,9 @@ void ArticleView::loadFinished( bool result )
if ( result ) {
emit pageLoaded( this );
}
- if ( Utils::Url::hasQueryItem( webview->url(), "regexp" ) )
+ if ( Utils::Url::hasQueryItem( webview->url(), "regexp" ) ) {
highlightFTSResults();
+ }
}
void ArticleView::handleTitleChanged( QString const & title )
@@ -2137,54 +2138,21 @@ void ArticleView::highlightFTSResults()
if ( regString.isEmpty() )
return;
- //watchout
to plainText will return "watchout".
- //if application goes here,that means the article text must contains the search text.
- //whole word match regString will contain \b . can not match the above senario.
- //workaround ,remove \b from the regstring="(\bwatch\b)"
- regString.remove( QRegularExpression( R"(\b)" ) );
- //make it simple ,and do not support too much complex cases. such as wildcard etc.
- firstAvailableText = regString;
+ //replace any unicode Number ,Symbol ,Punctuation ,Mark character to whitespace
+ regString.replace( QRegularExpression( R"([\p{N}\p{S}\p{P}\p{M}])", QRegularExpression::UseUnicodePropertiesOption ),
+ " " );
- if ( firstAvailableText.isEmpty() ) {
- return;
- }
-
- //remove possible wildcard character.
- auto cleaned =
- firstAvailableText.split( QRegularExpression( "\\p{P}", QRegularExpression::UseUnicodePropertiesOption ) );
-
- if ( cleaned.empty() )
+ if ( regString.trimmed().isEmpty() )
return;
- firstAvailableText = cleaned.at( 0 );
-#if ( QT_VERSION >= QT_VERSION_CHECK( 6, 0, 0 ) )
- webview->findText( firstAvailableText,
- QWebEnginePage::FindBackward,
- [ & ]( const QWebEngineFindTextResult & result ) {
- qInfo() << result.activeMatch() << "of" << result.numberOfMatches() << "matches";
+ QString script = QString(
+ "var context = document.querySelector(\"body\");\n"
+ "var instance = new Mark(context);\n"
+ "instance.mark(\"%1\");" )
+ .arg( regString );
- if ( result.numberOfMatches() == 0 ) {
- ftsSearchPanel->statusLabel->setText( searchStatusMessageNoMatches() );
- }
- else {
- ftsSearchPanel->statusLabel->setText(
- searchStatusMessage( result.activeMatch(), result.numberOfMatches() ) );
- }
-
- ftsSearchPanel->show();
- ftsSearchPanel->previous->setEnabled( result.numberOfMatches() > 1 );
- ftsSearchPanel->next->setEnabled( result.numberOfMatches() > 1 );
-
- ftsSearchIsOpened = true;
- } );
-#else
- webview->findText( firstAvailableText, QWebEnginePage::FindBackward, [ this ]( bool res ) {
- ftsSearchPanel->previous->setEnabled( res );
- if ( !ftsSearchPanel->next->isEnabled() )
- ftsSearchPanel->next->setEnabled( res );
- } );
-#endif
+ webview->page()->runJavaScript( script );
}
void ArticleView::setActiveDictIds( const ActiveDictIds & ad )