basant307/AI_Governance_Project
045
1# Upgrading to Highlight.js v11.02 3- [Overview of Breaking Changes](#overview-of-breaking-changes)4 - [Built-in set of "Common" Languages](#built-in-set-of-common-languages)5 - [Language Files](#language-files)6 - [Language Aliases](#language-aliases)7 - [Styles and CSS](#styles-and-css)8 - [Grammar Scopes](#grammar-scopes)9 - [Behavioral changes](#behavioral-changes)10 - [API changes](#api-changes)11 - [Changes to Result Data](#changes-to-result-data)12 - [Feature Removal](#feature-removal)13 - [Small Things](#small-things)14 - [Upgrading from Version 9.x](#upgrading-from-version-9x)15 16 17## Overview of Breaking Changes18 19Welcome to version 11.0. This a major release and therefore contains breaking changes. Below is a complete list of those such changes.20 21 22### Built-in set of "Common" Languages23 24The default `highlight.min.js` build **removes** a few less popular grammars:25 26- apache27- http28- nginx29- properties30- coffeescript31 32If you need any of these, you can always create a custom build.33 34Ref: https://github.com/highlightjs/highlight.js/issues/284835 36 37### Language Files38 39This would matter if you are requiring any of these files directly (via Node.js or CDN).40 41- `htmlbars` has been removed. Use `handlebars` instead.42- `c-like` has been removed. Use `c`, `cpp`, or `arduino`.43- `sql_more` has been removed. Use `sql` instead or a more specific 3rd party grammar.44 45 46### Language Aliases47 48This would matter if you are using these aliases.49 50- `php3`,`php4`,`php5`, `php6`, `php7`, and `php8` have been removed. Use `php` instead.51- `zsh` has been removed. Use `sh` or `bash` instead.52- `freepascal`, `lazarus`, `lpr`, and `lpm` removed. Use `delphi` instead.53 54You can of course re-register any of these aliases easily if necessary. For example to restore the PHP aliases:55 56```js57hljs.registerAliases(["php3","php4","php5","php6","php7","php8"],{ languageName: "php" })58```59 60### Styles and CSS61 62- The default padding on `.hljs` element has been increased and is now `1em` (it was `0.5em` previously). If your design depends on the smaller spacing you may need to update your CSS to override.63- `schoolbook` no longer has a custom lined background, it is solid color now. The old image and CSS can be found in the [10-stable branch](https://github.com/highlightjs/highlight.js/tree/10-stable/src/styles) if you wish to manually copy it into your project.64- `github` includes significant changes to more properly match modern GitHub syntax highlighting. If you desire the old theme you can manually copy it into your project from the [10-stable branch](https://github.com/highlightjs/highlight.js/tree/10-stable/src/styles).65- `github-gist` has been removed in favor of `github` as GitHub and GitHub Gist have converged. If you desire the theme you can manually copy it into your project from the [10-stable branch](https://github.com/highlightjs/highlight.js/tree/10-stable/src/styles).66- The `.hljs` CSS selector is now further scoped. It now targets `code.hljs` (inline code) and `pre code.hljs` (code blocks). If you are using a different element you may need to update your CSS to reapply some styling.67- All [Base16 themes](https://github.com/highlightjs/base16-highlightjs) now live in the `styles/base16` directory - this means some CSS files have moved. Please confirm themes you use reference the new locations.68 69 70#### Grammar Scopes71 72- `.meta-string` removed/deprecated. Use `.meta .string` (a nested scope) instead. See [meta-keyword][].73- `.meta-keyword` removed/deprecated. Use `.meta .keyword` (a nested scope) instead. See [meta-keyword][].74 75### Behavioral changes76 77- `after:highlightElement` plugin callback is now fired *after* the DOM has been updated, not before.78 79#### API changes80 81- The option `ignoreIllegals` is now `true` by default (for `highlight()`). Previously it was `false`.82- The `highlight(language,code, ...args)` API no longer accepts `continuation` as a 4th argument.83- The `highlight(language,code, ...args)` API is deprecated (to be removed in 12.0).84 85The new call signature is `highlight(code, {options})`. ([see docs](https://highlightjs.readthedocs.io/en/latest/api.html#highlight))86 87Code using the old API:88 89```js90// highlight(language, code, ignoreIllegals, continuation)91highlight("javascript", "var a = 5;", true)92```93...would be upgraded to the newer API as follows:94 95```js96// highlight(code, {language, ignoreIllegals})97highlight("var a = 5;", {language: "javascript", ignoreIllegals: true})98```99 100The new API purposely does not support `continuation` as this is only intended for internal library usage.101 102- `initHighlighting()` is deprecated (to be removed in 12.0).103- `initHighlightingOnLoad()` is deprecated (to be removed in 12.0).104 105**Use `highlightAll()` instead.** ([see docs](https://highlightjs.readthedocs.io/en/latest/api.html#highlight-all)) The old functions are now simply aliases of `highlightAll()`. The new function may be called before or after the DOM is loaded and should do the correct thing in all cases, replacing the need for the previous individual functions.106 107Note: `highlightAll()` does not guard against calling itself repeatedly as the previous functions did. Your code should be careful to avoid doing this.108 109- `highlightBlock()` is deprecated (to be removed in 12.0).110 111**Use `highlightElement()` instead.** ([see docs](https://highlightjs.readthedocs.io/en/latest/api.html#highlight-element)) This is merely a naming change.112 113Note: The object literal passed to the `before:highlightElement` callback now passes the element in the `el` key vs the `block` key.114 115##### Changes to Result Data116 117- `highlightAuto()`'s `second_best` key has been renamed to `secondBest`118- `highlightElement()`'s result now no longer includes a `re` key. Use the `relevance` key now.119- `highlight()` renames some result keys to more clearly mark them as private: `_top`, `_emitter`, and `_illegalBy`. You should not depend on these keys as they are subject to change at any time.120- The `relevance` key returned by `highlight()` is no longer guaranteed to be an even integer.121- `highlightElement` now always tags blocks with a consistent `language-[name]` class122 123This behavior was inconsistent before. Sometimes `[name]` class would be added, sometimes the alias name would be added, something no class would be added. now `language-[name]` is always added. This also affects sublanguage `span` tags which now also include the `language-` prefix.124 125#### Feature Removal126 127- HTML auto-passthru is now no longer included in core. Use a plugin instead. For a possible plugin please see [#2889](https://github.com/highlightjs/highlight.js/issues/2889).128 129An example:130 131```html132<pre><code class="lang-js">133var a = 4;134<span class="yellow">var a = 4;</span>135</code></pre>136```137 138Unescaped HTML like this will now be ignored (stripped before highlighting) and a warning will be logged to the console. All HTML to be highlighted should be properly escaped to avoid potential HTML/JS injection attacks.139 140- `fixMarkup` has been removed.141 142This function was deprecated in v10.2. It is not our goal to provide random string utilities. You may need to provide your own replacement [Ref: #2534](https://github.com/highlightjs/highlight.js/issues/2634)143 144- `CSS_NUMBER_MODE` has been removed.145 146This rule was too broad for bring inclusion in core and has been removed.147 148- `lexemes` mode attribute has been removed.149 150Use the new `keywords.$pattern` instead.151 152Before:153 154```js155{156 keywords: "do.it start.now begin.later end.immediately"157 lexemes: /[a-z.]+/158}159```160 161After:162 163```js164{165 keywords: {166 $pattern: /[a-z.]+/167 keyword: "do.it start.now begin.later end.immediately",168 }169}170```171 172This may required converting your `keywords` key into an object if it's not already (as shown above).173 174- `endSameAsBegin` mode attribute has been removed.175 176Use the new `END_SAME_AS_BEGIN` mode rule/function instead.177 178- `useBR` configuration has been removed.179 180This configuration option was deprecated in v10.1. Use a plugin or preferably simply CSS `white-space: pre`. [Ref: #2559](https://github.com/highlightjs/highlight.js/issues/2559)181 182 183- `tabReplace` configuration has been removed.184 185This configuration option was deprecated in v10.5. Use a plugin or pre-render content instead with desired spacing. [Ref: #2874](https://github.com/highlightjs/highlight.js/issues/2874)186 187 188 189 190 191### Small Things192 193- The `regex` utility `join` has been renamed to `_eitherRewriteBackreferences` (this has always been intended for internal use only)194 195### Upgrading from Version 9.x196 197If you're upgrading all the way from version 9 it may still be helpful to review all the breaking changes in version 10 as well:198 199- [VERSION_10_UPGRADE.md](https://github.com/highlightjs/highlight.js/blob/main/VERSION_10_UPGRADE.md)200- [VERSION_10_BREAKING_CHANGES.md](https://github.com/highlightjs/highlight.js/blob/main/VERSION_10_BREAKING_CHANGES.md)201 202 203[meta-keyword]: https://github.com/highlightjs/highlight.js/pull/3167204 