我使用 Dojo 中包含的荧光笔(改编自Ivan Sagalaev 的 highlight.js)。您需要做的就是在您的网页头部包含几行代码(一个指向 AOL 或 Google 的脚本标签,一个指向 AOL 或 Google 托管的 CSS 的链接,以及一个请求突出显示的简单脚本)和添加带有预格式化片段的 <pre><code lang="javascript"> 块——它们将被自动找到并突出显示。
当然,支持多种语言以及自动猜测代码段的语言。如果用户关闭 JavaScript,它将优雅地降级。
这个解决方案的另一个优点:不需要托管任何文件,不需要配置服务器,不需要动态生成 HTML,可以与任何东西一起使用——即使是静态文件也会被突出显示。
You can see examples in official tests: test_highlight.html, test_pygments.html. This is the example of snippets on my web site: the article with several highlighted code snippets — look in the head of this page to see how the highlighter can be included directly from AOL.