<pre> 中的语法高亮显示标签 [英] Syntax highlighting in <pre> tags
问题描述
是否有任何库可以让我在 <pre>
标签中显示代码并根据语言突出显示语法?我正在想象这样的事情:
类我的类:"""一个简单的示例类"""我 = 12345def f(自我):返回你好世界"
...pre.python
的 CSS 将适当地突出显示 Python 代码.
这样的东西存在吗?
#python代码在这里
还有 highlight.js,它可以选择自动检测语法并适当突出显示;但是,您需要同时使用
标签来包装您的代码.
如果您正在寻找服务器端示例,可以使用 GeSHi 或 Pygments 适用于 Python.
Are there any libraries that will allow me to display code in
<pre>
tags and highlight the syntax according to the language? I'm imagining something like this:<pre class="python"> class MyClass: """A simple example class""" i = 12345 def f(self): return 'hello world' </pre>
...where the CSS for
pre.python
would highlight the Python code appropriately.Does something like this exist?
解决方案There's SyntaxHighlighter:
<pre class="brush: python"> # python code here </pre>
There's also highlight.js which has the option of automatically detecting the syntax and highlighting it appropriately; however, you would need to use both
<pre><code>
tags to wrap your code.If you're looking for a server-side example, there's GeSHi or Pygments for Python.
这篇关于<pre> 中的语法高亮显示标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!