highlight

2019-09-13 admin

highlight是什么

什么是highlight,Highlight code syntax with node.js

highlight使用教程帮助文档

DEPRECATION NOTICE

This project is deprecated in favor of highlight.js. I never created the parser myself, the module was created in the early days of node as a wrapper for an existing browser based parser highlight.js so if you are using this module and have problems with the parsing logic, I can’t help you much as I’m not familiar with the inner details.

Pull requests are still welcomed - if you find a bug and fix it, then I’ll pull the change in but I won’t be fixing the bugs myself. Sorry for that.

highlight

highlight for node.js is based on highlight.js parser and is meant to highlight code syntax in languages that are not known beforehand (highlight.js detects the used language automatically). This is especially important for pages in Markdown format - there’s no easy way to know which language is actually used.

Installation

Use npm package manager

npm install highlight

Usage

Include syntax highlighter

var hl = require("highlight").Highlight;

highlight code

html = hl("for(var i=0;i<10;i++)alert(i);");

use special tab replacing string (default is 4 spaces)

html = hl(code_string, "<span>  </span>");

convert code only between <code> blocks (leaves everything else as is) - especially useful if used together with converted Markdown syntax that includes <code> blocks.

html = hl("<p>PHP:</p><code><?php echo 'Hello world!';?></code>", false, true);

Styles

highlight outputs HTML code with predefined CSS class names for different elements. This doesn’t make a lot of sense by default (it’s just a bunch of SPAN’s) so you need to use a CSS file that sets the used color set for the highlighting. There’s some sample CSS files in /lib/vendor/highlight.js/styles that can be used with no modification - just include one of the files in the page you are showing the highlighted code.

<link rel="stylesheet" href="/path/to/styles/default.css"/>

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-75015.html

文章标题:highlight

相关文章
react-highlight-words源码解析
react-highlight-words https://github.com/bvaughn/re… 一个React组件,用处:在一段文本中高亮展示某些单词 源码思路 直接返回一个函数式组件 最重要是调用findAll函数,返回[...
2018-03-07
react-highlight-words
react-highlight-words是什么 什么是react-highlight-words,React component to highlight words within a larger body of text react...
2019-04-09
jQuery.highlightRegex
jQuery.highlightRegex是什么 什么是jQuery.highlightRegex,Regular-expression highlighter for jQuery jQuery.highlightRegex官网:官网 ...
2018-08-21
highlight-es
highlight-es是什么 什么是highlight-es,Highlight ECMAScript syntax for the console or any other medium. highlight-es官网:官网 high...
2018-11-05
highlight.js的调用方法
highlight.js是一个用来高亮代码的插件 下载地址:https://highlightjs.org/downl… 配色参考:https://highlightjs.org/stati… 使用方法: &lt;!DOCTYPE html...
2018-12-24
gitbook-plugin-highlight
gitbook-plugin-highlight是什么 什么是gitbook-plugin-highlight,Default code highlighter for GitBook gitbook-plugin-highlight官网...
2019-01-29
texthighlighter
texthighlighter是什么 什么是texthighlighter,TextHighlighter allows you to highlight text on web pages. texthighlighter官网:官网 t...
2018-08-15
jQuery .click() is triggering when selecting/highlighting text
krische提出了一个问题:jQuery .click() is triggering when selecting/highlighting text,或许与您遇到的问题类似。 回答者Rocket Hazmat给出了该问题的处理方式: ...
2018-04-24
react-syntax-highlighter-virtualized-renderer
react-syntax-highlighter-virtualized-renderer是什么 什么是react-syntax-highlighter-virtualized-renderer,a virtualized custom r...
2018-10-21
remark-highlight.js
remark-highlight.js是什么 什么是remark-highlight.js,Highlight code blocks in Markdown files with highlight.js. remark-highlig...
2018-10-02
回到顶部