Mark.js保持永久标记吗? [英] Mark.js keep marking permanently?

查看:133
本文介绍了Mark.js保持永久标记吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在将mark.js用于Google chrome扩展程序以突出显示网页上的某些文本。

i am currently using mark.js for a google chrome extension to highlight some text on a web page.

现在,每当我刷新页面或右键单击时我所有的标记都丢失了。

Now whenever i refresh the page or do a right click all my marking is lost.

有没有办法保留该标记?据我所知,mark.js不会更改DOM。
我想标记文字但也可以例如当我打印该页面或将其另存为pdf时,要保持突出显示。.

Is there a way to keep that marking? As far as i see mark.js does not change the DOM. I would like to mark the text but also be able e.g. when i print that page or save it as a pdf, to maintain the highlighting i did..

这就是我标记的方式。它与 https://markjs.io/

That is the way i mark. it is pretty much the same as instructed on https://markjs.io/:

function mark(text, label){
var paragraphs = Array.from(document.getElementsByClassName('description-line'));
switch(label){
        case "strAdv":
            for(var elem of paragraphs) { // loop through each element in paragraphs array
                 var instance=new Mark(elem);
                 instance.mark(text, {className: "strAdv",separateWordSearch:false});

             }
             break;
....

strAdv.css:

strAdv.css:

/*CSS to define diferent marking classes*/
.strAdv {
padding: 0;
background-color: chartreuse;
}


推荐答案

找到了解决该问题的方法问题。
只需存储要标记的文本项,并在每次刷新页面时再次对其进行标记。

Found a way to overcome that problem. Just store the text items you want to mark and mark them again every time a page gets refreshed.

这篇关于Mark.js保持永久标记吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆