SyntaxHighlighter google开源项目(语法高亮、代码着色) - 开源空间 - 共享社区共享空间 - Powered by Discuz!NT

导读:


引言

syntaxhighlighter的目的是不依赖任何服务器端脚本即可在网页上插入着色后的代码

目标客户

主要是针对博客。不过,我看到了一些源码网站使用它作为其主要展示源代码的工具。

不适合客户

syntaxhighlighter不是针对那种强调在线编辑高亮代码的客户设计的,它不会让您编辑源代码,它不能这样做也绝不会这样做。

性能

syntaxhighlighter使用正则表达式解析源码。它不是非常快,事实上,它的速度相当缓慢。如果您想尝试百十行代码,您将不会看到任何问题。如果要高亮超过10k的源码,由于JavaScript运行时间过长会导致程序中止

SyntaxHighlighter is here to help a developer/coder to post code snippets online with ease and have it look pretty. It's 100% Java Script based and it doesn't care what you have on your server.

Features  Summary of features.

SyntaxHighlighter features


  • 100% client side, no server dependency
  • Multiple languages support
  • Easy to use and deploy, just copy files and link them in your templates
  • Wide browser support
  • Very lightweight, compressed core library is 11kb plus whatever brushes you need.


Languages  List of supported languages.

Supported languagesHere's a list of supported languages and their aliases:









































Language Aliases
C++ cpp, c, c++
C# c#, c-sharp, csharp
CSS css
Delphi delphi, pascal
Java java
Java Script js, jscript, javascript
PHP php
Python py, python
Ruby rb, ruby, rails, ror
Sql sql
VB vb, vb.net
XML/HTML xml, html, xhtml, xslt




Usage  How to use SyntaxHighlighter.

UsagePlacing the codePlace your code on the page and surround it with

 tag. Set name attribute to code and class attribute to one of the language aliases you wish to use. 
... some code here ...
NOTE: One important thing to watch out for is opening triangular bracket <. It must be replaced with an HTML equivalent of < in all cases. Failure to do won't break the page, but might break the source code displayed.
An alternative to
 is to use Extended configurationThere's a way to pass a few configuration options to the code block. It's done via colon separated arguments. 
... some code here ...
Making it workFinally, to get the whole thing to render properly on the page, you have to add JavaScript to the page.
type="text/css" rel="stylesheet" href="css/SyntaxHighlighter.css"><script language="javascript" src="js/shCore.js"></script><script language="javascript" src="js/shBrushCSharp.js"></script><script language="javascript" src="js/shBrushXml.js"></script><script language="javascript">dp.SyntaxHighlighter.ClipboardSwf = '/flash/clipboard.swf';dp.SyntaxHighlighter.HighlightAll('code');</script>For optimal result, place this code at the very end of your page. Check HighlightAll for more details about the function.



下载




















 FilenameSummary + LabelsUploadedSizeDownloadCount...
SyntaxHighlighter_1.5.1.rar 1.5.1  Featured Aug 0539.3 KB22152


本文转自
http://www.mikecat.net/space/viewspacepost.aspx?postid=52

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
`react-syntax-highlighter`是一个用于React应用中的代码高亮库,它可以让你在渲染中轻松地为各种编程语言提供语法高亮。当你需要在组件中显示代码片段并使其看起来更易阅读时,这个库非常有用。 以下是如何使用`react-syntax-highlighter`的步骤: 1. **安装依赖**: 使用npm或yarn来安装版本12.2.1: ``` npm install react-syntax-highlighter@12.2.1 或者 yarn add react-syntax-highlighter@12.2.1 ``` 2. **导入库和样式**: 在你的React组件中,导入`hljs`(用于实际的语法高亮)和`SyntaxHighlighter`组件: ```jsx import React from 'react'; import hljs from 'react-syntax-highlighter/dist/esm/hljs.min.js'; import { SyntaxHighlighter, Code } from 'react-syntax-highlighter/dist/esm/prism-react-renderer'; import 'react-syntax-highlighter/dist/esm/styles/prism.css'; // 引入你喜欢的样式,如Prism主题 ``` 3. **创建语法高亮组件**: 创建一个函数组件,接受`code`(你要高亮代码字符串)作为props,并使用`SyntaxHighlighter`包裹`Code`元素: ```jsx const HighlightedCode = ({ language, code }) => { return ( <SyntaxHighlighter language={language} customStyle={myCustomStyle}> <Code>{code}</Code> </SyntaxHighlighter> ); }; // 如果你需要动态语言设置,可以在函数内部判断: const myCustomStyle = /* ... */; // 根据需求自定义样式 // 使用组件示例: <HighlightedCode language="javascript" code={`function helloWorld() { console.log('Hello, world!'); }`} /> ``` 4. **处理不同语言的代码**: `SyntaxHighlighter`组件接受`language` prop,确保根据实际代码内容提供正确的语言标识。`react-syntax-highlighter`支持多种编程语言。 5. **定制样式**: 你可以覆盖默认样式或者创建自定义样式(`myCustomStyle`在上面的例子中被提到)。`prism.css`通常提供了丰富的样式选择。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值