GithubHelp home page GithubHelp logo

sunriseydy / pure-highlightjs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from icodechef/pure-highlightjs

14.0 1.0 5.0 1.68 MB

一个可以在编辑器中可视化选择代码语言和插入代码的 WordPress 插件,可以显示行号、鼠标悬浮高亮和被标记行高亮

Home Page: https://blog.sunriseydy.top/technology/server-blog/wordpress/pure-highlightjs-with-line-number/

License: MIT License

CSS 79.54% HTML 0.72% PHP 12.58% JavaScript 7.16%
wordpress-plugin highlight line-numbers

pure-highlightjs's Introduction

Pure-Highlightjs

A lightweight syntax highlighter for WordPress

一个可以在编辑器中可视化选择代码语言和插入代码的 WordPress 插件。

利用 highlightjs 来实现代码高亮。

可以显示行号、鼠标悬浮高亮和被标记行高亮

预览图

代码高亮、显示行号、鼠标悬浮行高亮和被标记行高亮

上图为代码高亮、显示行号、鼠标悬浮行高亮和被标记行高亮

颜色设置界面

上图为颜色设置界面

显示行号

代码参考自:给博客的highlight.js添加行号和行号高亮

Dependents

highlight.js

BugList

未解决的 Bug:

代码中的单行注释 // ***** 后面所有的代码不会被高亮。判断是显示行号 JS 代码导致的,由于能力问题暂不能修复该 Bug,目前的解决办法为使用 Prism 实现代码高亮和显示行号。详见 Prism 分支。

</code></pre> 在同一行的代码不被显示,原版插件在插入代码时代码最后和结束标签连在一起,因此使用了显示行号 JS 脚本后会导致原来文章中代码最后一行不显示。

解决方法:修改之前的文章,或者用 SQL 语句批量更改之前文章中的 “</code></pre>

改为 “\n</code></pre>

即将代码最后一行和 </code></pre> 之间用换行隔开。

Attention

已在插件主文件中添加了执行 SQL 语句的函数,因此在启用插件时会自动执行下面的 SQL 语句。

SQL 语句为:

UPDATE wp_posts
SET post_content = replace( post_content, '</code></pre>', '\n</code></pre>' )
WHERE post_status = 'publish' AND post_type IN ('post','page');

UPDATE wp_posts
SET post_content = replace( post_content, '\n\n</code></pre>', '\n</code></pre>' )
WHERE post_status = 'publish' AND post_type IN ('post','page');

UPDATE wp_posts
SET post_content = replace( post_content, '\r\n\r\n</code></pre>', '\r\n</code></pre>' )
WHERE post_status = 'publish' AND post_type IN ('post','page');

对于之后编写新文章插入代码,此项目中已经将插件的插入代码部分做了修改,在插入代码时自动将代码和结束标签间用换行隔开。

Prism 分支

Prism 分支解决了目前已知的 Bug,不过没有了动画,能接受上面所说的Bug的,可以继续使用该版本(v2),若无法接受则使用 Prism 版本(v3)。

安装方法

前往 Release 页面下载打包好的 zip 压缩包,在 WordPress 插件页面点击安装插件,再点击上传插件,选中下载好的插件压缩包即可。对了,在启用插件前要先把原版的插件给停用了,不然可能会产生冲突。

具体教程

纯代码让 pure-highlightjs 插件能够显示代码行号(已更新插件)

License

The MIT License.

Copyright (c) Sunriseydy

pure-highlightjs's People

Contributors

icodechef avatar sunriseydy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.