📄 VERSION_11_UPGRADE.md

← 返回目录

Upgrading to Highlight.js v11.0

- Overview of Breaking Changes - Built-in set of "Common" Languages - Language Files - Language Aliases - Styles and CSS - Grammar Scopes - Behavioral changes - API changes - Changes to Result Data - Feature Removal - Small Things - Upgrading from Version 9.x

Overview of Breaking Changes

Welcome to version 11.0. This a major release and therefore contains breaking changes. Below is a complete list of those such changes.

Built-in set of "Common" Languages

The default highlight.min.js build removes a few less popular grammars:

- apache

Language Files

This would matter if you are requiring any of these files directly (via Node.js or CDN).

- htmlbars has been removed. Use handlebars instead.

Language Aliases

This would matter if you are using these aliases.

- php3,php4,php5, php6, php7, and php8 have been removed. Use php instead.

Styles and CSS

- 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.

#### Grammar Scopes

- .meta-string removed/deprecated. Use .meta .string (a nested scope) instead. See [meta-keyword][].

highlight("javascript", "var a = 5;", true) ...would be upgraded to the newer API as follows:

// highlight(code, {language, ignoreIllegals})
highlight("var a = 5;", {language: "javascript", ignoreIllegals: true})

The new API purposely does not support continuation as this is only intended for internal library usage.

- initHighlighting() is deprecated (to be removed in 12.0).

var a = 4; var a = 4;

Unescaped 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.

- fixMarkup has been removed.

This 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

- CSS_NUMBER_MODE has been removed.

This rule was too broad for bring inclusion in core and has been removed.

- lexemes mode attribute has been removed.

Use the new keywords.$pattern instead.

Before:

{
  keywords: "do.it start.now begin.later end.immediately"
  lexemes: /[a-z.]+/
}

After:

{
  keywords: {
    $pattern: /[a-z.]+/
    keyword: "do.it start.now begin.later end.immediately",
  }
}

This may required converting your keywords key into an object if it's not already (as shown above).

- endSameAsBegin mode attribute has been removed.

Use the new END_SAME_AS_BEGIN mode rule/function instead.

- useBR configuration has been removed.

This configuration option was deprecated in v10.1. Use a plugin or preferably simply CSS white-space: pre. Ref: #2559

[meta-keyword]: https://github.com/highlightjs/highlight.js/pull/3167