Making line numbers uncopyable

后端 未结 4 1039
情书的邮戳
情书的邮戳 2021-01-02 04:20

I\'m working on adding line number support to Rainbow, a syntax highlighter, but I can\'t figure out how to make the line numbers uncopyable.

Disabling selection via

4条回答
  •  一生所求
    2021-01-02 04:36

    Okay, the easiest way in compliant browsers, and, sadly, not reliable cross-browser, is to use generated content (I've removed the various parts where index was being added to textual content in the plug-in, and used the following (at the end of the CSS) to implement un-copyable text:

    table.rainbow {
        counter-reset: line;
    }
    
    table.rainbow tbody tr td:first-child {
        counter-increment: line;
    }
    
    table.rainbow tr td:first-child::before {
        content: counter(line);
    }
    

    JS Fiddle demo.

    This does, though, have some rather large flaws (the cross-browser unfriendly approach being the biggest), so I'll try for something better...

提交回复
热议问题