# (old) method for adding languages to highlight.js on Discourse

**URL:** https://meta.discourse.org/t/old-method-for-adding-languages-to-highlight-js-on-discourse/55818
**Category:** Development
**Created:** [2017年一月16日 05:19 UTC](https://meta.discourse.org/t/old-method-for-adding-languages-to-highlight-js-on-discourse/55818 "2017-01-16T05:19:36Z")
**Posts on this page:** 1
**Showing post:** 19

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [2024年一月22日 10:23 UTC](https://meta.discourse.org/t/old-method-for-adding-languages-to-highlight-js-on-discourse/55818/19 "2024-01-22T10:23:44Z")

</div>

你好 @what，此主题的 OP 已过时。我已将有效的说明提取到一个新主题中：

> [@Install a new language for Highlight.JS via a theme component](https://meta.discourse.org/t/install-a-new-language-for-highlight-js-via-a-theme-component/292480):
>
> I’ve just added a hook to our HighlightJS code so now you can use the plugin API to add a custom language for Highlight.JS. Example (using the beancount language definition): const beancountLang = function(e){var c="[A-Z][A-Za-z0-9-]\*",a="[0-9]{4}[-|/][0-9]{2}[-|/][0-9]{2}",b="(balance|commodity|custom|document|event|note|open|pad|price|query)",t={cN:"literal",b:/([\-|\+]?)([\d]+[\.]?[\d]\*)/,r:0},n={cN:"string",b:'"',e:'"',r:0,c:[e.BE]},s={cN:"name",b:"\\{",e:"\\}",c:[{cN:"literal",b:a},t,n,{c…

---

_[View the full topic](https://meta.discourse.org/t/old-method-for-adding-languages-to-highlight-js-on-discourse/55818)._
