本文目录

google-code-prettify 中代码只有 1 的 BUG

🌙
手机阅读
本文目录结构

在使用 code-prettify 的时候,有遇到一个 BUG;

当时使用的是国内一个博客提供给的链接,下载来后,有问题的;

问题:当从 webstrome 内复制的代码,直接复制近 WLW 的时候,行号只有第一行;其它的没有了;

clone github 的源码发现;

这个 BUG 已经被别人修复了;但是它的压缩包和 src 文件内还是以前的;

需要手动修改下;

找到 walk 这个方法;

    function walk(node) {
        var type = node.nodeType;
        if (type == 1 && !nocode.test(node.className)) {  // Element
            if ('br' === node.nodeName.toLowerCase()) {
                breakAfter(node);
                // Discard the <BR> since it is now flush against a </LI>.
                if (node.parentNode) {
                    node.parentNode.removeChild(node);
                }
            } else {
                for (var child = node.firstChild; child; child = child.nextSibling) {
                    walk(child);
                }
            }
        } else if ((type == 3 || type == 4) && isPreformatted) {  // Text
            var text = node.nodeValue;
            var match = text.match(lineBreak);
            if (match) {
                var firstLine = text.substring(0, match.index);
                node.nodeValue = firstLine;
                var tail = text.substring(match.index + match[0].length);
                if (tail) {
                    var parent = node.parentNode;
                    parent.insertBefore(
                        document.createTextNode(tail), node.nextSibling);
                }
                breakAfter(node);
                if (!firstLine) {
                    // Don't leave blank text nodes in the DOM.
                    node.parentNode.removeChild(node);
                }
            }
        }
    }

请把

    if (br === node.nodeName) {
    //修改为下面这个
    if (br === node.nodeName.toLowerCase()) {

然后压缩后就可以了;

Github 的仓库地址:https://github.com/jmblog/color-themes-for-google-code-prettify

AXIHE / 精选资源

浏览全部教程

面试题

学习网站

前端培训
自己甄别

前端书籍

关于朱安邦

我叫 朱安邦,阿西河的站长,在杭州。

以前是一名平面设计师,后来开始接接触前端开发,主要研究前端技术中的JS方向。

业余时间我喜欢分享和交流自己的技术,欢迎大家关注我的 Bilibili

关注我: Github / 知乎

于2021年离开前端领域,目前重心放在研究区块链上面了

我叫朱安邦,阿西河的站长

目前在杭州从事区块链周边的开发工作,机械专业,以前从事平面设计工作。

2014年底脱产在老家自学6个月的前端技术,自学期间几乎从未出过家门,最终找到了满意的前端工作。更多>

于2021年离开前端领域,目前从事区块链方面工作了