diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000..a3d789ae81 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,15 @@ +.DS_Store +build +docs/_build +__pycache__ +*.swp +node_modules +.project + +# editors +.idea/ +.vscode/ +.Rproj.user + +# misc +/work diff --git a/.eslintrc.js b/.eslintrc.js index 1561b367b1..3d7e7b9bf1 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,71 +1,86 @@ module.exports = { - "env": { - "browser": true, - "es6": true, - "node": true, - "mocha": true - }, - "extends": [ - "eslint:recommended", - "standard" - ], - "globals": { - "Atomics": "readonly", - "SharedArrayBuffer": "readonly" - }, - "parserOptions": { - "ecmaVersion": 2018, - "sourceType": "module" - }, - "parser": '@typescript-eslint/parser', - "plugins": [ - "@typescript-eslint" - ], - "rules": { - "array-callback-return": "error", - "block-scoped-var": "error", - // we like our semi-colons - "semi": ["error","always"], - // our codebase doesn't do this at all, so disabled for now - "space-before-function-paren": ["error","never"], - // for now ignore diff between types of quoting - "quotes": "off", - // this is the style we are already using - "operator-linebreak": ["error","before", { "overrides": { "?": "after", ":": "after", "+": "after" } }], - // sometimes we declare variables with extra spacing - "indent": ["error", 2, {"VariableDeclarator":2}], - // seems like a good idea not to use explicit undefined - "no-undefined": "error", - // ensure import specifier contains file extension - "import/extensions": ["error", "always"], - - // TODO maybe - "camelcase": "off", // TODO: turn on later - "init-declarations": ["error","always"] + env: { + browser: true, + es6: true, + node: true, + mocha: true + }, + extends: [ + "eslint:recommended", + "standard" + ], + globals: { + Atomics: "readonly", + SharedArrayBuffer: "readonly" + }, + parserOptions: { + ecmaVersion: 2015, + sourceType: "module" + }, + // parser: '@typescript-eslint/parser', + plugins: [ + "@typescript-eslint" + ], + rules: { + "no-var": 1, + "init-declarations": ["error", "always"], + "array-callback-return": "error", + "block-scoped-var": "error", + // we like our semi-colons + semi: ["error", "always"], + // our codebase doesn't do this at all, so disabled for now + "space-before-function-paren": ["error", "never"], + // for now ignore diff between types of quoting + quotes: "off", + // this is the style we are already using + "operator-linebreak": ["error", "before", { overrides: { "=": "after", "?": "after", ":": "after", "+": "after" } }], + // sometimes we declare variables with extra spacing + indent: ["error", 2, { VariableDeclarator: 2 }], + // seems like a good idea not to use explicit undefined + "no-undefined": "error", + // ensure import specifier contains file extension + "import/extensions": ["error", "always"] + }, + overrides: [ + { + files: ["src/**/*.js"], + rules: { + // make sure there is no Node.js specific API slipping into the source files + "import/no-nodejs-modules": "error", + "import/no-commonjs": "error" + } }, - "overrides": [ - { - "files": ["src/**/*.js"], - "rules": { - // make sure there is no Node.js specific API slipping into the source files - "import/no-nodejs-modules": "error", - "import/no-commonjs": "error", - } - }, - { - "files": ["src/languages/*.js"], - "rules": { - "no-unused-expressions": "off", - // languages are all over the map and we don't want to - // do a mass edit so turn off the most egregious rule violations - "indent": "off", - "comma-dangle": "off", - "array-bracket-spacing": "off", - "object-curly-spacing": "off", - "key-spacing": "off", - "object-curly-newline": "off", - "object-property-newline": "off" - } + { + files: ["src/languages/*.js"], + rules: { + "no-unused-expressions": "off", + // // languages are all over the map and we don't want to + // // do a mass edit so turn off the most egregious rule violations + // indent: "off", + "camelcase": 0, + "no-control-regex": 0, + "no-useless-escape": 0, + "comma-dangle": 1, + "array-bracket-spacing": ["error", "always" + // { + // objectsInArrays: true + // } + ], + // "object-curly-spacing": 1, + // "key-spacing": "off", + // "array-bracket-spacing": [1], + "array-bracket-newline": [1, { + multiline: true, + minItems: 2 + }], + "array-element-newline": 1, + "object-curly-newline": [1, { + minProperties: 1 + }], + "object-property-newline": [2, + { allowAllPropertiesOnSameLine: false } + ] } - ] + } + ] }; diff --git a/.eslintrc.lang.js b/.eslintrc.lang.js new file mode 100644 index 0000000000..da193b1a51 --- /dev/null +++ b/.eslintrc.lang.js @@ -0,0 +1,20 @@ +module.exports = { + env: { + browser: true, + es6: true, + node: true, + mocha: true + }, + extends: [], + globals: { + Atomics: "readonly", + SharedArrayBuffer: "readonly" + }, + parserOptions: { + ecmaVersion: 2015, + sourceType: "module" + }, + // no rules, this file exists only to lint the grammars and check + // that no ES2018 or newer syntax has crept in by accident + rules: {} +}; diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000000..21245f47e6 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,12 @@ + + + + + +### Changes + + +### Checklist +- [ ] Added markup tests, or they don't apply here because... +- [ ] Updated the changelog at `CHANGES.md` +- [ ] Added myself to `AUTHORS.txt`, under Contributors diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000000..187b5f8d45 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,31 @@ +# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: Lint + +on: +# push: + # branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [15.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - name: Lint the main source + run: npx eslint src/*.js src/lib/*.js + - name: Lint the language grammars + run: npx eslint --no-eslintrc -c .eslintrc.lang.js src/languages/**/*.js diff --git a/.github/workflows/node.js.yml b/.github/workflows/node.js.yml new file mode 100644 index 0000000000..f3a91de333 --- /dev/null +++ b/.github/workflows/node.js.yml @@ -0,0 +1,48 @@ +# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: Node.js CI + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [12.x, 14.x, 15.x] + build-how: ["node", "browser", "browser -n"] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: node ./tools/build.js -t ${{ matrix.build-how }} + # normal browser build + - if: contains(matrix.build-how, 'browser') + name: Test browser build + run: | + npm run test-browser + node test/builds/browser_build_as_commonjs.js + + - if: contains(matrix.build-how, 'node') + name: Test Node.js build + run: | + npm test + + # test that our build is "use strict" safe for use with packaging + # systems importing our source thru ES6 modules (rollup, etc.) + - if: contains(matrix.build-how, 'node') + name: Test Node.js build is "use strict" safe + run: | + ./node_modules/.bin/rollup -c test/builds/rollup_import_via_commonjs.js + node build/bundle.js diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000000..31bdad66c4 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,131 @@ +name: Release + +on: + push: + tags: + - "*beta*" + - "*pre*" + - "1[0-9]+.[0-9]+.[0-9]+" + +jobs: + prerelease: + name: Pre-release + runs-on: ubuntu-latest + steps: + - name: Checkout highlight.js + uses: actions/checkout@v2 + + - name: Tag is ${{ github.ref }}. + # we have to repeat ourselves here since the environment is not actually updated + # until the next step executes, so we can't access $TAG_NAME yet + run: | + echo "TAG_NAME=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV + echo "MAJOR_VERSION=$(echo ${GITHUB_REF/refs\/tags\//} | cut -d'.' -f1)" >> $GITHUB_ENV + - name: Make sure we are pushing a tag... + if: ${{ !contains(github.ref,'refs/tags/') }} + run: false + # run: echo "TAG_NAME=0.0.0-test0" >> $GITHUB_ENV + + - if: contains(github.ref, 'beta') || contains(github.ref, 'pre') + run: | + echo "NPM_TAG=beta" >> $GITHUB_ENV + echo "RELEASING=beta" >> $GITHUB_ENV + + - if: ${{ !(contains(github.ref, 'beta') || contains(github.ref, 'pre')) }} + run: | + echo "NPM_TAG=latest" >> $GITHUB_ENV + echo "RELEASING=stable" >> $GITHUB_ENV + + - name: match-tag-to-package-version + uses: geritol/match-tag-to-package-version@0.0.2 + env: + TAG_PREFIX: refs/tags/ # Optional, default prefix refs/tags/ + + - name: Use Node.js 15.x + uses: actions/setup-node@v1 + with: + node-version: 15.x + - name: Build Node.js package + run: | + npm install + node ./tools/build.js -t node + npm test + + - name: Publish highlight.js to NPM + id: publish + uses: JS-DevTools/npm-publish@v1 + with: + check-version: true + token: ${{ secrets.NPM_TOKEN }} + package: ./build/package.json + tag: ${{ env.NPM_TAG }} + + - if: steps.publish.outputs.type != 'none' + run: | + echo "Version changed: ${{ steps.publish.outputs.old-version }} => ${{ steps.publish.outputs.version }}" + + # if stable release + - name: Stable Release + if: env.RELEASING == 'stable' + run: echo "BRANCH_NAME=${MAJOR_VERSION}-stable" >> $GITHUB_ENV + # else (beta) + - name: Beta Release + if: env.RELEASING == 'beta' + run: echo "BRANCH_NAME=master" >> $GITHUB_ENV + - name: Confirm release is either stable or beta + if: ${{ !(env.RELEASING == 'stable' || env.RELEASING == 'beta') }} + run: | + echo We seem to be releasing `${RELEASING}`. + false + + - name: Checkout cdn-release + uses: actions/checkout@v2 + with: + repository: 'highlightjs/cdn-release' + path: 'cdn-release' + token: ${{ secrets.CDN_REPO_TOKEN }} + ref: ${{ env.BRANCH_NAME }} + + - name: Build CDN package + run: node ./tools/build.js -t cdn :common + + - name: Commmit & Push cdn-release ${{ env.TAG_NAME }} + working-directory: ./cdn-release + run: | + rm -r ./build + mv ../build/ ./build/ + git config user.name github-actions + git config user.email github-actions@github.com + git add ./build/ + git commit -m'Update to version ${{ env.TAG_NAME }}' + git tag ${TAG_NAME} + git push -f --atomic origin ${BRANCH_NAME} ${TAG_NAME} + + - name: Publish cdn-assets to NPM + id: publish_cdn + uses: JS-DevTools/npm-publish@v1 + with: + check-version: true + token: ${{ secrets.NPM_TOKEN }} + package: ./cdn-release/build/package.json + tag: ${{ env.NPM_TAG }} + + # log.info('Updating CDN repo at %s' % settings.HLJS_CDN_SOURCE) + # run(['nodejs', 'tools/build.js', '--target', 'cdn', ':common']) + # os.chdir(settings.HLJS_CDN_SOURCE) + # run(['git', 'pull', '-f']) + # lines = run(['git', '--git-dir', os.path.join(settings.HLJS_CDN_SOURCE, '.git'), 'tag']) + # build_dir = os.path.join(settings.HLJS_CDN_SOURCE, 'build') + # if version in lines: + # log.info('Tag %s already exists in the local CDN repo' % version) + # else: + # if os.path.exists(build_dir): + # shutil.rmtree(build_dir) + # shutil.move(os.path.join(settings.HLJS_SOURCE, 'build'), build_dir) + # run(['git', 'add', '.']) + # run(['git', 'commit', '-m', 'Update to version %s' % version]) + # run(['git', 'tag', version]) + # run(['git', 'push']) + # run(['git', 'push', '--tags']) + # npm_publish(build_dir) + # os.chdir(settings.HLJS_SOURCE) diff --git a/.gitignore b/.gitignore index 52ed616381..c61bf80d10 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ extra/ # misc /work +/website diff --git a/.mocharc.json b/.mocharc.json new file mode 100644 index 0000000000..ef2f5d36c8 --- /dev/null +++ b/.mocharc.json @@ -0,0 +1,3 @@ +{ + "require": "should" +} diff --git a/.tokeignore b/.tokeignore new file mode 100644 index 0000000000..783c23bc18 --- /dev/null +++ b/.tokeignore @@ -0,0 +1,7 @@ +test/* +src/styles/* +*.md +*.json +tools +docs +types diff --git a/.travis.yml b/.travis.yml index 67fd1364cf..01429794df 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,7 +28,7 @@ script: if [ "x$BUILD" = "xnode" ]; then npm run test else - npm run test-browser + npm run test-browser || exit 1 # our browser build should also work fine as a Node.js CommonJS module node test/builds/browser_build_as_commonjs.js fi diff --git a/AUTHORS.txt b/AUTHORS.txt index 131f873ad8..68d7233d31 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -2,20 +2,27 @@ Syntax highlighting with language autodetection. URL: https://highlightjs.org/ -Current core developers (alphabetical): + +Current Core Team: + +- Josh Goebel (maintainer) +- Egor Rogov +- Vladimir Jimenez + +Former maintainers: + +- Ivan Sagalaev (original author) +- Jeremy Hull +- Oleg Efimov + +Former Core Team members: - Gidi Meir Morris - Jan T. Sott - Li Xuanji - Marcos Cáceres - Sang Dang -- Josh Goebel - -Former maintainers: -- Ivan Sagalaev (original author) -- Jeremy Hull -- Oleg Efimov Contributors: @@ -288,3 +295,18 @@ Contributors: - Alexandre Grison - Jim Mason - lioshi +- David Pine +- Konrad Rudolph +- Tom Wallace +- Michael Newton +- Richard Gibson +- Fredrik Ekre +- Jan Pilzer +- Jonathan Sharpe +- Michael Rush +- Florian Bezdeka +- Marat Nagayev +- Patrick Scheibe +- Kyle Brown +- Marcus Ortiz +- Guillaume Grossetie diff --git a/CHANGES.md b/CHANGES.md index 64af1e904b..c570079808 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,207 @@ +## Version 10.4.1 + +Security + +- (fix) Exponential backtracking fixes for: [Josh Goebel][] + - cpp + - handlebars + - gams + - perl + - jboss-cli + - r + - erlang-repl + - powershell + - routeros +- (fix) Polynomial backtracking fixes for: [Josh Goebel][] + - asciidoc + - reasonml + - latex + - kotlin + - gcode + - d + - aspectj + - moonscript + - coffeescript/livescript + - csharp + - scilab + - crystal + - elixir + - basic + - ebnf + - ruby + - fortran/irpf90 + - livecodeserver + - yaml + - x86asm + - dsconfig + - markdown + - ruleslanguage + - xquery + - sqf + +Very grateful to [Michael Schmidt][] for all the help. + +[Michael Schmidt]: https://github.com/RunDevelopment +[Josh Goebel]: https://github.com/joshgoebel + + +## Version 10.4.0 + +A largish release with many improvements and fixes from quite a few different contributors. Enjoy! + +Deprecations: + +- (chore) `requireLanguage` is deprecated. + - Prefer `getLanguage` (with custom error handling) or built-time dependencies. + - See [Library API](https://highlightjs.readthedocs.io/en/latest/api.html#requirelanguage-name) for more information. + +Parser: + +- enh(parser) use negative look-ahead for `beginKeywords` support (#2813) [Josh Goebel][] +- enh(grammars) allow `classNameAliases` for more complex grammars [Josh Goebel][] +- fix(vue): Language name now appears in CSS class (#2807) [Michael Rush][] +- (chore) Clean up all regexs to be UTF-8 compliant/ready (#2759) [Josh Goebel][] + +New Languages: + +- Added 3rd party Chapel grammar to SUPPORTED_LANGUAGES (#2806) [Brad Chamberlain][] +- Added BBCode grammar to SUPPORTED_LANGUAGES (#2867) [Paul Reid][] +- enh(javascript) Added `node-repl` for Node.js REPL sessions (#2792) [Marat Nagayev][] + +Language Improvements: + +- enh(shell) Recognize prompts which contain tilde `~` (#2859) [Guillaume Grossetie][] +- enh(shell) Add support for multiline commands with line continuation `\` (#2861) [Guillaume Grossetie][] +- enh(autodetect) Over 30+ improvements to auto-detect (#2745) [Josh Goebel][] + - 4-5% improvement in auto-detect against large sample set + - properties, angelscript, lsl, javascript, n1ql, ocaml, ruby + - protobuf, hy, scheme, crystal, yaml, r, vbscript, groovy + - python, java, php, lisp, matlab, clojure, csharp, css +- fix(r) fixed keywords not properly spaced (#2852) [Josh Goebel][] +- fix(javascript) fix potential catastrophic backtracking (#2852) [Josh Goebel][] +- fix(livescript) fix potential catastrophic backtracking (#2852) [Josh Goebel][] +- bug(xml) XML grammar was far too imprecise/fuzzy [Josh Goebel][] +- enh(xml) Improve precision to prevent false auto-detect positives [Josh Goebel][] +- fix(js/ts) Prevent for/while/if/switch from falsly matching as functions (#2803) [Josh Goebel][] +- enh(julia) Update keyword lists for Julia 1.x (#2781) [Fredrik Ekre][] +- enh(python) Match numeric literals per the language reference [Richard Gibson][] +- enh(ruby) Match numeric literals per language documentation [Richard Gibson][] +- enh(javascript) Match numeric literals per ECMA-262 spec [Richard Gibson][] +- enh(java) Match numeric literals per Java Language Specification [Richard Gibson][] +- enh(swift) Match numeric literals per language reference [Richard Gibson][] +- enh(php) highlight variables (#2785) [Taufik Nurrohman][] +- fix(python) Handle comments on decorators (#2804) [Jonathan Sharpe][] +- enh(diff) improve highlighting of diff for git patches [Florian Bezdeka][] +- fix(llvm) lots of small improvements and fixes (#2830) [Josh Goebel][] +- enh(mathematica) Rework entire implementation [Patrick Scheibe][] + - Correct matching of the many variations of Mathematica's numbers + - Matching of named-characters aka special symbols like `\[Gamma]` + - Updated list of version 12.1 built-in symbols + - Matching of patterns, slots, message-names and braces +- fix(swift) Handle keywords that start with `#` [Marcus Ortiz][] +- enh(swift) Match `some` keyword [Marcus Ortiz][] +- enh(swift) Match `@main` attribute [Marcus Ortiz][] + +Dev Improvements: + +- chore(dev) add theme picker to the tools/developer tool (#2770) [Josh Goebel][] +- fix(dev) the Vue.js plugin no longer throws an exception when hljs is not in the global namespace [Kyle Brown][] + +New themes: + +- *StackOverflow Dark* by [Jan Pilzer][] +- *StackOverflow Light* by [Jan Pilzer][] + +[Guillaume Grossetie]: https://github.com/mogztter +[Brad Chamberlain]: https://github.com/bradcray +[Marat Nagayev]: https://github.com/nagayev +[Fredrik Ekre]: https://github.com/fredrikekre +[Richard Gibson]: https://github.com/gibson042 +[Josh Goebel]: https://github.com/joshgoebel +[Taufik Nurrohman]: https://github.com/taufik-nurrohman +[Jan Pilzer]: https://github.com/Hirse +[Jonathan Sharpe]: https://github.com/textbook +[Michael Rush]: https://github.com/rushimusmaximus +[Patrick Scheibe]: https://github.com/halirutan +[Kyle Brown]: https://github.com/kylebrown9 +[Marcus Ortiz]: https://github.com/mportiz08 +[Paul Reid]: https://github.com/RedGuy12 + + +## Version 10.3.1 + +Prior version let some look-behind regex sneak in, which does not work +yet on Safari. This release removes those incompatible regexes. + +Fix: + +- fix(Safari) Remove currently unsupported look-behind regex ([fix][187e7cfc]) [Josh Goebel][] + +[Josh Goebel]: https://github.com/joshgoebel +[187e7cfc]: https://github.com/highlightjs/highlight.js/commit/187e7cfcb06277ce13b5f35fb6c37ab7a7b46de9 + + +## Version 10.3.0 + +Language Improvements: + +- enh(latex) Complete ground up rewrite of LaTex grammar [schtandard][] +- fix(cpp) implement backslash line continuation in comments (#2757) [Konrad Rudolph][] +- fix(cpp) improve parsing issues with templates (#2752) [Josh Goebel][] +- enh(cpp) add support for `enum (struct|class)` and `union` (#2752) [Josh Goebel][] +- fix(js/ts) Fix nesting of `{}` inside template literals SUBST expression (#2748) [Josh Goebel][] +- enh(js/ts) Highlight class methods as functions (#2727) [Josh Goebel][] +- fix(js/ts) `constructor` is now highlighted as a function title (not keyword) (#2727) [Josh Goebel][] +- fix(c-like) preprocessor directives not detected after else (#2738) [Josh Goebel][] +- enh(javascript) allow `#` for private class fields (#2701) [Chris Krycho][] +- fix(js) prevent runaway regex (#2746) [Josh Goebel][] +- fix(bash) enh(bash) allow nested params (#2731) [Josh Goebel][] +- fix(python) Fix highlighting of keywords and strings (#2713, #2715) [Konrad Rudolph][] +- fix(fsharp) Prevent `(*)` from being detected as a multi-line comment [Josh Goebel][] +- enh(bash) add support for heredocs (#2684) [Josh Goebel][] +- enh(r) major overhaul of the R language grammar (and fix a few bugs) (#2680) [Konrad Rudolph][] +- enh(csharp) Add all C# 9 keywords, and other missing keywords (#2679) [David Pine][] +- enh(objectivec) Add `objective-c++` and `obj-c++` aliases for Objective-C [Josh Goebel][] +- enh(java) Add support for `record` (#2685) [Josh Goebel][] +- fix(csharp) prevent modifier keywords wrongly flagged as `title` (#2683) [Josh Goebel][] +- enh(axapta) Update keyword list for Axapta (X++) (#2686) [Ryan Jonasson][] +- fix(fortran) FORTRAN 77-style comments (#2677) [Philipp Engel][] +- fix(javascript) Comments inside params should be highlighted (#2702) [Josh Goebel][] +- fix(scala) Comments inside class header should be highlighted (#1559) [Josh Goebel][] +- fix(c-like) Correctly highlight modifiers (`final`) in class declaration (#2696) [Josh Goebel][] +- enh(angelscript) Improve heredocs, numbers, metadata blocks (#2724) [Melissa Geels][] +- enh(javascript) Implement Numeric Separators (#2617) [Antoine du Hamel][] +- enh(typescript) TypeScript also gains support for numeric separators (#2617) [Antoine du Hamel][] +- enh(php) Add support for PHP 8 `match` keyword and add `php8` as an alias (#2733) [Ayesh Karunaratne][] +- fix(handlebars) Support if else keyboards (#2659) [Tom Wallace][] + +Deprecations: + +- `useBR` option deprecated and will be removed in v11.0. (#2559) [Josh Goebel][] + +[Chris Krycho]: https://github.com/chriskrycho +[David Pine]: https://github.com/IEvangelist + + +[Ryan Jonasson]: https://github.com/ryanjonasson +[Philipp Engel]: https://github.com/interkosmos +[Konrad Rudolph]: https://github.com/klmr +[Melissa Geels]: https://github.com/codecat +[Antoine du Hamel]: https://github.com/aduh95 +[Ayesh Karunaratne]: https://github.com/Ayesh +[Tom Wallace]: https://github.com/thomasmichaelwallace +[schtandard]: https://github.com/schtandard + + +## Version 10.2.1 + + Parser Engine: + + - fix(parser) complete fix for resuming matches from same index (#2678) [Josh Goebel][] + + [Josh Goebel]: https://github.com/yyyc514 + + ## Version 10.2.0 Parser Engine: @@ -29,7 +233,7 @@ Language Improvements: - enh(php) detect newer more flexible HEREdoc syntax (#2658) [eytienne][] [Youssef Victor]: https://github.com/Youssef1313 -[Josh Goebel]: https://github.com/yyyc514 +[Josh Goebel]: https://github.com/joshgoebel [Andrew Janke]: https://github.com/apjanke [Samia Ali]: https://github.com/samiaab1990 [kageru]: https://github.com/kageru @@ -47,7 +251,7 @@ Fixes: - Resolve issue on Node 6 due to dangling comma (#2608) [Edwin Hoogerbeets][] - Resolve `index.d.ts is not a module` error (#2603) [Josh Goebel][] -[Josh Goebel]: https://github.com/yyyc514 +[Josh Goebel]: https://github.com/joshgoebel [Edwin Hoogerbeets]: https://github.com/ehoogerbeets @@ -103,7 +307,7 @@ Language Improvements: - enh(protobuf) Support multiline comments (#2597) [Pavel Evstigneev][] - fix(toml) Improve key parsing (#2595) [Antoine du Hamel][] -[Josh Goebel]: https://github.com/yyyc514 +[Josh Goebel]: https://github.com/joshgoebel [Peter Plantinga]: https://github.com/pplantinga [David Benjamin]: https://github.com/davidben [Vania Kucher]: https://github.com/qWici @@ -131,7 +335,7 @@ Parser Engine Changes: - [Issue](https://github.com/highlightjs/highlight.js/issues/2522) fix(parser) Fix freez issue with illegal 0 width matches (#2524) [Josh Goebel][] -[Josh Goebel]: https://github.com/yyyc514 +[Josh Goebel]: https://github.com/joshgoebel ## Version 10.0.1 @@ -140,7 +344,7 @@ Parser Engine Changes: - (bug) Fix sublanguage with no relevance score (#2506) [Josh Goebel][] -[Josh Goebel]: https://github.com/yyyc514 +[Josh Goebel]: https://github.com/joshgoebel ## Version 10.0.0 @@ -209,12 +413,12 @@ Developer Tools: [Omid Golparvar]: https://github.com/omidgolparvar [Alexandre Grison]: https://github.com/agrison -[Josh Goebel]: https://github.com/yyyc514 +[Josh Goebel]: https://github.com/joshgoebel [Chen Bin]: https://github.com/redguardtoo [Sam Miller]: https://github.com/smillerc [Robert Riebisch]: https://github.com/bttrx [Taufik Nurrohman]: https://github.com/taufik-nurrohman -[Josh Goebel]: https://github.com/yyyc514 +[Josh Goebel]: https://github.com/joshgoebel [Sean Williams]: https://github.com/hmmwhatsthisdo [Adnan Yaqoob]: https://github.com/adnanyaqoobvirk [Álvaro Mondéjar]: https://github.com/mondeja @@ -226,7 +430,7 @@ Grammar Improvements: - bug(coffeescript) fix freezing bug due to badly behaved regex (#2376) [Josh Goebel][] -[Josh Goebel]: https://github.com/yyyc514 +[Josh Goebel]: https://github.com/joshgoebel ## Version 9.18.0 @@ -261,7 +465,7 @@ Developer Tools: - feat(developer): add button to show parsed structure (#2345) [Nils Knappmeier][] [Jeffrey Arnold]: https://github.com/jrnold -[Josh Goebel]: https://github.com/yyyc514 +[Josh Goebel]: https://github.com/joshgoebel [Philipp Engel]: https://github.com/interkosmos [Youssef Victor]: https://github.com/Youssef1313 [Nils Knappmeier]: https://github.com/nknapp @@ -273,7 +477,7 @@ Fixes: - fix(parser): resolve IE 11 issue with Object.freeze() (#2319) [Josh Goebel][] -[Josh Goebel]: https://github.com/yyyc514 +[Josh Goebel]: https://github.com/joshgoebel ## Version 9.17.0 @@ -323,7 +527,7 @@ Language Improvements: - fix(objectivec): Handle multibyte character literals (#2268) [David Benjamin][] - enh(cpp): Add additional keywords (#2289) [Adrian Ostrowski][] -[Josh Goebel]: https://github.com/yyyc514 +[Josh Goebel]: https://github.com/joshgoebel [Liam Nobel]: https://github.com/liamnobel [Carl Baxter]: https://github.com/cdbax [Milutin Kristofic]: https://github.com/milutin @@ -1232,7 +1436,7 @@ Notable fixes and improvements to existing languages: - HTML ` + href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.4.1/styles/default.min.css"> + + src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.4.1/languages/go.min.js"> ``` **jsdelivr** ([link](https://www.jsdelivr.com/package/gh/highlightjs/cdn-release)) ```html - + href="//cdn.jsdelivr.net/gh/highlightjs/cdn-release@10.4.1/build/styles/default.min.css"> + +``` + +**unpkg** ([link](https://unpkg.com/browse/@highlightjs/cdn-assets/)) + +```html + + ``` **Note:** *The CDN-hosted `highlight.min.js` package doesn't bundle every language.* It would be -very large. You can find our list "common" languages that we bundle by default on our [download page][5]. +very large. You can find our list "common" languages that we bundle by default on our [download page][5]. ### Self Hosting diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000000..76821036ba --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,19 @@ +# Security Policy + +## Supported Versions + +Due to both time and resource constrains the Highlight.js core team only fully supports the current major/minor release of the library. Problems with minor releases are often resolved by upgrading to the most recent release. + +| Version | Supported | Status | +| :-----: | :-: | :------ | +| 10.4.1 | :white_check_mark:   :closed_lock_with_key: | The 10.x series recieves regular updates, new features & bug fixes. | +| <= 10.4.0 | :x: | Known vulnerabities. *Please upgrade to a more recent 10.x release.* | +| 9.18.5 | :x: | [EOL](https://github.com/highlightjs/highlight.js/issues/2877). No longer supported. See [VERSION_10_UPGRADE.md](https://github.com/highlightjs/highlight.js/blob/master/VERSION_10_UPGRADE.md). | +| <= 9.18.3 | :x: | No longer supported. Known vulnerabities. | +| <= 8.x | :x: | Obsolete. | + + +## Reporting a Vulnerability + +Minor vulnerabilities can simply be reported (and tracked) via our [GitHub issues](https://github.com/highlightjs/highlight.js/issues). If you feel your issue is more sensitive than that you can always reach us via email: [security@highlightjs.org](mailto:security@highlightjs.org) + diff --git a/SUPPORTED_LANGUAGES.md b/SUPPORTED_LANGUAGES.md index 0d2fd820dc..8c4661ac98 100644 --- a/SUPPORTED_LANGUAGES.md +++ b/SUPPORTED_LANGUAGES.md @@ -27,9 +27,9 @@ Languages that listed a **Package** below are 3rd party languages and are not bu | AutoHotkey | autohotkey | | | AutoIt | autoit | | | Awk | awk, mawk, nawk, gawk | | -| Axapta | axapta | | | Bash | bash, sh, zsh | | | Basic | basic | | +| BBCode | bbcode | [highlightjs-bbcode](https://github.com/RedGuy7/highlightjs-bbcode) | | BNF | bnf | | | Brainfuck | brainfuck, bf | | | C# | csharp, cs | | @@ -43,6 +43,7 @@ Languages that listed a **Package** below are 3rd party languages and are not bu | CSS | css | | | Cap’n Proto | capnproto, capnp | | | Chaos | chaos, kaos | [highlightjs-chaos](https://github.com/chaos-lang/highlightjs-chaos) | +| Chapel | chapel, chpl | [highlightjs-chapel](https://github.com/chapel-lang/highlightjs-chapel) | | Cisco CLI | cisco | [highlightjs-cisco-cli](https://github.com/BMatheas/highlightjs-cisco-cli) | | Clojure | clojure, clj | | | CoffeeScript | coffeescript, coffee, cson, iced | | @@ -96,6 +97,7 @@ Languages that listed a **Package** below are 3rd party languages and are not bu | Java | java, jsp | | | JavaScript | javascript, js, jsx | | | Jolie | jolie, iol, ol | [highlightjs-jolie](https://github.com/xiroV/highlightjs-jolie) | +| Julia | julia, julia-repl | | | Kotlin | kotlin, kt | | | LaTeX | tex | | | Leaf | leaf | | @@ -123,11 +125,11 @@ Languages that listed a **Package** below are 3rd party languages and are not bu | NSIS | nsis | | | Never | never | [highlightjs-never](https://github.com/never-lang/highlightjs-never) | | Nginx | nginx, nginxconf | | -| Nim | nimrod | | +| Nim | nim, nimrod | | | Nix | nix | | | Object Constraint Language | ocl | [highlightjs-ocl](https://github.com/nhomble/highlightjs-ocl) | | OCaml | ocaml, ml | | -| Objective C | objectivec, mm, objc, obj-c | | +| Objective C | objectivec, mm, objc, obj-c, obj-c++, objective-c++ | | | OpenGL Shading Language | glsl | | | OpenSCAD | openscad, scad | | | Oracle Rules Language | ruleslanguage | | @@ -197,6 +199,7 @@ Languages that listed a **Package** below are 3rd party languages and are not bu | Vala | vala | | | Verilog | verilog, v | | | Vim Script | vim | | +| X++ | axapta, x++ | | | x86 Assembly | x86asm | | | XL | xl, tao | | | XQuery | xquery, xpath, xq | | diff --git a/VERSION_10_BREAKING_CHANGES.md b/VERSION_10_BREAKING_CHANGES.md index f60a6c00d5..cc9ac1cce5 100644 --- a/VERSION_10_BREAKING_CHANGES.md +++ b/VERSION_10_BREAKING_CHANGES.md @@ -32,7 +32,7 @@ Removed styles: - chore(styles): darkula.css (use darcula.css instead) [Josh Goebel][] -[Josh Goebel]: https://github.com/yyyc514 +[Josh Goebel]: https://github.com/joshgoebel --- diff --git a/demo/demo.js b/demo/demo.js index bb46e7a605..cd90785bf7 100644 --- a/demo/demo.js +++ b/demo/demo.js @@ -13,11 +13,9 @@ var screenHeight = $window.height() $categoryContainer.css('max-height', screenHeight / 4); - $categoryContainer.perfectScrollbar('update'); $styleContainer.height( screenHeight - $styleContainer.position().top - 20 ); - $styleContainer.perfectScrollbar('update'); } function selectCategory(category) { @@ -83,7 +81,6 @@ }); $categories.first().click(); - $categoryContainer.perfectScrollbar(); } function selectStyle(style) { @@ -109,7 +106,6 @@ selectStyle($style.text()); }); $styles.first().click(); - $styleContainer.perfectScrollbar(); } $(function() { diff --git a/demo/index.html b/demo/index.html index 6ff356a32c..8177631787 100644 --- a/demo/index.html +++ b/demo/index.html @@ -5,7 +5,6 @@ highlight.js demo - <% _.each(styles, function(style) { %> @@ -21,12 +20,12 @@

highlight.js demo

-

Language categories

+

Languages

    -

    Styles

    +

    Themes

      @@ -47,9 +46,12 @@

      <%- language.prettyName %>

      + <% if (minify) { %> + <% } else { %> + + <% } %> - diff --git a/demo/perfect-scrollbar.min.css b/demo/perfect-scrollbar.min.css deleted file mode 100644 index fc452aff82..0000000000 --- a/demo/perfect-scrollbar.min.css +++ /dev/null @@ -1,5 +0,0 @@ -/*! perfect-scrollbar - v0.5.7 -* http://noraesae.github.com/perfect-scrollbar/ -* Copyright (c) 2014 Hyunje Alex Jun; Licensed MIT */ - -.ps-container.ps-active-x>.ps-scrollbar-x-rail,.ps-container.ps-active-y>.ps-scrollbar-y-rail{display:block}.ps-container>.ps-scrollbar-x-rail{display:none;position:absolute;-webkit-border-radius:4px;-moz-border-radius:4px;-ms-border-radius:4px;border-radius:4px;opacity:0;-ms-filter:"alpha(Opacity=0)";filter:alpha(opacity=0);-webkit-transition:background-color .2s linear,opacity .2s linear;-moz-transition:background-color .2s linear,opacity .2s linear;-o-transition:background-color .2s linear,opacity .2s linear;transition:background-color .2s linear,opacity .2s linear;bottom:3px;height:8px}.ps-container>.ps-scrollbar-x-rail>.ps-scrollbar-x{position:absolute;background-color:#aaa;-webkit-border-radius:4px;-moz-border-radius:4px;-ms-border-radius:4px;border-radius:4px;-webkit-transition:background-color .2s linear;-moz-transition:background-color .2s linear;-o-transition:background-color .2s linear;transition:background-color .2s linear;bottom:0;height:8px}.ps-container>.ps-scrollbar-x-rail.in-scrolling{background-color:#eee;opacity:.9;-ms-filter:"alpha(Opacity=90)";filter:alpha(opacity=90)}.ps-container>.ps-scrollbar-y-rail{display:none;position:absolute;-webkit-border-radius:4px;-moz-border-radius:4px;-ms-border-radius:4px;border-radius:4px;opacity:0;-ms-filter:"alpha(Opacity=0)";filter:alpha(opacity=0);-webkit-transition:background-color .2s linear,opacity .2s linear;-moz-transition:background-color .2s linear,opacity .2s linear;-o-transition:background-color .2s linear,opacity .2s linear;transition:background-color .2s linear,opacity .2s linear;right:3px;width:8px}.ps-container>.ps-scrollbar-y-rail>.ps-scrollbar-y{position:absolute;background-color:#aaa;-webkit-border-radius:4px;-moz-border-radius:4px;-ms-border-radius:4px;border-radius:4px;-webkit-transition:background-color .2s linear;-moz-transition:background-color .2s linear;-o-transition:background-color .2s linear;transition:background-color .2s linear;right:0;width:8px}.ps-container>.ps-scrollbar-y-rail.in-scrolling{background-color:#eee;opacity:.9;-ms-filter:"alpha(Opacity=90)";filter:alpha(opacity=90)}.ps-container:hover>.ps-scrollbar-x-rail,.ps-container:hover>.ps-scrollbar-y-rail{opacity:.6;-ms-filter:"alpha(Opacity=60)";filter:alpha(opacity=60)}.ps-container:hover>.ps-scrollbar-x-rail.in-scrolling,.ps-container:hover>.ps-scrollbar-y-rail.in-scrolling{background-color:#eee;opacity:.9;-ms-filter:"alpha(Opacity=90)";filter:alpha(opacity=90)}.ps-container:hover>.ps-scrollbar-x-rail:hover{background-color:#eee;opacity:.9;-ms-filter:"alpha(Opacity=90)";filter:alpha(opacity=90)}.ps-container:hover>.ps-scrollbar-x-rail:hover>.ps-scrollbar-x{background-color:#999}.ps-container:hover>.ps-scrollbar-y-rail:hover{background-color:#eee;opacity:.9;-ms-filter:"alpha(Opacity=90)";filter:alpha(opacity=90)}.ps-container:hover>.ps-scrollbar-y-rail:hover>.ps-scrollbar-y{background-color:#999} \ No newline at end of file diff --git a/demo/perfect-scrollbar.min.js b/demo/perfect-scrollbar.min.js deleted file mode 100644 index ff3f5ac9c8..0000000000 --- a/demo/perfect-scrollbar.min.js +++ /dev/null @@ -1,4 +0,0 @@ -/*! perfect-scrollbar - v0.5.7 -* http://noraesae.github.com/perfect-scrollbar/ -* Copyright (c) 2014 Hyunje Alex Jun; Licensed MIT */ -(function(e){"use strict";"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof exports?e(require("jquery")):e(jQuery)})(function(e){"use strict";function t(e){return"string"==typeof e?parseInt(e,10):~~e}var o={wheelSpeed:1,wheelPropagation:!1,minScrollbarLength:null,maxScrollbarLength:null,useBothWheelAxes:!1,useKeyboard:!0,suppressScrollX:!1,suppressScrollY:!1,scrollXMarginOffset:0,scrollYMarginOffset:0,includePadding:!1},n=0,r=function(){var e=n++;return function(t){var o=".perfect-scrollbar-"+e;return t===void 0?o:t+o}};e.fn.perfectScrollbar=function(n,l){return this.each(function(){function i(e,o){var n=e+o,r=E-W;I=0>n?0:n>r?r:n;var l=t(I*(D-E)/(E-W));S.scrollTop(l)}function a(e,o){var n=e+o,r=x-Y;X=0>n?0:n>r?r:n;var l=t(X*(M-x)/(x-Y));S.scrollLeft(l)}function c(e){return L.minScrollbarLength&&(e=Math.max(e,L.minScrollbarLength)),L.maxScrollbarLength&&(e=Math.min(e,L.maxScrollbarLength)),e}function s(){var e={width:x};e.left=O?S.scrollLeft()+x-M:S.scrollLeft(),B?e.bottom=q-S.scrollTop():e.top=H+S.scrollTop(),A.css(e);var t={top:S.scrollTop(),height:E};z?t.right=O?M-S.scrollLeft()-Q-N.outerWidth():Q-S.scrollLeft():t.left=O?S.scrollLeft()+2*x-M-F-N.outerWidth():F+S.scrollLeft(),_.css(t),K.css({left:X,width:Y-U}),N.css({top:I,height:W-G})}function d(){S.removeClass("ps-active-x"),S.removeClass("ps-active-y"),x=L.includePadding?S.innerWidth():S.width(),E=L.includePadding?S.innerHeight():S.height(),M=S.prop("scrollWidth"),D=S.prop("scrollHeight"),!L.suppressScrollX&&M>x+L.scrollXMarginOffset?(C=!0,Y=c(t(x*x/M)),X=t(S.scrollLeft()*(x-Y)/(M-x))):(C=!1,Y=0,X=0,S.scrollLeft(0)),!L.suppressScrollY&&D>E+L.scrollYMarginOffset?(k=!0,W=c(t(E*E/D)),I=t(S.scrollTop()*(E-W)/(D-E))):(k=!1,W=0,I=0,S.scrollTop(0)),X>=x-Y&&(X=x-Y),I>=E-W&&(I=E-W),s(),C&&S.addClass("ps-active-x"),k&&S.addClass("ps-active-y")}function u(){var t,o,n=!1;K.bind(j("mousedown"),function(e){o=e.pageX,t=K.position().left,A.addClass("in-scrolling"),n=!0,e.stopPropagation(),e.preventDefault()}),e(R).bind(j("mousemove"),function(e){n&&(a(t,e.pageX-o),d(),e.stopPropagation(),e.preventDefault())}),e(R).bind(j("mouseup"),function(){n&&(n=!1,A.removeClass("in-scrolling"))}),t=o=null}function p(){var t,o,n=!1;N.bind(j("mousedown"),function(e){o=e.pageY,t=N.position().top,n=!0,_.addClass("in-scrolling"),e.stopPropagation(),e.preventDefault()}),e(R).bind(j("mousemove"),function(e){n&&(i(t,e.pageY-o),d(),e.stopPropagation(),e.preventDefault())}),e(R).bind(j("mouseup"),function(){n&&(n=!1,_.removeClass("in-scrolling"))}),t=o=null}function f(e,t){var o=S.scrollTop();if(0===e){if(!k)return!1;if(0===o&&t>0||o>=D-E&&0>t)return!L.wheelPropagation}var n=S.scrollLeft();if(0===t){if(!C)return!1;if(0===n&&0>e||n>=M-x&&e>0)return!L.wheelPropagation}return!0}function v(){function e(e){var t=e.originalEvent.deltaX,o=-1*e.originalEvent.deltaY;return(t===void 0||o===void 0)&&(t=-1*e.originalEvent.wheelDeltaX/6,o=e.originalEvent.wheelDeltaY/6),e.originalEvent.deltaMode&&1===e.originalEvent.deltaMode&&(t*=10,o*=10),t!==t&&o!==o&&(t=0,o=e.originalEvent.wheelDelta),[t,o]}function t(t){var n=e(t),r=n[0],l=n[1];o=!1,L.useBothWheelAxes?k&&!C?(l?S.scrollTop(S.scrollTop()-l*L.wheelSpeed):S.scrollTop(S.scrollTop()+r*L.wheelSpeed),o=!0):C&&!k&&(r?S.scrollLeft(S.scrollLeft()+r*L.wheelSpeed):S.scrollLeft(S.scrollLeft()-l*L.wheelSpeed),o=!0):(S.scrollTop(S.scrollTop()-l*L.wheelSpeed),S.scrollLeft(S.scrollLeft()+r*L.wheelSpeed)),d(),o=o||f(r,l),o&&(t.stopPropagation(),t.preventDefault())}var o=!1;window.onwheel!==void 0?S.bind(j("wheel"),t):window.onmousewheel!==void 0&&S.bind(j("mousewheel"),t)}function g(){var t=!1;S.bind(j("mouseenter"),function(){t=!0}),S.bind(j("mouseleave"),function(){t=!1});var o=!1;e(R).bind(j("keydown"),function(n){if((!n.isDefaultPrevented||!n.isDefaultPrevented())&&t){for(var r=document.activeElement?document.activeElement:R.activeElement;r.shadowRoot;)r=r.shadowRoot.activeElement;if(!e(r).is(":input,[contenteditable]")){var l=0,i=0;switch(n.which){case 37:l=-30;break;case 38:i=30;break;case 39:l=30;break;case 40:i=-30;break;case 33:i=90;break;case 32:case 34:i=-90;break;case 35:i=n.ctrlKey?-D:-E;break;case 36:i=n.ctrlKey?S.scrollTop():E;break;default:return}S.scrollTop(S.scrollTop()-i),S.scrollLeft(S.scrollLeft()+l),o=f(l,i),o&&n.preventDefault()}}})}function b(){function e(e){e.stopPropagation()}N.bind(j("click"),e),_.bind(j("click"),function(e){var o=t(W/2),n=e.pageY-_.offset().top-o,r=E-W,l=n/r;0>l?l=0:l>1&&(l=1),S.scrollTop((D-E)*l)}),K.bind(j("click"),e),A.bind(j("click"),function(e){var o=t(Y/2),n=e.pageX-A.offset().left-o,r=x-Y,l=n/r;0>l?l=0:l>1&&(l=1),S.scrollLeft((M-x)*l)})}function h(){function t(){var e=window.getSelection?window.getSelection():document.getSlection?document.getSlection():{rangeCount:0};return 0===e.rangeCount?null:e.getRangeAt(0).commonAncestorContainer}function o(){r||(r=setInterval(function(){return P()?(S.scrollTop(S.scrollTop()+l.top),S.scrollLeft(S.scrollLeft()+l.left),d(),void 0):(clearInterval(r),void 0)},50))}function n(){r&&(clearInterval(r),r=null),A.removeClass("in-scrolling"),_.removeClass("in-scrolling")}var r=null,l={top:0,left:0},i=!1;e(R).bind(j("selectionchange"),function(){e.contains(S[0],t())?i=!0:(i=!1,n())}),e(window).bind(j("mouseup"),function(){i&&(i=!1,n())}),e(window).bind(j("mousemove"),function(e){if(i){var t={x:e.pageX,y:e.pageY},r=S.offset(),a={left:r.left,right:r.left+S.outerWidth(),top:r.top,bottom:r.top+S.outerHeight()};t.xa.right-3?(l.left=5,A.addClass("in-scrolling")):l.left=0,t.ya.top+3-t.y?-5:-20,_.addClass("in-scrolling")):t.y>a.bottom-3?(l.top=5>t.y-a.bottom+3?5:20,_.addClass("in-scrolling")):l.top=0,0===l.top&&0===l.left?n():o()}})}function w(t,o){function n(e,t){S.scrollTop(S.scrollTop()-t),S.scrollLeft(S.scrollLeft()-e),d()}function r(){b=!0}function l(){b=!1}function i(e){return e.originalEvent.targetTouches?e.originalEvent.targetTouches[0]:e.originalEvent}function a(e){var t=e.originalEvent;return t.targetTouches&&1===t.targetTouches.length?!0:t.pointerType&&"mouse"!==t.pointerType&&t.pointerType!==t.MSPOINTER_TYPE_MOUSE?!0:!1}function c(e){if(a(e)){h=!0;var t=i(e);p.pageX=t.pageX,p.pageY=t.pageY,f=(new Date).getTime(),null!==g&&clearInterval(g),e.stopPropagation()}}function s(e){if(!b&&h&&a(e)){var t=i(e),o={pageX:t.pageX,pageY:t.pageY},r=o.pageX-p.pageX,l=o.pageY-p.pageY;n(r,l),p=o;var c=(new Date).getTime(),s=c-f;s>0&&(v.x=r/s,v.y=l/s,f=c),e.stopPropagation(),e.preventDefault()}}function u(){!b&&h&&(h=!1,clearInterval(g),g=setInterval(function(){return P()?.01>Math.abs(v.x)&&.01>Math.abs(v.y)?(clearInterval(g),void 0):(n(30*v.x,30*v.y),v.x*=.8,v.y*=.8,void 0):(clearInterval(g),void 0)},10))}var p={},f=0,v={},g=null,b=!1,h=!1;t&&(e(window).bind(j("touchstart"),r),e(window).bind(j("touchend"),l),S.bind(j("touchstart"),c),S.bind(j("touchmove"),s),S.bind(j("touchend"),u)),o&&(window.PointerEvent?(e(window).bind(j("pointerdown"),r),e(window).bind(j("pointerup"),l),S.bind(j("pointerdown"),c),S.bind(j("pointermove"),s),S.bind(j("pointerup"),u)):window.MSPointerEvent&&(e(window).bind(j("MSPointerDown"),r),e(window).bind(j("MSPointerUp"),l),S.bind(j("MSPointerDown"),c),S.bind(j("MSPointerMove"),s),S.bind(j("MSPointerUp"),u)))}function m(){S.bind(j("scroll"),function(){d()})}function T(){S.unbind(j()),e(window).unbind(j()),e(R).unbind(j()),S.data("perfect-scrollbar",null),S.data("perfect-scrollbar-update",null),S.data("perfect-scrollbar-destroy",null),K.remove(),N.remove(),A.remove(),_.remove(),S=A=_=K=N=C=k=x=E=M=D=Y=X=q=B=H=W=I=Q=z=F=O=j=null}function y(){d(),m(),u(),p(),b(),h(),v(),(J||V)&&w(J,V),L.useKeyboard&&g(),S.data("perfect-scrollbar",S),S.data("perfect-scrollbar-update",d),S.data("perfect-scrollbar-destroy",T)}var L=e.extend(!0,{},o),S=e(this),P=function(){return!!S};if("object"==typeof n?e.extend(!0,L,n):l=n,"update"===l)return S.data("perfect-scrollbar-update")&&S.data("perfect-scrollbar-update")(),S;if("destroy"===l)return S.data("perfect-scrollbar-destroy")&&S.data("perfect-scrollbar-destroy")(),S;if(S.data("perfect-scrollbar"))return S.data("perfect-scrollbar");S.addClass("ps-container");var x,E,M,D,C,Y,X,k,W,I,O="rtl"===S.css("direction"),j=r(),R=this.ownerDocument||document,A=e("
      ").appendTo(S),K=e("
      ").appendTo(A),q=t(A.css("bottom")),B=q===q,H=B?null:t(A.css("top")),U=t(A.css("borderLeftWidth"))+t(A.css("borderRightWidth")),_=e("
      ").appendTo(S),N=e("
      ").appendTo(_),Q=t(_.css("right")),z=Q===Q,F=z?null:t(_.css("left")),G=t(_.css("borderTopWidth"))+t(_.css("borderBottomWidth")),J="ontouchstart"in window||window.DocumentTouch&&document instanceof window.DocumentTouch,V=null!==window.navigator.msMaxTouchPoints;return y(),S})}}); \ No newline at end of file diff --git a/demo/style.css b/demo/style.css index 6fa82319b8..103be0c89f 100644 --- a/demo/style.css +++ b/demo/style.css @@ -1,33 +1,51 @@ +@import url(https://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic); + /* Base styles */ body { - color: #F0F0F0; + color: #f0f0f0; background: #500; - font-family: Arial, sans; - margin: 0; padding: 0; + font-family: PT Sans, DejaVu Sans, Arial, sans; + margin: 0; + padding: 0; } a { - color: white; + color: #f0f0f0; } h1 { - font: bold 150% Arial, sans-serif; - margin: 0; padding: 1em 0; + font-size: 150%; + margin: 0; + padding: 1em 0 0.5em; } h2 { - font: bold 120% Arial, sans-serif; + font-size: 120%; margin: 1.5em 0 0.5em 0; } pre { margin: 0; - font-size: medium; +} + +code { + font-family: Consolas, Monaco, monospace; + font-size: 10pt; + scrollbar-width: thin; +} + +body pre code.hljs { + padding-left: 1.5em; + /* compatible with school-book */ + padding-top:15px; } #sidebar { - float: left; width: 16em; height: 1000em; position: fixed; - padding: 1px 1em; + float: left; + width: 16em; + height: 1000em; + position: fixed; + padding: 0 1em; background: #600; box-shadow: 0 0 15px black; } @@ -35,12 +53,38 @@ pre { #sidebar ul, #sidebar li { list-style: none; - margin: 0; padding: 0; + margin: 0; + padding: 0; } #sidebar ul { position: relative; - overflow-y: hidden; + overflow-y: auto; + scrollbar-width: thin; +} + +#sidebar ul::-webkit-scrollbar { + width: 8px; +} + +#sidebar ul::-webkit-scrollbar-track { + background: #4d0607; + border-radius: 5px; +} + +#sidebar ul::-webkit-scrollbar-thumb { + background: #926868; + border-right: 1px solid #4d0607; + border-left: 1px solid #4d0607; + border-radius: 5px; +} + +#sidebar ul::-webkit-scrollbar-thumb:hover { + background: #7f5555; +} + +#sidebar ul::-webkit-scrollbar-thumb:active { + background: #5d3333; } #sidebar li { @@ -53,12 +97,15 @@ pre { } #sidebar li.current:before { - content: '▶'; font-size: smaller; - position: absolute; left: 0; + content: "▶"; + font-size: smaller; + position: absolute; + left: 0; } #content { - margin-left: 19em; + margin-left: 18em; + min-width: 36em; } #languages { diff --git a/docs/api.rst b/docs/api.rst index 8b5ee44540..877f2c0bda 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -45,8 +45,10 @@ Returns an object with the following properties: * ``second_best``: object with the same structure for second-best heuristically detected language (may be absent) -``fixMarkup(value)`` --------------------- +``fixMarkup(value)`` (deprecated as of 10.3) +-------------------------------------------- + +**fixMarkup is deprecated and will be removed entirely in v11.** Post-processing of the highlighted markup. Currently consists of replacing indentation TAB characters and using ``
      `` tags instead of new-line characters. Options are set globally with ``configure``. @@ -59,7 +61,7 @@ Accepts a string with the highlighted markup. Applies highlighting to a DOM node containing code. This function is the one to use to apply highlighting dynamically after page load -or within initialization code of third-party Javascript frameworks. +or within initialization code of third-party JavaScript frameworks. The function uses language detection by default but you can specify the language in the ``class`` attribute of the DOM node. See the :doc:`class reference @@ -138,8 +140,13 @@ Looks up a language by name or alias. Returns the language object if found, ``undefined`` otherwise. -``requireLanguage(name)`` -------------------------- +``requireLanguage(name)`` (deprecated as of 10.4) +------------------------------------------------- + +**This has been deprecated and will be removed in a future release.** If you +need this type of functionality use ``getLanguage`` with your own error +handling. It is highly recommended that all inter-dependencies between grammars +be handled at built-time, not run-time. This is what the core library now does. Looks up a language by name or alias. diff --git a/docs/building-testing.rst b/docs/building-testing.rst index 72c91ca022..09bbc34235 100644 --- a/docs/building-testing.rst +++ b/docs/building-testing.rst @@ -71,8 +71,8 @@ detection still works with your language definition included in the whole suite. Testing is done using `Mocha `_ and the files are found in the ``test/`` directory. You can use the node build to -run the tests in the command line with ``npm test`` after installing the -dependencies with ``npm install``. +run the tests from the command line with ``npm test`` after building_. (Using +``npm run build_and_test`` you can build and then test with one command.) **Note**: for Debian-based machine, like Ubuntu, you might need to create an alias or symbolic link for nodejs to node. The reason for this is the diff --git a/docs/conf.py b/docs/conf.py index 71554e24c0..76c0dc9f46 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -46,11 +46,11 @@ # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. -# -# The short X.Y version. -version = '10.2' + # The full version, including alpha/beta/rc tags. -release = '10.2.0' +release = '10.4.1' +# The short X.Y version. +version = ".".join(release.split(".")[:2]) # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/css-classes-reference.rst b/docs/css-classes-reference.rst index aa4d45321d..f44c8ceff4 100644 --- a/docs/css-classes-reference.rst +++ b/docs/css-classes-reference.rst @@ -5,22 +5,40 @@ CSS classes reference Stylable classes ---------------- +The general purpose classes are intended to be used for any language, but the +other classes may also be used when they are semantically correct. For example +if you had a general purpose language that allowed inline URLs: + +:: + + var GOOGLE = https://www.google.com/ + + +It would be wholly reasonable to use the ``link`` class for this, even though +your language is not considered a "Markup" language. + +------------------------------------------------------------------------------+ -| **General-purpose** | +| **General purpose** | +--------------------------+---------------------------------------------------+ | keyword | keyword in a regular Algol-style language | +--------------------------+---------------------------------------------------+ | built_in | built-in or library object (constant, class, | | | function) | +--------------------------+---------------------------------------------------+ -| type | user-defined type in a language with first-class | -| | syntactically significant types, like Haskell | +| type | data type (in a language with syntactically | +| | significant types) (``string``, ``int``, | +| | ``array``, etc.) | +--------------------------+---------------------------------------------------+ -| literal | special identifier for a built-in value ("true", | -| | "false", "null") | +| literal | special identifier for a built-in value | +| | (``true``, ``false``, ``null``, etc.) | +--------------------------+---------------------------------------------------+ | number | number, including units and modifiers, if any. | +--------------------------+---------------------------------------------------+ +| operator | operators: ``+``, ``-``, ``>>``, ``|``, ``==`` | ++--------------------------+---------------------------------------------------+ +| punctuation | aux. punctuation that should be subtly highlighted| +| | (parentheses, brackets, etc.) | ++--------------------------+---------------------------------------------------+ | regexp | literal regular expression | +--------------------------+---------------------------------------------------+ | string | literal string, character | @@ -30,24 +48,27 @@ Stylable classes | symbol | symbolic constant, interned string, goto label | +--------------------------+---------------------------------------------------+ | class | class or class-level declaration (interfaces, | -| | traits, modules, etc) | +| | traits, modules, etc), typically includes a | +| | ``title`` submode | +--------------------------+---------------------------------------------------+ | function | function or method declaration | +--------------------------+---------------------------------------------------+ +| variable | variables | ++--------------------------+---------------------------------------------------+ | title | name of a class or a function at the place of | | | declaration | +--------------------------+---------------------------------------------------+ | params | block of function arguments (parameters) at the | | | place of declaration | +--------------------------+---------------------------------------------------+ -| **Meta** | -+--------------------------+---------------------------------------------------+ -| comment | comment | +| comment | comments | +--------------------------+---------------------------------------------------+ | doctag | documentation markup within comments | +--------------------------+---------------------------------------------------+ +| **Meta** | ++--------------------------+---------------------------------------------------+ | meta | flags, modifiers, annotations, processing | -| | instructions, preprocessor directive, etc | +| | instructions, preprocessor directives, etc | +--------------------------+---------------------------------------------------+ | meta-keyword | keyword or built-in within meta construct | +--------------------------+---------------------------------------------------+ @@ -74,36 +95,33 @@ Stylable classes | attribute | name of an attribute followed by a structured | | | value part, like CSS properties | +--------------------------+---------------------------------------------------+ -| variable | variable in a config or a template file, | -| | environment var expansion in a script | -+--------------------------+---------------------------------------------------+ -| **Markup** | +| **Text Markup** | +--------------------------+---------------------------------------------------+ -| bullet | list item bullet in text markup | +| bullet | list item bullet | +--------------------------+---------------------------------------------------+ -| code | code block in text markup | +| code | code block | +--------------------------+---------------------------------------------------+ -| emphasis | emphasis in text markup | +| emphasis | emphasis | +--------------------------+---------------------------------------------------+ -| strong | strong emphasis in text markup | +| strong | strong emphasis | +--------------------------+---------------------------------------------------+ -| formula | mathematical formula in text markup | +| formula | mathematical formula | +--------------------------+---------------------------------------------------+ -| link | hyperlink in text markup | +| link | hyperlink | +--------------------------+---------------------------------------------------+ -| quote | quotation in text markup | +| quote | quotation or blockquote | +--------------------------+---------------------------------------------------+ | **CSS** | +--------------------------+---------------------------------------------------+ -| selector-tag | tag selector in CSS | +| selector-tag | tag selector | +--------------------------+---------------------------------------------------+ -| selector-id | #id selector in CSS | +| selector-id | #id selector | +--------------------------+---------------------------------------------------+ -| selector-class | .class selector in CSS | +| selector-class | .class selector | +--------------------------+---------------------------------------------------+ -| selector-attr | [attr] selector in CSS | +| selector-attr | [attr] selector | +--------------------------+---------------------------------------------------+ -| selector-pseudo | :pseudo selector in CSS | +| selector-pseudo | :pseudo selector | +--------------------------+---------------------------------------------------+ | **Templates** | +--------------------------+---------------------------------------------------+ @@ -113,23 +131,49 @@ Stylable classes +--------------------------+---------------------------------------------------+ | **diff** | +--------------------------+---------------------------------------------------+ -| addition | added or changed line in a diff | +| addition | added or changed line | +--------------------------+---------------------------------------------------+ -| deletion | deleted line in a diff | +| deletion | deleted line | +--------------------------+---------------------------------------------------+ -| **ReasonML** | + +A note on newer classes +^^^^^^^^^^^^^^^^^^^^^^^ + +Some classes have been added more recently and do not enjoy universal theme +support. For themes without support, these items will simply not be +highlighted. This doesn't mean not to use them, only that they will be +highlighted better as support improves over time. + +A list of these classes: + +- operator +- punctuation + + +Reserved classes +^^^^^^^^^^^^^^^^ + +The below classes (ReasonML) are left here for documentation purposes but may +not be used in other grammars because they are very poorly supported by all +themes. + +If you'd like to help out with the larger issue here: + +- https://github.com/highlightjs/highlight.js/issues/2521 +- https://github.com/highlightjs/highlight.js/issues/2500 + +--------------------------+---------------------------------------------------+ -| operator | reasonml operator such as pipe | +| **ReasonML** | +--------------------------+---------------------------------------------------+ -| pattern-match | reasonml pattern matching matchers | +| pattern-match | pattern matching matchers | +--------------------------+---------------------------------------------------+ | typing | type signatures on function parameters | +--------------------------+---------------------------------------------------+ | constructor | type constructors | +--------------------------+---------------------------------------------------+ -| module-access | scope access into a ReasonML module | +| module-access | scope access into a module | +--------------------------+---------------------------------------------------+ -| module | ReasonML module reference within scope access | +| module | module reference within scope access | +--------------------------+---------------------------------------------------+ diff --git a/docs/language-contribution.rst b/docs/language-contribution.rst index f492becb4e..1e2de0a9f5 100644 --- a/docs/language-contribution.rst +++ b/docs/language-contribution.rst @@ -1,13 +1,37 @@ Language contributor checklist ============================== -1. Read ``extra/3RD_PARTY_QUICK_START.md`` ------------------------------------------- +1. Know that you are creating a 3rd party grammar +------------------------------------------------- -It contains rough high-level steps for creating a 3rd party language grammar for Highlight.js. +*Sadly, due to lack of maintainer time we no longer merge new languages grammars +into the core library.* Instead, the project works by encouraging 3rd party +language grammar development by willing contributors ready to help and maintain +them. We're also happy to host those 3rd party language grammars at the +``highlightjs`` GitHub organization. Or you're welcome to host yourself - we're +always happy to link to to new language grammars. +We also make it easy to build, maintain, and distribute 3rd party grammar +modules so that Highlight.js can always be easily extended with new languages. +Using a 3rd party language (for end users) is often as simple as just adding a +single line of code to their JavaScript or build system. -2. Create a language grammar definition file +We'd love to have your grammar as a 3rd party language module if you'd be +willing to maintain it over time. It's easy to develop and publish a 3rd party +language module. If you already started work in the main source tree - it's +trivial to convert your existing work into a 3rd party module. (you pretty much +just move your files into a new project folder) + + +2. Read extra/3RD_PARTY_QUICK_START.md +-------------------------------------- + +Next, read ``extra/3RD_PARTY_QUICK_START.md``. This should provide you with a +very high-level overview of the steps for creating a third-party language +grammar for Highlight.js. + + +3. Create a language grammar definition file -------------------------------------------- The file defines a function accepting a reference to the library and returning a language object. @@ -25,10 +49,12 @@ process and details differ for different build targets. } } -The name of the file is used as a short language identifier and should be usable as a class name in HTML and CSS. +The name of the file is used as a short language identifier and should be usable +as a class name in HTML and CSS. Typically you'll place this file in your +new grammar repository under ``my_new_grammar/src/languages/``. -3. Add language metadata +4. Add language metadata ---------------------------- At the top of the file there is a specially formatted comment with meta data processed by a build system. @@ -56,7 +82,7 @@ The build system just makes sure that they will be in the final package in The meaning of the other headers should be pretty obvious. -4. Create a code example +5. Create a code example ------------------------ The code example is used both to test language detection and for the demo page @@ -66,7 +92,7 @@ Take inspiration from other languages in ``test/detect/`` and read :ref:`testing instructions ` for more details. -5. Write a class reference if your class uses custom classes +6. Write a class reference if your class uses custom classes ------------------------------------------------------------ A class reference document should typically be placed at the root of your @@ -79,14 +105,14 @@ are not going to support your custom classes and you should likely also distribute your own custom theme. -6. Request a repository at the ``highlightjs`` organization +7. Request a repository at the ``highlightjs`` organization ---------------------------------------------------------- *This is optional.* Of course you are free to host your repository anywhere you would like. -7. Create a pull request +8. Create a pull request ------------------------ Submit a PR to add your language to `SUPPORTED_LANGUAGES.md`. diff --git a/docs/language-guide.rst b/docs/language-guide.rst index 71aa2754ac..ae8e3c51d3 100644 --- a/docs/language-guide.rst +++ b/docs/language-guide.rst @@ -5,10 +5,10 @@ Highlighting overview --------------------- Programming language code consists of parts with different rules of parsing: keywords like ``for`` or ``if`` -don't make sense inside strings, strings may contain backslash-escaped symbols like ``\"`` +don't make sense inside strings, strings may contain backslash-escaped symbols like ``\"``, and comments usually don't contain anything interesting except the end of the comment. -In highlight.js such parts are called "modes". +In Highlight.js such parts are called "modes". Each mode consists of: @@ -19,7 +19,7 @@ Each mode consists of: * …exotic stuff like another language inside a language The parser's work is to look for modes and their keywords. -Upon finding, it wraps them into the markup ``...`` +Upon finding them, it wraps them into the markup ``...`` and puts the name of the mode ("string", "comment", "number") or a keyword group name ("keyword", "literal", "built-in") as the span's class name. @@ -75,8 +75,8 @@ In the simple case language keywords can be defined with a string, separated by Some languages have different kinds of "keywords" that might not be called as such by the language spec but are very close to them from the point of view of a syntax highlighter. These are all sorts of "literals", "built-ins", "symbols" -and such. To define such keyword groups the attribute ``keywords`` becomes an -object each property of which defines its own group of keywords: +and such. To define such keyword groups, the attribute ``keywords`` becomes an +object, each property of which defines its own group of keywords: :: @@ -87,11 +87,11 @@ object each property of which defines its own group of keywords: } } -The group name becomes the class name in the generated markup enabling different -themeing for different kinds of keywords. +The group name becomes the class name in the generated markup, enabling different +theming for different kinds of keywords. -To detect keywords highlight.js breaks the processed chunk of code into separate -words — a process called lexing. By default "words" are matched with the regexp +To detect keywords, highlight.js breaks the processed chunk of code into separate +words — a process called lexing. By default, "words" are matched with the regexp ``\w+``, and that works well for many languages. Different lexing rules can be defined by the magic ``$pattern`` attribute: @@ -130,7 +130,7 @@ This is commonly used to define nested modes: { className: 'object', - begin: '{', end: '}', + begin: /\{/, end: /\}/, contains: [hljs.QUOTE_STRING_MODE, 'self'] } @@ -188,7 +188,7 @@ A classic example is an escaping sequence inside strings allowing them to contai contains: [{begin: '\\\\.'}], } -For such modes ``className`` attribute should be omitted so they won't generate excessive markup. +For such modes, the ``className`` attribute should be omitted so they won't generate excessive markup. Mode attributes @@ -230,7 +230,12 @@ and it makes sense to bring their relevance to zero to lessen statistical noise: relevance: 0 } -The default value for relevance is 1. When setting an explicit value it's recommended to use either 10 or 0. +The default value for relevance is always 1. When setting an explicit value +typically either 10 or 0 is used. A 0 means this match should not be considered +for language detection purposes. 0 should be used for very common matches that +might be found in ANY language (basic numbers, strings, etc) or things that +would otherwise create too many false positives. A 10 means "this is almost +guaranteed to be XYZ code". 10 should be used sparingly. Keywords also influence relevance. Each of them usually has a relevance of 1, but there are some unique names that aren't likely to be found outside of their languages, even in the form of variable names. @@ -248,10 +253,10 @@ Illegal symbols --------------- Another way to improve language detection is to define illegal symbols for a mode. -For example in Python first line of class definition (``class MyClass(object):``) cannot contain symbol "{" or a newline. -Presence of these symbols clearly shows that the language is not Python and the parser can drop this attempt early. +For example, in Python the first line of a class definition (``class MyClass(object):``) cannot contain the symbol ``{`` or a newline. +The presence of these symbols clearly shows that the language is not Python, and the parser can drop this attempt early. -Illegal symbols are defined as a a single regular expression: +Illegal symbols are defined using a single regular expression: :: @@ -264,14 +269,13 @@ Illegal symbols are defined as a a single regular expression: Pre-defined modes and regular expressions ----------------------------------------- -Many languages share common modes and regular expressions. Such expressions are defined in core highlight.js code -at the end under "Common regexps" and "Common modes" titles. Use them when possible. +Many languages share common modes and regular expressions. These expressions are defined in `lib/modes.js `_ and should be used whenever possible. Regular Expression Features --------------------------- -The goal of Highlight.js is to support whatever regex features Javascript itself supports. You're using real regular expressions, use them responsibly. That said, due to the design of the parser, there are some caveats. These are addressed below. +The goal of Highlight.js is to support whatever regex features JavaScript itself supports. You're using real regular expressions, use them responsibly. That said, due to the design of the parser, there are some caveats. These are addressed below. Things we support now that we did not always: diff --git a/docs/language-requests.rst b/docs/language-requests.rst index 07b8d8c98e..b00df95a01 100644 --- a/docs/language-requests.rst +++ b/docs/language-requests.rst @@ -2,7 +2,7 @@ On requesting new languages =========================== This is a general answer to requests for adding new languages that appear from -time to time in the highlight.js issue tracker and discussion group. +time to time in the Highlight.js issue tracker and discussion group. Highlight.js does not have a fundamental plan for implementing new languages - i.e., the core team doesn't usually develop new languages. The core team diff --git a/docs/line-numbers.rst b/docs/line-numbers.rst index 674542d4ed..07b2f32db6 100644 --- a/docs/line-numbers.rst +++ b/docs/line-numbers.rst @@ -5,7 +5,7 @@ Highlight.js' notable lack of line numbers support is not an oversight but a feature. Following is the explanation of this policy from the current project maintainer (hey guys!): - One of the defining design principles for highlight.js from the start was + One of the defining design principles for Highlight.js from the start was simplicity. Not the simplicity of code (in fact, it's quite complex) but the simplicity of usage and of the actual look of highlighted snippets on HTML pages. Many highlighters, in my opinion, are overdoing it with such @@ -15,7 +15,7 @@ maintainer (hey guys!): reader from understanding it. This is why it's not a straightforward decision: this new feature will not - just make highlight.js better, it might actually make it worse simply by + just make Highlight.js better, it might actually make it worse simply by making it look more bloated in blog posts around the Internet. This is why I'm asking people to show that it's worth it. @@ -28,9 +28,9 @@ maintainer (hey guys!): are better is to set up some usability research on the subject. I doubt anyone would bother to do it. - Then there's maintenance. So far the core code of highlight.js is + Then there's maintenance. So far the core code of Highlight.js is maintained by only one person — yours truly. Inclusion of any new code in - highlight.js means that from that moment I will have to fix bugs in it, + Highlight.js means that from that moment I will have to fix bugs in it, improve it further, make it work together with the rest of the code, defend its design. And I don't want to do all this for the feature that I consider "evil" and probably will never use myself. diff --git a/docs/maintainers-guide.rst b/docs/maintainers-guide.rst index 0ac3719e84..8b16073a77 100644 --- a/docs/maintainers-guide.rst +++ b/docs/maintainers-guide.rst @@ -16,26 +16,30 @@ Release process Releases (minor) typically happen on a 6-week schedule. -For major/minor releases you'll be releasing from ``master``. For patch releases you'll be releasing from a stable branch, such as ``9-16-stable``. This allows ongoing development of new features to continue in isolation (in master) without those changes leaking into patch releases (which should focus only on fixing breaking changes). +For major/minor releases you'll be releasing from ``master``. For patch releases you'll be releasing from a stable branch, such as ``10-stable``. This allows ongoing development of new features to continue in isolation (in master) without those changes leaking into patch releases (which should focus only on fixing breaking changes). The goal being that minor version series always get more stable over time and that patch releases do not add features. -* For patch releases: First switch to the associated stable branch (i.e., ``9-16-stable``) +* For patch releases: First switch to the associated stable branch (i.e., ``10-stable``) * Update CHANGES.md with everything interesting since the last update. * Update version numbers using the three-part x.y.z notation everywhere: * The header in CHANGES.md (this is where the site looks for the latest version number) - * ``"version"`` attribute in package.json - * ``"version"`` attribute in package-lock.json (run `npm install`) - * Two places in docs/conf.py (``version`` and ``release``) + * ``version`` attribute in package.json + * ``version`` attribute in package-lock.json (run `npm install`) + * ``release`` variable in docs/conf.py + * All mentions of version number in the README + * Update ``SECURITY.md`` version table -* Commit the version changes and tag the commit with the version number (``9.16.2``, no "v" prefix or anything like that) +* Commit the version changes and tag the commit with the version number (``10.4.0``, no "v" prefix or anything like that) -* For major/minor releases: Create a new ``[major]-[minor]-stable`` branch such as ``9-16-stable`` +* For major/minor releases: Create (or push push) the ``[major]-stable`` branch such as ``10-stable`` -* Push the commit and the tags (``git push && git push --tags``) +IE, the ``10-stable`` branch should always point to the latest stable release in the 10 series. + +* Push the commit the tag (``git push && git push 10.4.0``) Pushing the tag triggers the update process which can be monitored at http://highlightjs.org/api/release/ diff --git a/docs/mode-reference.rst b/docs/mode-reference.rst index afec714bb0..4c058a5e63 100644 --- a/docs/mode-reference.rst +++ b/docs/mode-reference.rst @@ -1,4 +1,4 @@ -Mode reference +Mode Reference ============== Types @@ -7,29 +7,40 @@ Types Types of attributes values in this reference: +------------+-------------------------------------------------------------------------------------+ -| identifier | String suitable to be used as a Javascript variable and CSS class name | +| identifier | String suitable to be used as a JavaScript variable and CSS class name | | | (i.e. mostly ``/[A-Za-z0-9_]+/``) | +------------+-------------------------------------------------------------------------------------+ -| regexp | String representing a Javascript regexp. | +| regexp | String representing a JavaScript regexp. | | | Note that since it's not a literal regexp all back-slashes should be repeated twice | +------------+-------------------------------------------------------------------------------------+ -| boolean | Javascript boolean: ``true`` or ``false`` | +| boolean | JavaScript boolean: ``true`` or ``false`` | +------------+-------------------------------------------------------------------------------------+ -| number | Javascript number | +| number | JavaScript number | +------------+-------------------------------------------------------------------------------------+ -| object | Javascript object: ``{ ... }`` | +| object | JavaScript object: ``{ ... }`` | +------------+-------------------------------------------------------------------------------------+ -| array | Javascript array: ``[ ... ]`` | +| array | JavaScript array: ``[ ... ]`` | +------------+-------------------------------------------------------------------------------------+ -Attributes ----------- +Language Only Attributes +------------------------ + +These attributes are only valid at the language level (ie, they many only exist on the top-most language object and have no meaning if specified in children modes). + + +name +^^^^ + +- **type**: string + +The canonical name of this language, ie "JavaScript", etc. + case_insensitive ^^^^^^^^^^^^^^^^ -**type**: boolean +- **type**: boolean Case insensitivity of language keywords and regexps. Used only on the top-level mode. @@ -37,15 +48,56 @@ Case insensitivity of language keywords and regexps. Used only on the top-level aliases ^^^^^^^ -**type**: array +- **type**: array A list of additional names (besides the canonical one given by the filename) that can be used to identify a language in HTML classes and in a call to :ref:`getLanguage `. +classNameAliases +^^^^^^^^^^^^^^^^ + +- **type**: object + +A mapping table of any custom class names your grammar uses and their supported equivalencies. Perhaps your language has a concept of "slots" that roughly correspond to variables in other languages. This allows you to write grammar code like: + +:: + + { + classNameAliases: { + slot: "variable", + "message-name": "string" + }, + contains: [ + { + className: "slot", + begin: // ... + } + ] + } + +The final HTML output will render slots with the CSS class as ``hljs-variable``. This feature exists to make it easier for grammar maintainers to think in their own language when maintaining a grammar. + +For a list of all supported class names please see the :doc:`CSS class reference +`. + + +disableAutodetect +^^^^^^^^^^^^^^^^^ + +- **type**: boolean + +Disables autodetection for this language. + + + +Mode Attributes +--------------- + + className ^^^^^^^^^ -**type**: identifier +- **type**: identifier The name of the mode. It is used as a class name in HTML markup. @@ -56,16 +108,16 @@ for one thing like string in single or double quotes. begin ^^^^^ -**type**: regexp +- **type**: regexp Regular expression starting a mode. For example a single quote for strings or two forward slashes for C-style comments. If absent, ``begin`` defaults to a regexp that matches anything, so the mode starts immediately. on:begin -^^^^^^^^^^^ +^^^^^^^^ -**type**: callback (matchData, response) +- **type**: callback (matchData, response) This callback is triggered the moment a begin match is detected. ``matchData`` includes the typical regex match data; the full match, match groups, etc. The ``response`` object is used to tell the parser how it should handle the match. It can be also used to temporarily store data. @@ -78,7 +130,7 @@ For an example of usage see ``END_SAME_AS_BEGIN`` in ``modes.js``. end ^^^ -**type**: regexp +- **type**: regexp Regular expression ending a mode. For example a single quote for strings or "$" (end of line) for one-line comments. @@ -93,9 +145,9 @@ This is achieved with :ref:`endsWithParent ` attribute. on:end -^^^^^^^^^^^ +^^^^^^ -**type**: callback (matchData, response) +- **type**: callback (matchData, response) This callback is triggered the moment an end match is detected. ``matchData`` includes the typical regex match data; the full match, match groups, etc. The ``response`` object is used to tell the parser how it should handle the match. It can also be used to retrieve data stored from a `begin` callback. @@ -106,9 +158,9 @@ For an example of usage see ``END_SAME_AS_BEGIN`` in ``modes.js``. beginKeywords -^^^^^^^^^^^^^^^^ +^^^^^^^^^^^^^ -**type**: string +- **type**: string Used instead of ``begin`` for modes starting with keywords to avoid needless repetition: @@ -140,7 +192,7 @@ Ex. ``class A { ... }`` would match while ``A.class == B.class`` would not. endsWithParent ^^^^^^^^^^^^^^ -**type**: boolean +- **type**: boolean A flag showing that a mode ends when its parent ends. @@ -158,7 +210,7 @@ This is when ``endsWithParent`` comes into play: :: { - className: 'rules', begin: '{', end: '}', + className: 'rules', begin: /\{/, end: /\}/, contains: [ {className: 'rule', /* ... */ end: ';', endsWithParent: true} ] @@ -169,7 +221,7 @@ This is when ``endsWithParent`` comes into play: endsParent ^^^^^^^^^^^^^^ -**type**: boolean +- **type**: boolean Forces closing of the parent mode right after the current mode is closed. @@ -215,7 +267,7 @@ endSameAsBegin (deprecated as of 10.1) ``END_SAME_AS_BEGIN`` mode or use the ``on:begin`` and ``on:end`` attributes to build more complex paired matchers. -**type**: boolean +- **type**: boolean Acts as ``end`` matching exactly the same string that was found by the corresponding ``begin`` regexp. @@ -244,7 +296,7 @@ and ``endSameAsBegin: true``. lexemes (now keywords.$pattern) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -**type**: regexp +- **type**: regexp A regular expression that extracts individual "words" from the code to compare against :ref:`keywords `. The default value is ``\w+`` which works for @@ -260,7 +312,7 @@ constant that you repeat multiple times within different modes of your grammar. keywords ^^^^^^^^ -**type**: object +- **type**: object / string Keyword definition comes in two forms: @@ -273,7 +325,7 @@ For detailed explanation see :doc:`Language definition guide `. illegal ^^^^^^^ -**type**: regexp +- **type**: regexp A regular expression that defines symbols illegal for the mode. When the parser finds a match for illegal expression it immediately drops parsing the whole language altogether. @@ -282,7 +334,7 @@ When the parser finds a match for illegal expression it immediately drops parsin excludeBegin, excludeEnd ^^^^^^^^^^^^^^^^^^^^^^^^ -**type**: boolean +- **type**: boolean Exclude beginning or ending lexemes out of mode's generated markup. For example in CSS syntax a rule ends with a semicolon. However visually it's better not to color it as the rule contents. Having ``excludeEnd: true`` forces a ```` element for the rule to close before the semicolon. @@ -291,7 +343,7 @@ However visually it's better not to color it as the rule contents. Having ``excl returnBegin ^^^^^^^^^^^ -**type**: boolean +- **type**: boolean Returns just found beginning lexeme back into parser. This is used when beginning of a sub-mode is a complex expression that should not only be found within a parent mode but also parsed according to the rules of a sub-mode. @@ -302,10 +354,10 @@ Since the parser is effectively goes back it's quite possible to create a infini returnEnd ^^^^^^^^^ -**type**: boolean +- **type**: boolean -Returns just found ending lexeme back into parser. This is used for example to parse Javascript embedded into HTML. -A Javascript block ends with the HTML closing tag ```` that cannot be parsed with Javascript rules. +Returns just found ending lexeme back into parser. This is used for example to parse JavaScript embedded into HTML. +A JavaScript block ends with the HTML closing tag ```` that cannot be parsed with JavaScript rules. So it is returned back into its parent HTML mode that knows what to do with it. Since the parser is effectively goes back it's quite possible to create a infinite loop here so use with caution! @@ -314,7 +366,7 @@ Since the parser is effectively goes back it's quite possible to create a infini contains ^^^^^^^^ -**type**: array +- **type**: array The list of sub-modes that can be found inside the mode. For detailed explanation see :doc:`Language definition guide `. @@ -322,18 +374,18 @@ The list of sub-modes that can be found inside the mode. For detailed explanatio starts ^^^^^^ -**type**: identifier +- **type**: identifier The name of the mode that will start right after the current mode ends. The new mode won't be contained within the current one. -Currently this attribute is used to highlight Javascript and CSS contained within HTML. +Currently this attribute is used to highlight JavaScript and CSS contained within HTML. Tags `` diff --git a/tools/lib/language.js b/tools/lib/language.js index 38897ebe2c..5c6e73d14b 100644 --- a/tools/lib/language.js +++ b/tools/lib/language.js @@ -5,9 +5,9 @@ const glob = require("glob") const path = require("path") const build_config = require("../build_config") -const REQUIRES_REGEX = /\/\*.*?Requires: (.*?)\n/s -const CATEGORY_REGEX = /\/\*.*?Category: (.*?)\n/s -const LANGUAGE_REGEX = /\/\*.*?Language: (.*?)\n/s +const REQUIRES_REGEX = /\/\*.*?Requires: (.*?)\r?\n/s +const CATEGORY_REGEX = /\/\*.*?Category: (.*?)\r?\n/s +const LANGUAGE_REGEX = /\/\*.*?Language: (.*?)\r?\n/s const {rollupCode} = require("./bundling.js") const { getThirdPartyPackages } = require("./external_language") @@ -90,7 +90,7 @@ async function compileLanguage (language, options) { var original = data; language.module = data; - data = Terser.minify(data, options["terser"]); + data = await Terser.minify(data, options.terser); language.minified = data.code || original; } diff --git a/types/index.d.ts b/types/index.d.ts index ab38f736b1..ee5c5e8513 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -142,7 +142,7 @@ type MatchType = "begin" | "end" | "illegal" interface ModeCallbacks { "on:end"?: Function, - "on:begin"?: Function, + "on:begin"?: ModeCallback } interface Mode extends ModeCallbacks, ModeDetails { @@ -154,10 +154,12 @@ interface LanguageDetail { rawDefinition?: () => Language aliases?: string[] disableAutodetect?: boolean - contains: ("self"|Mode)[] + contains: (Mode)[] case_insensitive?: boolean keywords?: Record | string - compiled?: boolean + compiled?: boolean, + exports?: any, + classNameAliases?: Record } type Language = LanguageDetail & Partial @@ -213,6 +215,7 @@ interface ModeDetails { // parsed subLanguage?: string | string[] compiled?: boolean + label?: string } // deprecated API since v10