├── .github ├── FUNDING.yml └── workflows │ ├── release.yml │ └── version.yml ├── .gitignore ├── .npmrc ├── README.md ├── addon └── mode │ ├── loadmode.js │ ├── multiplex.js │ ├── overlay.js │ └── simple.js ├── lib └── codemirror.js ├── main.ts ├── manifest.json ├── mode ├── apl │ └── apl.js ├── asciiarmor │ └── asciiarmor.js ├── asn.1 │ └── asn.1.js ├── asterisk │ └── asterisk.js ├── brainfuck │ └── brainfuck.js ├── clike │ └── clike.js ├── clojure │ └── clojure.js ├── cmake │ └── cmake.js ├── cobol │ └── cobol.js ├── coffeescript │ └── coffeescript.js ├── commonlisp │ └── commonlisp.js ├── crystal │ └── crystal.js ├── css │ └── css.js ├── cypher │ └── cypher.js ├── d │ └── d.js ├── dart │ └── dart.js ├── diff │ └── diff.js ├── django │ └── django.js ├── dockerfile │ └── dockerfile.js ├── dtd │ └── dtd.js ├── dylan │ └── dylan.js ├── ebnf │ └── ebnf.js ├── ecl │ └── ecl.js ├── eiffel │ └── eiffel.js ├── elixir │ └── elixir.js ├── elm │ └── elm.js ├── erlang │ └── erlang.js ├── factor │ └── factor.js ├── fcl │ └── fcl.js ├── forth │ └── forth.js ├── fortran │ └── fortran.js ├── gas │ └── gas.js ├── gfm │ └── gfm.js ├── gherkin │ └── gherkin.js ├── go │ └── go.js ├── groovy │ └── groovy.js ├── haml │ └── haml.js ├── handlebars │ └── handlebars.js ├── haskell-literate │ └── haskell-literate.js ├── haskell │ └── haskell.js ├── haxe │ └── haxe.js ├── htmlembedded │ └── htmlembedded.js ├── htmlmixed │ └── htmlmixed.js ├── http │ └── http.js ├── idl │ └── idl.js ├── javascript │ └── javascript.js ├── jinja2 │ └── jinja2.js ├── jsx │ └── jsx.js ├── julia │ └── julia.js ├── livescript │ └── livescript.js ├── lua │ └── lua.js ├── markdown │ └── markdown.js ├── mathematica │ └── mathematica.js ├── mbox │ └── mbox.js ├── meta.js ├── mirc │ └── mirc.js ├── mllike │ └── mllike.js ├── modelica │ └── modelica.js ├── mscgen │ └── mscgen.js ├── mumps │ └── mumps.js ├── nginx │ └── nginx.js ├── nsis │ └── nsis.js ├── ntriples │ └── ntriples.js ├── octave │ └── octave.js ├── oz │ └── oz.js ├── pascal │ └── pascal.js ├── pegjs │ └── pegjs.js ├── perl │ └── perl.js ├── php │ └── php.js ├── pig │ └── pig.js ├── powershell │ └── powershell.js ├── properties │ └── properties.js ├── protobuf │ └── protobuf.js ├── pug │ └── pug.js ├── puppet │ └── puppet.js ├── python │ └── python.js ├── q │ └── q.js ├── r │ └── r.js ├── rpm │ └── rpm.js ├── rst │ └── rst.js ├── ruby │ └── ruby.js ├── rust │ └── rust.js ├── sas │ └── sas.js ├── sass │ └── sass.js ├── scheme │ └── scheme.js ├── shell │ └── shell.js ├── sieve │ └── sieve.js ├── slim │ └── slim.js ├── smalltalk │ └── smalltalk.js ├── smarty │ └── smarty.js ├── solr │ └── solr.js ├── soy │ └── soy.js ├── sparql │ └── sparql.js ├── spreadsheet │ └── spreadsheet.js ├── sql │ └── sql.js ├── stex │ └── stex.js ├── stylus │ └── stylus.js ├── swift │ └── swift.js ├── tcl │ └── tcl.js ├── textile │ └── textile.js ├── tiddlywiki │ ├── tiddlywiki.css │ └── tiddlywiki.js ├── tiki │ ├── tiki.css │ └── tiki.js ├── toml │ └── toml.js ├── tornado │ └── tornado.js ├── troff │ └── troff.js ├── ttcn-cfg │ └── ttcn-cfg.js ├── ttcn │ └── ttcn.js ├── turtle │ └── turtle.js ├── twig │ └── twig.js ├── vb │ └── vb.js ├── vbscript │ └── vbscript.js ├── velocity │ └── velocity.js ├── verilog │ └── verilog.js ├── vhdl │ └── vhdl.js ├── vue │ └── vue.js ├── wast │ └── wast.js ├── webidl │ └── webidl.js ├── xml │ └── xml.js ├── xquery │ └── xquery.js ├── yacas │ └── yacas.js ├── yaml-frontmatter │ └── yaml-frontmatter.js ├── yaml │ └── yaml.js └── z80 │ └── z80.js ├── package.json ├── rollup.config.js ├── screenshot.png ├── styles.scss ├── tsconfig.json └── versions.json /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: deathau 2 | custom: ["https://www.paypal.me/deathau"] 3 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release Obsidian Plugin 2 | on: 3 | push: 4 | # Sequence of patterns matched against refs/tags 5 | tags: 6 | - '*' # Push events to matching any tag format, i.e. 1.0, 20.15.10 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v2 12 | with: 13 | fetch-depth: 0 # otherwise, you will failed to push refs to dest repo 14 | - name: Use Node.js 15 | uses: actions/setup-node@v1 16 | with: 17 | node-version: '14.x' # You might need to adjust this value to your own version 18 | # Get the version number and put it in a variable 19 | - name: Get Version 20 | id: version 21 | run: | 22 | echo "::set-output name=tag::$(git describe --abbrev=0)" 23 | # Build the plugin 24 | - name: Build 25 | id: build 26 | run: | 27 | npm install 28 | npm run build --if-present 29 | # Package the required files into a zip 30 | - name: Package 31 | run: | 32 | mkdir ${{ github.event.repository.name }} 33 | cp main.js manifest.json styles.css README.md ${{ github.event.repository.name }} 34 | zip -r ${{ github.event.repository.name }}.zip ${{ github.event.repository.name }} 35 | # Create the release on github 36 | - name: Create Release 37 | id: create_release 38 | uses: actions/create-release@v1 39 | env: 40 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 41 | VERSION: ${{ github.ref }} 42 | with: 43 | tag_name: ${{ github.ref }} 44 | release_name: ${{ github.ref }} 45 | draft: false 46 | prerelease: false 47 | # Upload the packaged release file 48 | - name: Upload zip file 49 | id: upload-zip 50 | uses: actions/upload-release-asset@v1 51 | env: 52 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 53 | with: 54 | upload_url: ${{ steps.create_release.outputs.upload_url }} 55 | asset_path: ./${{ github.event.repository.name }}.zip 56 | asset_name: ${{ github.event.repository.name }}-${{ steps.version.outputs.tag }}.zip 57 | asset_content_type: application/zip 58 | # Upload the main.js 59 | - name: Upload main.js 60 | id: upload-main 61 | uses: actions/upload-release-asset@v1 62 | env: 63 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 64 | with: 65 | upload_url: ${{ steps.create_release.outputs.upload_url }} 66 | asset_path: ./main.js 67 | asset_name: main.js 68 | asset_content_type: text/javascript 69 | # Upload the manifest.json 70 | - name: Upload manifest.json 71 | id: upload-manifest 72 | uses: actions/upload-release-asset@v1 73 | env: 74 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 75 | with: 76 | upload_url: ${{ steps.create_release.outputs.upload_url }} 77 | asset_path: ./manifest.json 78 | asset_name: manifest.json 79 | asset_content_type: application/json 80 | # Upload the style.css 81 | - name: Upload styles.css 82 | id: upload-css 83 | uses: actions/upload-release-asset@v1 84 | env: 85 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 86 | with: 87 | upload_url: ${{ steps.create_release.outputs.upload_url }} 88 | asset_path: ./styles.css 89 | asset_name: styles.css 90 | asset_content_type: text/css 91 | # TODO: release notes??? 92 | -------------------------------------------------------------------------------- /.github/workflows/version.yml: -------------------------------------------------------------------------------- 1 | name: Bump Version 2 | on: 3 | workflow_dispatch: 4 | inputs: 5 | type: 6 | description: 'Type of version (`major`, `minor`, `patch`)' 7 | required: true 8 | default: 'patch' 9 | jobs: 10 | bump: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v2 14 | with: 15 | persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token 16 | fetch-depth: 0 # otherwise, you will failed to push refs to dest repo 17 | token: ${{secrets.PAT}} # use a personal acces token so that other actions can trigger 18 | - name: Use Node.js 19 | uses: actions/setup-node@v1 20 | with: 21 | node-version: '14.x' # You might need to adjust this value to your own version 22 | - name: Update version 23 | id: version 24 | run: | 25 | git config --local user.email "action@github.com" 26 | git config --local user.name "GitHub Action" 27 | npm version ${{ github.event.inputs.type }} 28 | echo "::set-output name=tag::$(git describe --abbrev=0)" 29 | # update the manifest.json with the tag version 30 | - name: Update manifest version 31 | uses: jossef/action-set-json-field@v1 32 | with: 33 | file: manifest.json 34 | field: version 35 | value: ${{ steps.version.outputs.tag }} 36 | - name: Commit manifest 37 | run: | 38 | git branch --show-current 39 | git add -u 40 | git commit --amend --no-edit 41 | git tag -fa ${{ steps.version.outputs.tag }} -m "${{ steps.version.outputs.tag }}" 42 | # push the commit 43 | - name: Push changes 44 | uses: ad-m/github-push-action@v0.6.0 45 | with: 46 | github_token: ${{secrets.PAT}} 47 | tags: true 48 | branch: ${{ github.ref }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Intellij 2 | *.iml 3 | .idea 4 | 5 | # npm 6 | node_modules 7 | package-lock.json 8 | 9 | # build 10 | main.js 11 | styles.css 12 | *.js.map 13 | 14 | # misc codemirror files 15 | *.html 16 | test.js 17 | 18 | cm-editor-syntax-highlight-obsidian.zip 19 | 20 | cm-editor-syntax-highlight-obsidian/ 21 | deploy -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | tag-version-prefix = "" -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Editor Syntax Highlight Obsidian Plugin 2 | A plugin for [Obsidian](https://obsidian.md) which allows syntax highlighting for code blocks in the editor. 3 | 4 | ![Screenshot](https://github.com/deathau/cm-editor-syntax-highlight-obsidian/raw/main/screenshot.png) 5 | 6 | Imports code from [CodeMirror](https://github.com/codemirror/CodeMirror/) 7 | 8 | ### Compatibility 9 | 10 | Custom plugins are only available for Obsidian v0.9.7+. 11 | 12 | The current API of this repo targets Obsidian **v0.9.7**. 13 | 14 | ### Notes 15 | This is all very expermental at the moment, so parts might not work, etc. 16 | 17 | This imports a bunch of [syntax highlighting modes from CodeMirror](https://github.com/codemirror/CodeMirror/tree/5.58.2/mode), as well as the [yonce](https://github.com/codemirror/CodeMirror/blob/5.58.2/theme/yonce.css) theme for dark mode. 18 | 19 | ## Installation 20 | 21 | ### From within Obsidian 22 | From Obsidian v0.9.8, you can activate this plugin within Obsidian by doing the following: 23 | - Open Settings > Third-party plugin 24 | - Make sure Safe mode is **off** 25 | - Click Browse community plugins 26 | - Search for "Syntax Highlight" 27 | - Click Install 28 | - Once installed, close the community plugins window and activate the newly installed plugin 29 | #### Updates 30 | You can follow the same procedure to update the plugin 31 | 32 | ### From GitHub 33 | - Download the [Latest release](https://github.com/deathau/cm-editor-syntax-highlight-obsidian/releases/latest) 34 | - Extract the `cm-editor-syntax-highlight-obsidian` folder from the zip to your vault's plugins folder: `/.obsidian/plugins/` 35 | Note: On some machines the `.obsidian` folder may be hidden. On MacOS you should be able to press `Command+Shift+Dot` to show the folder in Finder. 36 | - Reload Obsidian 37 | - If prompted about Safe Mode, you can disable safe mode and enable the plugin. 38 | Otherwise head to Settings, third-party plugins, make sure safe mode is off and 39 | enable the plugin from there. 40 | 41 | ## Development 42 | 43 | This project uses Typescript to provide type checking and documentation. 44 | The repo depends on the latest [plugin API](https://github.com/obsidianmd/obsidian-api) in Typescript Definition format, which contains TSDoc comments describing what it does. 45 | 46 | **Note:** The Obsidian API is still in early alpha and is subject to change at any time! 47 | 48 | If you want to contribute to development and/or just customize it with your own 49 | tweaks, you can do the following: 50 | - Clone this repo. 51 | - `npm i` or `yarn` to install dependencies 52 | - `npm run build` to compile. 53 | - Copy `manifest.json`, `main.js` and `styles.css` to a subfolder of your plugins 54 | folder (e.g, `/.obsidian/plugins/cm-editor-syntax-highlight-obsidian/`) 55 | - Reload obsidian to see changes 56 | 57 | Alternately, you can clone the repo directly into your plugins folder and once 58 | dependencies are installed use `npm run dev` to start compilation in watch mode. 59 | You may have to reload obsidian (`ctrl+R`) to see changes. 60 | 61 | ## Pricing 62 | Huh? This is an open-source plugin I made *for fun*. It's completely free. 63 | However, if you absolutely *have* to send me money because you like it that 64 | much, feel free to throw some coins in my hat via 65 | [PayPal](https://paypal.me/deathau) or sponsor me via 66 | [GitHub Sponsors](https://github.com/sponsors/deathau) 67 | 68 | # Version History 69 | ## 0.1.3 70 | - Fixed elixir mode (sorry this took me so long to release, it was fixed AAAGES ago...) 71 | - Added javascript syntax highlighting for `dataviewjs` blocks (thanks @dbarenholz) 72 | - Added YAML syntax highlighting for `dataview` and `tracker` blocks (thanks @KjellConnelly) 73 | 74 | ## 0.1.2 75 | - Added elixir mode (thanks to James Dalton) 76 | 77 | ## 0.1.1 78 | - Apply codemirror theme to latex math also 79 | 80 | ## 0.1.0 81 | - Adjusted the dark codemirror theme to also apply to frontmatter 82 | - Reload the editor modes on load, so syntax highlighting is shown on enable 83 | - Delete editor modes on unload, so syntax highlighting is hidden on disable 84 | 85 | ## v0.0.1 86 | Initial Release. 87 | Copy-pasted and imported editor modes from [CodeMirror 5.58.2](https://github.com/codemirror/CodeMirror/tree/5.58.2/mode). Got compiler errors importing `markdown` and `gfm`, so those aren't available for now. 88 | -------------------------------------------------------------------------------- /addon/mode/loadmode.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror"), "cjs"); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], function(CM) { mod(CM, "amd"); }); 9 | else // Plain browser env 10 | mod(CodeMirror, "plain"); 11 | })(function(CodeMirror, env) { 12 | if (!CodeMirror.modeURL) CodeMirror.modeURL = "../mode/%N/%N.js"; 13 | 14 | var loading = {}; 15 | function splitCallback(cont, n) { 16 | var countDown = n; 17 | return function() { if (--countDown == 0) cont(); }; 18 | } 19 | function ensureDeps(mode, cont, options) { 20 | var modeObj = CodeMirror.modes[mode], deps = modeObj && modeObj.dependencies; 21 | if (!deps) return cont(); 22 | var missing = []; 23 | for (var i = 0; i < deps.length; ++i) { 24 | if (!CodeMirror.modes.hasOwnProperty(deps[i])) 25 | missing.push(deps[i]); 26 | } 27 | if (!missing.length) return cont(); 28 | var split = splitCallback(cont, missing.length); 29 | for (var i = 0; i < missing.length; ++i) 30 | CodeMirror.requireMode(missing[i], split, options); 31 | } 32 | 33 | CodeMirror.requireMode = function(mode, cont, options) { 34 | if (typeof mode != "string") mode = mode.name; 35 | if (CodeMirror.modes.hasOwnProperty(mode)) return ensureDeps(mode, cont, options); 36 | if (loading.hasOwnProperty(mode)) return loading[mode].push(cont); 37 | 38 | var file = options && options.path ? options.path(mode) : CodeMirror.modeURL.replace(/%N/g, mode); 39 | if (options && options.loadMode) { 40 | options.loadMode(file, function() { ensureDeps(mode, cont, options) }) 41 | } else if (env == "plain") { 42 | var script = document.createElement("script"); 43 | script.src = file; 44 | var others = document.getElementsByTagName("script")[0]; 45 | var list = loading[mode] = [cont]; 46 | CodeMirror.on(script, "load", function() { 47 | ensureDeps(mode, function() { 48 | for (var i = 0; i < list.length; ++i) list[i](); 49 | }, options); 50 | }); 51 | others.parentNode.insertBefore(script, others); 52 | } else if (env == "cjs") { 53 | require(file); 54 | cont(); 55 | } else if (env == "amd") { 56 | requirejs([file], cont); 57 | } 58 | }; 59 | 60 | CodeMirror.autoLoadMode = function(instance, mode, options) { 61 | if (!CodeMirror.modes.hasOwnProperty(mode)) 62 | CodeMirror.requireMode(mode, function() { 63 | instance.setOption("mode", instance.getOption("mode")); 64 | }, options); 65 | }; 66 | }); 67 | -------------------------------------------------------------------------------- /addon/mode/multiplex.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | }); 14 | -------------------------------------------------------------------------------- /addon/mode/overlay.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | // Utility function that allows modes to be combined. The mode given 5 | // as the base argument takes care of most of the normal mode 6 | // functionality, but a second (typically simple) mode is used, which 7 | // can override the style of text. Both modes get to parse all of the 8 | // text, but when both assign a non-null style to a piece of code, the 9 | // overlay wins, unless the combine argument was true and not overridden, 10 | // or state.overlay.combineTokens was true, in which case the styles are 11 | // combined. 12 | 13 | (function(mod) { 14 | if (typeof exports == "object" && typeof module == "object") // CommonJS 15 | mod(require("../../lib/codemirror")); 16 | else if (typeof define == "function" && define.amd) // AMD 17 | define(["../../lib/codemirror"], mod); 18 | else // Plain browser env 19 | mod(CodeMirror); 20 | })(function(CodeMirror) { 21 | "use strict"; 22 | 23 | }); 24 | -------------------------------------------------------------------------------- /lib/codemirror.js: -------------------------------------------------------------------------------- 1 | module.exports = CodeMirror; -------------------------------------------------------------------------------- /main.ts: -------------------------------------------------------------------------------- 1 | import './styles.scss' 2 | import { MarkdownView, Plugin } from 'obsidian' 3 | 4 | import './lib/codemirror' 5 | import './mode/meta' 6 | import './mode/apl/apl' 7 | import './mode/asciiarmor/asciiarmor' 8 | import './mode/asn.1/asn.1' 9 | import './mode/asterisk/asterisk' 10 | import './mode/brainfuck/brainfuck' 11 | import './mode/clike/clike' 12 | import './mode/clojure/clojure' 13 | import './mode/cmake/cmake' 14 | import './mode/cobol/cobol' 15 | import './mode/coffeescript/coffeescript' 16 | import './mode/commonlisp/commonlisp' 17 | import './mode/crystal/crystal' 18 | import './mode/css/css' 19 | import './mode/cypher/cypher' 20 | import './mode/d/d' 21 | import './mode/dart/dart' 22 | import './mode/diff/diff' 23 | import './mode/django/django' 24 | import './mode/dockerfile/dockerfile' 25 | import './mode/dtd/dtd' 26 | import './mode/dylan/dylan' 27 | import './mode/ebnf/ebnf' 28 | import './mode/ecl/ecl' 29 | import './mode/eiffel/eiffel' 30 | import './mode/elixir/elixir' 31 | import './mode/elm/elm' 32 | import './mode/erlang/erlang' 33 | import './mode/factor/factor' 34 | import './mode/fcl/fcl' 35 | import './mode/forth/forth' 36 | import './mode/fortran/fortran' 37 | import './mode/gas/gas' 38 | // import './mode/gfm/gfm' // Error: '__moduleExports' is not exported by mode\meta.js, imported by .obsidian/plugins/cm-editor-snytax-highlight-obsidian/mode/meta.js?commonjs-proxy 39 | import './mode/gherkin/gherkin' 40 | import './mode/go/go' 41 | import './mode/groovy/groovy' 42 | import './mode/haml/haml' 43 | import './mode/handlebars/handlebars' 44 | import './mode/haskell/haskell' 45 | import './mode/haskell-literate/haskell-literate' 46 | import './mode/haxe/haxe' 47 | import './mode/htmlembedded/htmlembedded' 48 | import './mode/htmlmixed/htmlmixed' 49 | import './mode/http/http' 50 | import './mode/idl/idl' 51 | import './mode/javascript/javascript' 52 | import './mode/jinja2/jinja2' 53 | import './mode/jsx/jsx' 54 | import './mode/julia/julia' 55 | import './mode/livescript/livescript' 56 | import './mode/lua/lua' 57 | // import './mode/markdown/markdown' // Error: '__moduleExports' is not exported by mode\meta.js, imported by .obsidian/plugins/cm-editor-snytax-highlight-obsidian/mode/meta.js?commonjs-proxy 58 | import './mode/mathematica/mathematica' 59 | import './mode/mbox/mbox' 60 | import './mode/mirc/mirc' 61 | import './mode/mllike/mllike' 62 | import './mode/modelica/modelica' 63 | import './mode/mscgen/mscgen' 64 | import './mode/mumps/mumps' 65 | import './mode/nginx/nginx' 66 | import './mode/nsis/nsis' 67 | import './mode/ntriples/ntriples' 68 | import './mode/octave/octave' 69 | import './mode/oz/oz' 70 | import './mode/pascal/pascal' 71 | import './mode/pegjs/pegjs' 72 | import './mode/perl/perl' 73 | import './mode/php/php' 74 | import './mode/pig/pig' 75 | import './mode/powershell/powershell' 76 | import './mode/properties/properties' 77 | import './mode/protobuf/protobuf' 78 | import './mode/pug/pug' 79 | import './mode/puppet/puppet' 80 | import './mode/python/python' 81 | import './mode/q/q' 82 | import './mode/r/r' 83 | import './mode/rpm/rpm' 84 | import './mode/rst/rst' 85 | import './mode/ruby/ruby' 86 | import './mode/rust/rust' 87 | import './mode/sas/sas' 88 | import './mode/sass/sass' 89 | import './mode/scheme/scheme' 90 | import './mode/shell/shell' 91 | import './mode/sieve/sieve' 92 | import './mode/slim/slim' 93 | import './mode/smalltalk/smalltalk' 94 | import './mode/smarty/smarty' 95 | import './mode/solr/solr' 96 | import './mode/soy/soy' 97 | import './mode/sparql/sparql' 98 | import './mode/spreadsheet/spreadsheet' 99 | import './mode/sql/sql' 100 | import './mode/stex/stex' 101 | import './mode/stylus/stylus' 102 | import './mode/swift/swift' 103 | import './mode/tcl/tcl' 104 | import './mode/textile/textile' 105 | import './mode/tiddlywiki/tiddlywiki' 106 | import './mode/tiki/tiki' 107 | import './mode/toml/toml' 108 | import './mode/tornado/tornado' 109 | import './mode/troff/troff' 110 | import './mode/ttcn/ttcn' 111 | import './mode/ttcn-cfg/ttcn-cfg' 112 | import './mode/turtle/turtle' 113 | import './mode/twig/twig' 114 | import './mode/vb/vb' 115 | import './mode/vbscript/vbscript' 116 | import './mode/velocity/velocity' 117 | import './mode/verilog/verilog' 118 | import './mode/vhdl/vhdl' 119 | import './mode/vue/vue' 120 | import './mode/wast/wast' 121 | import './mode/webidl/webidl' 122 | import './mode/xml/xml' 123 | import './mode/xquery/xquery' 124 | import './mode/yacas/yacas' 125 | import './mode/yaml/yaml' 126 | import './mode/yaml-frontmatter/yaml-frontmatter' 127 | import './mode/z80/z80' 128 | 129 | export default class CMSyntaxHighlightPlugin extends Plugin { 130 | 131 | // these are the CodeMirror modes that Obsidian uses by default 132 | modesToKeep = ["hypermd", "markdown", "null", "xml"]; 133 | 134 | async onload() { 135 | // wait for layout to be ready to perform the rest 136 | this.app.workspace.layoutReady ? this.layoutReady() : this.app.workspace.on('layout-ready', this.layoutReady); 137 | } 138 | 139 | layoutReady = () => { 140 | // don't need the event handler anymore, get rid of it 141 | this.app.workspace.off('layout-ready', this.layoutReady); 142 | this.refreshLeaves(); 143 | } 144 | 145 | onunload() { 146 | // Delete all the codemirror modes, to disable the syntax highlighting 147 | // except the default ones, obviously 148 | for (const key in CodeMirror.modes) { 149 | if (CodeMirror.modes.hasOwnProperty(key) && !this.modesToKeep.includes(key)) { 150 | delete CodeMirror.modes[key]; 151 | } 152 | } 153 | 154 | this.refreshLeaves(); 155 | } 156 | 157 | refreshLeaves = () => { 158 | // re-set the editor mode to refresh the syntax highlighting 159 | this.app.workspace.iterateCodeMirrors(cm => cm.setOption("mode", cm.getOption("mode"))) 160 | } 161 | } -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": "cm-editor-syntax-highlight-obsidian", 3 | "name": "Editor Syntax Highlight", 4 | "author": "death_au", 5 | "authorUrl": "https://github.com/deathau", 6 | "description": "Show syntax highlighing in code blocks the editor", 7 | "isDesktopOnly": false, 8 | "version": "0.1.3", 9 | "minAppVersion": "0.10.0" 10 | } -------------------------------------------------------------------------------- /mode/apl/apl.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineMode("apl", function() { 15 | var builtInOps = { 16 | ".": "innerProduct", 17 | "\\": "scan", 18 | "/": "reduce", 19 | "⌿": "reduce1Axis", 20 | "⍀": "scan1Axis", 21 | "¨": "each", 22 | "⍣": "power" 23 | }; 24 | var builtInFuncs = { 25 | "+": ["conjugate", "add"], 26 | "−": ["negate", "subtract"], 27 | "×": ["signOf", "multiply"], 28 | "÷": ["reciprocal", "divide"], 29 | "⌈": ["ceiling", "greaterOf"], 30 | "⌊": ["floor", "lesserOf"], 31 | "∣": ["absolute", "residue"], 32 | "⍳": ["indexGenerate", "indexOf"], 33 | "?": ["roll", "deal"], 34 | "⋆": ["exponentiate", "toThePowerOf"], 35 | "⍟": ["naturalLog", "logToTheBase"], 36 | "○": ["piTimes", "circularFuncs"], 37 | "!": ["factorial", "binomial"], 38 | "⌹": ["matrixInverse", "matrixDivide"], 39 | "<": [null, "lessThan"], 40 | "≤": [null, "lessThanOrEqual"], 41 | "=": [null, "equals"], 42 | ">": [null, "greaterThan"], 43 | "≥": [null, "greaterThanOrEqual"], 44 | "≠": [null, "notEqual"], 45 | "≡": ["depth", "match"], 46 | "≢": [null, "notMatch"], 47 | "∈": ["enlist", "membership"], 48 | "⍷": [null, "find"], 49 | "∪": ["unique", "union"], 50 | "∩": [null, "intersection"], 51 | "∼": ["not", "without"], 52 | "∨": [null, "or"], 53 | "∧": [null, "and"], 54 | "⍱": [null, "nor"], 55 | "⍲": [null, "nand"], 56 | "⍴": ["shapeOf", "reshape"], 57 | ",": ["ravel", "catenate"], 58 | "⍪": [null, "firstAxisCatenate"], 59 | "⌽": ["reverse", "rotate"], 60 | "⊖": ["axis1Reverse", "axis1Rotate"], 61 | "⍉": ["transpose", null], 62 | "↑": ["first", "take"], 63 | "↓": [null, "drop"], 64 | "⊂": ["enclose", "partitionWithAxis"], 65 | "⊃": ["diclose", "pick"], 66 | "⌷": [null, "index"], 67 | "⍋": ["gradeUp", null], 68 | "⍒": ["gradeDown", null], 69 | "⊤": ["encode", null], 70 | "⊥": ["decode", null], 71 | "⍕": ["format", "formatByExample"], 72 | "⍎": ["execute", null], 73 | "⊣": ["stop", "left"], 74 | "⊢": ["pass", "right"] 75 | }; 76 | 77 | var isOperator = /[\.\/⌿⍀¨⍣]/; 78 | var isNiladic = /⍬/; 79 | var isFunction = /[\+−×÷⌈⌊∣⍳\?⋆⍟○!⌹<≤=>≥≠≡≢∈⍷∪∩∼∨∧⍱⍲⍴,⍪⌽⊖⍉↑↓⊂⊃⌷⍋⍒⊤⊥⍕⍎⊣⊢]/; 80 | var isArrow = /←/; 81 | var isComment = /[⍝#].*$/; 82 | 83 | var stringEater = function(type) { 84 | var prev; 85 | prev = false; 86 | return function(c) { 87 | prev = c; 88 | if (c === type) { 89 | return prev === "\\"; 90 | } 91 | return true; 92 | }; 93 | }; 94 | return { 95 | startState: function() { 96 | return { 97 | prev: false, 98 | func: false, 99 | op: false, 100 | string: false, 101 | escape: false 102 | }; 103 | }, 104 | token: function(stream, state) { 105 | var ch, funcName; 106 | if (stream.eatSpace()) { 107 | return null; 108 | } 109 | ch = stream.next(); 110 | if (ch === '"' || ch === "'") { 111 | stream.eatWhile(stringEater(ch)); 112 | stream.next(); 113 | state.prev = true; 114 | return "string"; 115 | } 116 | if (/[\[{\(]/.test(ch)) { 117 | state.prev = false; 118 | return null; 119 | } 120 | if (/[\]}\)]/.test(ch)) { 121 | state.prev = true; 122 | return null; 123 | } 124 | if (isNiladic.test(ch)) { 125 | state.prev = false; 126 | return "niladic"; 127 | } 128 | if (/[¯\d]/.test(ch)) { 129 | if (state.func) { 130 | state.func = false; 131 | state.prev = false; 132 | } else { 133 | state.prev = true; 134 | } 135 | stream.eatWhile(/[\w\.]/); 136 | return "number"; 137 | } 138 | if (isOperator.test(ch)) { 139 | return "operator apl-" + builtInOps[ch]; 140 | } 141 | if (isArrow.test(ch)) { 142 | return "apl-arrow"; 143 | } 144 | if (isFunction.test(ch)) { 145 | funcName = "apl-"; 146 | if (builtInFuncs[ch] != null) { 147 | if (state.prev) { 148 | funcName += builtInFuncs[ch][1]; 149 | } else { 150 | funcName += builtInFuncs[ch][0]; 151 | } 152 | } 153 | state.func = true; 154 | state.prev = false; 155 | return "function " + funcName; 156 | } 157 | if (isComment.test(ch)) { 158 | stream.skipToEnd(); 159 | return "comment"; 160 | } 161 | if (ch === "∘" && stream.peek() === ".") { 162 | stream.next(); 163 | return "function jot-dot"; 164 | } 165 | stream.eatWhile(/[\w\$_]/); 166 | state.prev = true; 167 | return "keyword"; 168 | } 169 | }; 170 | }); 171 | 172 | CodeMirror.defineMIME("text/apl", "apl"); 173 | 174 | }); 175 | -------------------------------------------------------------------------------- /mode/asciiarmor/asciiarmor.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | function errorIfNotEmpty(stream) { 15 | var nonWS = stream.match(/^\s*\S/); 16 | stream.skipToEnd(); 17 | return nonWS ? "error" : null; 18 | } 19 | 20 | CodeMirror.defineMode("asciiarmor", function() { 21 | return { 22 | token: function(stream, state) { 23 | var m; 24 | if (state.state == "top") { 25 | if (stream.sol() && (m = stream.match(/^-----BEGIN (.*)?-----\s*$/))) { 26 | state.state = "headers"; 27 | state.type = m[1]; 28 | return "tag"; 29 | } 30 | return errorIfNotEmpty(stream); 31 | } else if (state.state == "headers") { 32 | if (stream.sol() && stream.match(/^\w+:/)) { 33 | state.state = "header"; 34 | return "atom"; 35 | } else { 36 | var result = errorIfNotEmpty(stream); 37 | if (result) state.state = "body"; 38 | return result; 39 | } 40 | } else if (state.state == "header") { 41 | stream.skipToEnd(); 42 | state.state = "headers"; 43 | return "string"; 44 | } else if (state.state == "body") { 45 | if (stream.sol() && (m = stream.match(/^-----END (.*)?-----\s*$/))) { 46 | if (m[1] != state.type) return "error"; 47 | state.state = "end"; 48 | return "tag"; 49 | } else { 50 | if (stream.eatWhile(/[A-Za-z0-9+\/=]/)) { 51 | return null; 52 | } else { 53 | stream.next(); 54 | return "error"; 55 | } 56 | } 57 | } else if (state.state == "end") { 58 | return errorIfNotEmpty(stream); 59 | } 60 | }, 61 | blankLine: function(state) { 62 | if (state.state == "headers") state.state = "body"; 63 | }, 64 | startState: function() { 65 | return {state: "top", type: null}; 66 | } 67 | }; 68 | }); 69 | 70 | CodeMirror.defineMIME("application/pgp", "asciiarmor"); 71 | CodeMirror.defineMIME("application/pgp-encrypted", "asciiarmor"); 72 | CodeMirror.defineMIME("application/pgp-keys", "asciiarmor"); 73 | CodeMirror.defineMIME("application/pgp-signature", "asciiarmor"); 74 | }); 75 | -------------------------------------------------------------------------------- /mode/brainfuck/brainfuck.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | // Brainfuck mode created by Michael Kaminsky https://github.com/mkaminsky11 5 | 6 | (function(mod) { 7 | if (typeof exports == "object" && typeof module == "object") 8 | mod(require("../../lib/codemirror")) 9 | else if (typeof define == "function" && define.amd) 10 | define(["../../lib/codemirror"], mod) 11 | else 12 | mod(CodeMirror) 13 | })(function(CodeMirror) { 14 | "use strict" 15 | var reserve = "><+-.,[]".split(""); 16 | /* 17 | comments can be either: 18 | placed behind lines 19 | 20 | +++ this is a comment 21 | 22 | where reserved characters cannot be used 23 | or in a loop 24 | [ 25 | this is ok to use [ ] and stuff 26 | ] 27 | or preceded by # 28 | */ 29 | CodeMirror.defineMode("brainfuck", function() { 30 | return { 31 | startState: function() { 32 | return { 33 | commentLine: false, 34 | left: 0, 35 | right: 0, 36 | commentLoop: false 37 | } 38 | }, 39 | token: function(stream, state) { 40 | if (stream.eatSpace()) return null 41 | if(stream.sol()){ 42 | state.commentLine = false; 43 | } 44 | var ch = stream.next().toString(); 45 | if(reserve.indexOf(ch) !== -1){ 46 | if(state.commentLine === true){ 47 | if(stream.eol()){ 48 | state.commentLine = false; 49 | } 50 | return "comment"; 51 | } 52 | if(ch === "]" || ch === "["){ 53 | if(ch === "["){ 54 | state.left++; 55 | } 56 | else{ 57 | state.right++; 58 | } 59 | return "bracket"; 60 | } 61 | else if(ch === "+" || ch === "-"){ 62 | return "keyword"; 63 | } 64 | else if(ch === "<" || ch === ">"){ 65 | return "atom"; 66 | } 67 | else if(ch === "." || ch === ","){ 68 | return "def"; 69 | } 70 | } 71 | else{ 72 | state.commentLine = true; 73 | if(stream.eol()){ 74 | state.commentLine = false; 75 | } 76 | return "comment"; 77 | } 78 | if(stream.eol()){ 79 | state.commentLine = false; 80 | } 81 | } 82 | }; 83 | }); 84 | CodeMirror.defineMIME("text/x-brainfuck","brainfuck") 85 | }); 86 | -------------------------------------------------------------------------------- /mode/cmake/cmake.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) 8 | define(["../../lib/codemirror"], mod); 9 | else 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineMode("cmake", function () { 15 | var variable_regex = /({)?[a-zA-Z0-9_]+(})?/; 16 | 17 | function tokenString(stream, state) { 18 | var current, prev, found_var = false; 19 | while (!stream.eol() && (current = stream.next()) != state.pending) { 20 | if (current === '$' && prev != '\\' && state.pending == '"') { 21 | found_var = true; 22 | break; 23 | } 24 | prev = current; 25 | } 26 | if (found_var) { 27 | stream.backUp(1); 28 | } 29 | if (current == state.pending) { 30 | state.continueString = false; 31 | } else { 32 | state.continueString = true; 33 | } 34 | return "string"; 35 | } 36 | 37 | function tokenize(stream, state) { 38 | var ch = stream.next(); 39 | 40 | // Have we found a variable? 41 | if (ch === '$') { 42 | if (stream.match(variable_regex)) { 43 | return 'variable-2'; 44 | } 45 | return 'variable'; 46 | } 47 | // Should we still be looking for the end of a string? 48 | if (state.continueString) { 49 | // If so, go through the loop again 50 | stream.backUp(1); 51 | return tokenString(stream, state); 52 | } 53 | // Do we just have a function on our hands? 54 | // In 'cmake_minimum_required (VERSION 2.8.8)', 'cmake_minimum_required' is matched 55 | if (stream.match(/(\s+)?\w+\(/) || stream.match(/(\s+)?\w+\ \(/)) { 56 | stream.backUp(1); 57 | return 'def'; 58 | } 59 | if (ch == "#") { 60 | stream.skipToEnd(); 61 | return "comment"; 62 | } 63 | // Have we found a string? 64 | if (ch == "'" || ch == '"') { 65 | // Store the type (single or double) 66 | state.pending = ch; 67 | // Perform the looping function to find the end 68 | return tokenString(stream, state); 69 | } 70 | if (ch == '(' || ch == ')') { 71 | return 'bracket'; 72 | } 73 | if (ch.match(/[0-9]/)) { 74 | return 'number'; 75 | } 76 | stream.eatWhile(/[\w-]/); 77 | return null; 78 | } 79 | return { 80 | startState: function () { 81 | var state = {}; 82 | state.inDefinition = false; 83 | state.inInclude = false; 84 | state.continueString = false; 85 | state.pending = false; 86 | return state; 87 | }, 88 | token: function (stream, state) { 89 | if (stream.eatSpace()) return null; 90 | return tokenize(stream, state); 91 | } 92 | }; 93 | }); 94 | 95 | CodeMirror.defineMIME("text/x-cmake", "cmake"); 96 | 97 | }); 98 | -------------------------------------------------------------------------------- /mode/commonlisp/commonlisp.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineMode("commonlisp", function (config) { 15 | var specialForm = /^(block|let*|return-from|catch|load-time-value|setq|eval-when|locally|symbol-macrolet|flet|macrolet|tagbody|function|multiple-value-call|the|go|multiple-value-prog1|throw|if|progn|unwind-protect|labels|progv|let|quote)$/; 16 | var assumeBody = /^with|^def|^do|^prog|case$|^cond$|bind$|when$|unless$/; 17 | var numLiteral = /^(?:[+\-]?(?:\d+|\d*\.\d+)(?:[efd][+\-]?\d+)?|[+\-]?\d+(?:\/[+\-]?\d+)?|#b[+\-]?[01]+|#o[+\-]?[0-7]+|#x[+\-]?[\da-f]+)/; 18 | var symbol = /[^\s'`,@()\[\]";]/; 19 | var type; 20 | 21 | function readSym(stream) { 22 | var ch; 23 | while (ch = stream.next()) { 24 | if (ch == "\\") stream.next(); 25 | else if (!symbol.test(ch)) { stream.backUp(1); break; } 26 | } 27 | return stream.current(); 28 | } 29 | 30 | function base(stream, state) { 31 | if (stream.eatSpace()) {type = "ws"; return null;} 32 | if (stream.match(numLiteral)) return "number"; 33 | var ch = stream.next(); 34 | if (ch == "\\") ch = stream.next(); 35 | 36 | if (ch == '"') return (state.tokenize = inString)(stream, state); 37 | else if (ch == "(") { type = "open"; return "bracket"; } 38 | else if (ch == ")" || ch == "]") { type = "close"; return "bracket"; } 39 | else if (ch == ";") { stream.skipToEnd(); type = "ws"; return "comment"; } 40 | else if (/['`,@]/.test(ch)) return null; 41 | else if (ch == "|") { 42 | if (stream.skipTo("|")) { stream.next(); return "symbol"; } 43 | else { stream.skipToEnd(); return "error"; } 44 | } else if (ch == "#") { 45 | var ch = stream.next(); 46 | if (ch == "(") { type = "open"; return "bracket"; } 47 | else if (/[+\-=\.']/.test(ch)) return null; 48 | else if (/\d/.test(ch) && stream.match(/^\d*#/)) return null; 49 | else if (ch == "|") return (state.tokenize = inComment)(stream, state); 50 | else if (ch == ":") { readSym(stream); return "meta"; } 51 | else if (ch == "\\") { stream.next(); readSym(stream); return "string-2" } 52 | else return "error"; 53 | } else { 54 | var name = readSym(stream); 55 | if (name == ".") return null; 56 | type = "symbol"; 57 | if (name == "nil" || name == "t" || name.charAt(0) == ":") return "atom"; 58 | if (state.lastType == "open" && (specialForm.test(name) || assumeBody.test(name))) return "keyword"; 59 | if (name.charAt(0) == "&") return "variable-2"; 60 | return "variable"; 61 | } 62 | } 63 | 64 | function inString(stream, state) { 65 | var escaped = false, next; 66 | while (next = stream.next()) { 67 | if (next == '"' && !escaped) { state.tokenize = base; break; } 68 | escaped = !escaped && next == "\\"; 69 | } 70 | return "string"; 71 | } 72 | 73 | function inComment(stream, state) { 74 | var next, last; 75 | while (next = stream.next()) { 76 | if (next == "#" && last == "|") { state.tokenize = base; break; } 77 | last = next; 78 | } 79 | type = "ws"; 80 | return "comment"; 81 | } 82 | 83 | return { 84 | startState: function () { 85 | return {ctx: {prev: null, start: 0, indentTo: 0}, lastType: null, tokenize: base}; 86 | }, 87 | 88 | token: function (stream, state) { 89 | if (stream.sol() && typeof state.ctx.indentTo != "number") 90 | state.ctx.indentTo = state.ctx.start + 1; 91 | 92 | type = null; 93 | var style = state.tokenize(stream, state); 94 | if (type != "ws") { 95 | if (state.ctx.indentTo == null) { 96 | if (type == "symbol" && assumeBody.test(stream.current())) 97 | state.ctx.indentTo = state.ctx.start + config.indentUnit; 98 | else 99 | state.ctx.indentTo = "next"; 100 | } else if (state.ctx.indentTo == "next") { 101 | state.ctx.indentTo = stream.column(); 102 | } 103 | state.lastType = type; 104 | } 105 | if (type == "open") state.ctx = {prev: state.ctx, start: stream.column(), indentTo: null}; 106 | else if (type == "close") state.ctx = state.ctx.prev || state.ctx; 107 | return style; 108 | }, 109 | 110 | indent: function (state, _textAfter) { 111 | var i = state.ctx.indentTo; 112 | return typeof i == "number" ? i : state.ctx.start + 1; 113 | }, 114 | 115 | closeBrackets: {pairs: "()[]{}\"\""}, 116 | lineComment: ";;", 117 | blockCommentStart: "#|", 118 | blockCommentEnd: "|#" 119 | }; 120 | }); 121 | 122 | CodeMirror.defineMIME("text/x-common-lisp", "commonlisp"); 123 | 124 | }); 125 | -------------------------------------------------------------------------------- /mode/dart/dart.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror"), require("../clike/clike")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror", "../clike/clike"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | var keywords = ("this super static final const abstract class extends external factory " + 15 | "implements mixin get native set typedef with enum throw rethrow " + 16 | "assert break case continue default in return new deferred async await covariant " + 17 | "try catch finally do else for if switch while import library export " + 18 | "part of show hide is as extension on yield late required").split(" "); 19 | var blockKeywords = "try catch finally do else for if switch while".split(" "); 20 | var atoms = "true false null".split(" "); 21 | var builtins = "void bool num int double dynamic var String Null Never".split(" "); 22 | 23 | function set(words) { 24 | var obj = {}; 25 | for (var i = 0; i < words.length; ++i) obj[words[i]] = true; 26 | return obj; 27 | } 28 | 29 | function pushInterpolationStack(state) { 30 | (state.interpolationStack || (state.interpolationStack = [])).push(state.tokenize); 31 | } 32 | 33 | function popInterpolationStack(state) { 34 | return (state.interpolationStack || (state.interpolationStack = [])).pop(); 35 | } 36 | 37 | function sizeInterpolationStack(state) { 38 | return state.interpolationStack ? state.interpolationStack.length : 0; 39 | } 40 | 41 | CodeMirror.defineMIME("application/dart", { 42 | name: "clike", 43 | keywords: set(keywords), 44 | blockKeywords: set(blockKeywords), 45 | builtin: set(builtins), 46 | atoms: set(atoms), 47 | hooks: { 48 | "@": function(stream) { 49 | stream.eatWhile(/[\w\$_\.]/); 50 | return "meta"; 51 | }, 52 | 53 | // custom string handling to deal with triple-quoted strings and string interpolation 54 | "'": function(stream, state) { 55 | return tokenString("'", stream, state, false); 56 | }, 57 | "\"": function(stream, state) { 58 | return tokenString("\"", stream, state, false); 59 | }, 60 | "r": function(stream, state) { 61 | var peek = stream.peek(); 62 | if (peek == "'" || peek == "\"") { 63 | return tokenString(stream.next(), stream, state, true); 64 | } 65 | return false; 66 | }, 67 | 68 | "}": function(_stream, state) { 69 | // "}" is end of interpolation, if interpolation stack is non-empty 70 | if (sizeInterpolationStack(state) > 0) { 71 | state.tokenize = popInterpolationStack(state); 72 | return null; 73 | } 74 | return false; 75 | }, 76 | 77 | "/": function(stream, state) { 78 | if (!stream.eat("*")) return false 79 | state.tokenize = tokenNestedComment(1) 80 | return state.tokenize(stream, state) 81 | }, 82 | token: function(stream, _, style) { 83 | if (style == "variable") { 84 | // Assume uppercase symbols are classes using variable-2 85 | var isUpper = RegExp('^[_$]*[A-Z][a-zA-Z0-9_$]*$','g'); 86 | if (isUpper.test(stream.current())) { 87 | return 'variable-2'; 88 | } 89 | } 90 | } 91 | } 92 | }); 93 | 94 | function tokenString(quote, stream, state, raw) { 95 | var tripleQuoted = false; 96 | if (stream.eat(quote)) { 97 | if (stream.eat(quote)) tripleQuoted = true; 98 | else return "string"; //empty string 99 | } 100 | function tokenStringHelper(stream, state) { 101 | var escaped = false; 102 | while (!stream.eol()) { 103 | if (!raw && !escaped && stream.peek() == "$") { 104 | pushInterpolationStack(state); 105 | state.tokenize = tokenInterpolation; 106 | return "string"; 107 | } 108 | var next = stream.next(); 109 | if (next == quote && !escaped && (!tripleQuoted || stream.match(quote + quote))) { 110 | state.tokenize = null; 111 | break; 112 | } 113 | escaped = !raw && !escaped && next == "\\"; 114 | } 115 | return "string"; 116 | } 117 | state.tokenize = tokenStringHelper; 118 | return tokenStringHelper(stream, state); 119 | } 120 | 121 | function tokenInterpolation(stream, state) { 122 | stream.eat("$"); 123 | if (stream.eat("{")) { 124 | // let clike handle the content of ${...}, 125 | // we take over again when "}" appears (see hooks). 126 | state.tokenize = null; 127 | } else { 128 | state.tokenize = tokenInterpolationIdentifier; 129 | } 130 | return null; 131 | } 132 | 133 | function tokenInterpolationIdentifier(stream, state) { 134 | stream.eatWhile(/[\w_]/); 135 | state.tokenize = popInterpolationStack(state); 136 | return "variable"; 137 | } 138 | 139 | function tokenNestedComment(depth) { 140 | return function (stream, state) { 141 | var ch 142 | while (ch = stream.next()) { 143 | if (ch == "*" && stream.eat("/")) { 144 | if (depth == 1) { 145 | state.tokenize = null 146 | break 147 | } else { 148 | state.tokenize = tokenNestedComment(depth - 1) 149 | return state.tokenize(stream, state) 150 | } 151 | } else if (ch == "/" && stream.eat("*")) { 152 | state.tokenize = tokenNestedComment(depth + 1) 153 | return state.tokenize(stream, state) 154 | } 155 | } 156 | return "comment" 157 | } 158 | } 159 | 160 | CodeMirror.registerHelper("hintWords", "application/dart", keywords.concat(atoms).concat(builtins)); 161 | 162 | // This is needed to make loading through meta.js work. 163 | CodeMirror.defineMode("dart", function(conf) { 164 | return CodeMirror.getMode(conf, "application/dart"); 165 | }, "clike"); 166 | }); 167 | -------------------------------------------------------------------------------- /mode/diff/diff.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineMode("diff", function() { 15 | 16 | var TOKEN_NAMES = { 17 | '+': 'positive', 18 | '-': 'negative', 19 | '@': 'meta' 20 | }; 21 | 22 | return { 23 | token: function(stream) { 24 | var tw_pos = stream.string.search(/[\t ]+?$/); 25 | 26 | if (!stream.sol() || tw_pos === 0) { 27 | stream.skipToEnd(); 28 | return ("error " + ( 29 | TOKEN_NAMES[stream.string.charAt(0)] || '')).replace(/ $/, ''); 30 | } 31 | 32 | var token_name = TOKEN_NAMES[stream.peek()] || stream.skipToEnd(); 33 | 34 | if (tw_pos === -1) { 35 | stream.skipToEnd(); 36 | } else { 37 | stream.pos = tw_pos; 38 | } 39 | 40 | return token_name; 41 | } 42 | }; 43 | }); 44 | 45 | CodeMirror.defineMIME("text/x-diff", "diff"); 46 | 47 | }); 48 | -------------------------------------------------------------------------------- /mode/dockerfile/dockerfile.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror"), require("../../addon/mode/simple")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror", "../../addon/mode/simple"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | var from = "from"; 15 | var fromRegex = new RegExp("^(\\s*)\\b(" + from + ")\\b", "i"); 16 | 17 | var shells = ["run", "cmd", "entrypoint", "shell"]; 18 | var shellsAsArrayRegex = new RegExp("^(\\s*)(" + shells.join('|') + ")(\\s+\\[)", "i"); 19 | 20 | var expose = "expose"; 21 | var exposeRegex = new RegExp("^(\\s*)(" + expose + ")(\\s+)", "i"); 22 | 23 | var others = [ 24 | "arg", "from", "maintainer", "label", "env", 25 | "add", "copy", "volume", "user", 26 | "workdir", "onbuild", "stopsignal", "healthcheck", "shell" 27 | ]; 28 | 29 | // Collect all Dockerfile directives 30 | var instructions = [from, expose].concat(shells).concat(others), 31 | instructionRegex = "(" + instructions.join('|') + ")", 32 | instructionOnlyLine = new RegExp("^(\\s*)" + instructionRegex + "(\\s*)(#.*)?$", "i"), 33 | instructionWithArguments = new RegExp("^(\\s*)" + instructionRegex + "(\\s+)", "i"); 34 | 35 | CodeMirror.defineSimpleMode("dockerfile", { 36 | start: [ 37 | // Block comment: This is a line starting with a comment 38 | { 39 | regex: /^\s*#.*$/, 40 | sol: true, 41 | token: "comment" 42 | }, 43 | { 44 | regex: fromRegex, 45 | token: [null, "keyword"], 46 | sol: true, 47 | next: "from" 48 | }, 49 | // Highlight an instruction without any arguments (for convenience) 50 | { 51 | regex: instructionOnlyLine, 52 | token: [null, "keyword", null, "error"], 53 | sol: true 54 | }, 55 | { 56 | regex: shellsAsArrayRegex, 57 | token: [null, "keyword", null], 58 | sol: true, 59 | next: "array" 60 | }, 61 | { 62 | regex: exposeRegex, 63 | token: [null, "keyword", null], 64 | sol: true, 65 | next: "expose" 66 | }, 67 | // Highlight an instruction followed by arguments 68 | { 69 | regex: instructionWithArguments, 70 | token: [null, "keyword", null], 71 | sol: true, 72 | next: "arguments" 73 | }, 74 | { 75 | regex: /./, 76 | token: null 77 | } 78 | ], 79 | from: [ 80 | { 81 | regex: /\s*$/, 82 | token: null, 83 | next: "start" 84 | }, 85 | { 86 | // Line comment without instruction arguments is an error 87 | regex: /(\s*)(#.*)$/, 88 | token: [null, "error"], 89 | next: "start" 90 | }, 91 | { 92 | regex: /(\s*\S+\s+)(as)/i, 93 | token: [null, "keyword"], 94 | next: "start" 95 | }, 96 | // Fail safe return to start 97 | { 98 | token: null, 99 | next: "start" 100 | } 101 | ], 102 | single: [ 103 | { 104 | regex: /(?:[^\\']|\\.)/, 105 | token: "string" 106 | }, 107 | { 108 | regex: /'/, 109 | token: "string", 110 | pop: true 111 | } 112 | ], 113 | double: [ 114 | { 115 | regex: /(?:[^\\"]|\\.)/, 116 | token: "string" 117 | }, 118 | { 119 | regex: /"/, 120 | token: "string", 121 | pop: true 122 | } 123 | ], 124 | array: [ 125 | { 126 | regex: /\]/, 127 | token: null, 128 | next: "start" 129 | }, 130 | { 131 | regex: /"(?:[^\\"]|\\.)*"?/, 132 | token: "string" 133 | } 134 | ], 135 | expose: [ 136 | { 137 | regex: /\d+$/, 138 | token: "number", 139 | next: "start" 140 | }, 141 | { 142 | regex: /[^\d]+$/, 143 | token: null, 144 | next: "start" 145 | }, 146 | { 147 | regex: /\d+/, 148 | token: "number" 149 | }, 150 | { 151 | regex: /[^\d]+/, 152 | token: null 153 | }, 154 | // Fail safe return to start 155 | { 156 | token: null, 157 | next: "start" 158 | } 159 | ], 160 | arguments: [ 161 | { 162 | regex: /^\s*#.*$/, 163 | sol: true, 164 | token: "comment" 165 | }, 166 | { 167 | regex: /"(?:[^\\"]|\\.)*"?$/, 168 | token: "string", 169 | next: "start" 170 | }, 171 | { 172 | regex: /"/, 173 | token: "string", 174 | push: "double" 175 | }, 176 | { 177 | regex: /'(?:[^\\']|\\.)*'?$/, 178 | token: "string", 179 | next: "start" 180 | }, 181 | { 182 | regex: /'/, 183 | token: "string", 184 | push: "single" 185 | }, 186 | { 187 | regex: /[^#"']+[\\`]$/, 188 | token: null 189 | }, 190 | { 191 | regex: /[^#"']+$/, 192 | token: null, 193 | next: "start" 194 | }, 195 | { 196 | regex: /[^#"']+/, 197 | token: null 198 | }, 199 | // Fail safe return to start 200 | { 201 | token: null, 202 | next: "start" 203 | } 204 | ], 205 | meta: { 206 | lineComment: "#" 207 | } 208 | }); 209 | 210 | CodeMirror.defineMIME("text/x-dockerfile", "dockerfile"); 211 | }); 212 | -------------------------------------------------------------------------------- /mode/dtd/dtd.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | /* 5 | DTD mode 6 | Ported to CodeMirror by Peter Kroon 7 | Report bugs/issues here: https://github.com/codemirror/CodeMirror/issues 8 | GitHub: @peterkroon 9 | */ 10 | 11 | (function(mod) { 12 | if (typeof exports == "object" && typeof module == "object") // CommonJS 13 | mod(require("../../lib/codemirror")); 14 | else if (typeof define == "function" && define.amd) // AMD 15 | define(["../../lib/codemirror"], mod); 16 | else // Plain browser env 17 | mod(CodeMirror); 18 | })(function(CodeMirror) { 19 | "use strict"; 20 | 21 | CodeMirror.defineMode("dtd", function(config) { 22 | var indentUnit = config.indentUnit, type; 23 | function ret(style, tp) {type = tp; return style;} 24 | 25 | function tokenBase(stream, state) { 26 | var ch = stream.next(); 27 | 28 | if (ch == "<" && stream.eat("!") ) { 29 | if (stream.eatWhile(/[\-]/)) { 30 | state.tokenize = tokenSGMLComment; 31 | return tokenSGMLComment(stream, state); 32 | } else if (stream.eatWhile(/[\w]/)) return ret("keyword", "doindent"); 33 | } else if (ch == "<" && stream.eat("?")) { //xml declaration 34 | state.tokenize = inBlock("meta", "?>"); 35 | return ret("meta", ch); 36 | } else if (ch == "#" && stream.eatWhile(/[\w]/)) return ret("atom", "tag"); 37 | else if (ch == "|") return ret("keyword", "seperator"); 38 | else if (ch.match(/[\(\)\[\]\-\.,\+\?>]/)) return ret(null, ch);//if(ch === ">") return ret(null, "endtag"); else 39 | else if (ch.match(/[\[\]]/)) return ret("rule", ch); 40 | else if (ch == "\"" || ch == "'") { 41 | state.tokenize = tokenString(ch); 42 | return state.tokenize(stream, state); 43 | } else if (stream.eatWhile(/[a-zA-Z\?\+\d]/)) { 44 | var sc = stream.current(); 45 | if( sc.substr(sc.length-1,sc.length).match(/\?|\+/) !== null )stream.backUp(1); 46 | return ret("tag", "tag"); 47 | } else if (ch == "%" || ch == "*" ) return ret("number", "number"); 48 | else { 49 | stream.eatWhile(/[\w\\\-_%.{,]/); 50 | return ret(null, null); 51 | } 52 | } 53 | 54 | function tokenSGMLComment(stream, state) { 55 | var dashes = 0, ch; 56 | while ((ch = stream.next()) != null) { 57 | if (dashes >= 2 && ch == ">") { 58 | state.tokenize = tokenBase; 59 | break; 60 | } 61 | dashes = (ch == "-") ? dashes + 1 : 0; 62 | } 63 | return ret("comment", "comment"); 64 | } 65 | 66 | function tokenString(quote) { 67 | return function(stream, state) { 68 | var escaped = false, ch; 69 | while ((ch = stream.next()) != null) { 70 | if (ch == quote && !escaped) { 71 | state.tokenize = tokenBase; 72 | break; 73 | } 74 | escaped = !escaped && ch == "\\"; 75 | } 76 | return ret("string", "tag"); 77 | }; 78 | } 79 | 80 | function inBlock(style, terminator) { 81 | return function(stream, state) { 82 | while (!stream.eol()) { 83 | if (stream.match(terminator)) { 84 | state.tokenize = tokenBase; 85 | break; 86 | } 87 | stream.next(); 88 | } 89 | return style; 90 | }; 91 | } 92 | 93 | return { 94 | startState: function(base) { 95 | return {tokenize: tokenBase, 96 | baseIndent: base || 0, 97 | stack: []}; 98 | }, 99 | 100 | token: function(stream, state) { 101 | if (stream.eatSpace()) return null; 102 | var style = state.tokenize(stream, state); 103 | 104 | var context = state.stack[state.stack.length-1]; 105 | if (stream.current() == "[" || type === "doindent" || type == "[") state.stack.push("rule"); 106 | else if (type === "endtag") state.stack[state.stack.length-1] = "endtag"; 107 | else if (stream.current() == "]" || type == "]" || (type == ">" && context == "rule")) state.stack.pop(); 108 | else if (type == "[") state.stack.push("["); 109 | return style; 110 | }, 111 | 112 | indent: function(state, textAfter) { 113 | var n = state.stack.length; 114 | 115 | if( textAfter.match(/\]\s+|\]/) )n=n-1; 116 | else if(textAfter.substr(textAfter.length-1, textAfter.length) === ">"){ 117 | if(textAfter.substr(0,1) === "<") {} 118 | else if( type == "doindent" && textAfter.length > 1 ) {} 119 | else if( type == "doindent")n--; 120 | else if( type == ">" && textAfter.length > 1) {} 121 | else if( type == "tag" && textAfter !== ">") {} 122 | else if( type == "tag" && state.stack[state.stack.length-1] == "rule")n--; 123 | else if( type == "tag")n++; 124 | else if( textAfter === ">" && state.stack[state.stack.length-1] == "rule" && type === ">")n--; 125 | else if( textAfter === ">" && state.stack[state.stack.length-1] == "rule") {} 126 | else if( textAfter.substr(0,1) !== "<" && textAfter.substr(0,1) === ">" )n=n-1; 127 | else if( textAfter === ">") {} 128 | else n=n-1; 129 | //over rule them all 130 | if(type == null || type == "]")n--; 131 | } 132 | 133 | return state.baseIndent + n * indentUnit; 134 | }, 135 | 136 | electricChars: "]>" 137 | }; 138 | }); 139 | 140 | CodeMirror.defineMIME("application/xml-dtd", "dtd"); 141 | 142 | }); 143 | -------------------------------------------------------------------------------- /mode/eiffel/eiffel.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineMode("eiffel", function() { 15 | function wordObj(words) { 16 | var o = {}; 17 | for (var i = 0, e = words.length; i < e; ++i) o[words[i]] = true; 18 | return o; 19 | } 20 | var keywords = wordObj([ 21 | 'note', 22 | 'across', 23 | 'when', 24 | 'variant', 25 | 'until', 26 | 'unique', 27 | 'undefine', 28 | 'then', 29 | 'strip', 30 | 'select', 31 | 'retry', 32 | 'rescue', 33 | 'require', 34 | 'rename', 35 | 'reference', 36 | 'redefine', 37 | 'prefix', 38 | 'once', 39 | 'old', 40 | 'obsolete', 41 | 'loop', 42 | 'local', 43 | 'like', 44 | 'is', 45 | 'inspect', 46 | 'infix', 47 | 'include', 48 | 'if', 49 | 'frozen', 50 | 'from', 51 | 'external', 52 | 'export', 53 | 'ensure', 54 | 'end', 55 | 'elseif', 56 | 'else', 57 | 'do', 58 | 'creation', 59 | 'create', 60 | 'check', 61 | 'alias', 62 | 'agent', 63 | 'separate', 64 | 'invariant', 65 | 'inherit', 66 | 'indexing', 67 | 'feature', 68 | 'expanded', 69 | 'deferred', 70 | 'class', 71 | 'Void', 72 | 'True', 73 | 'Result', 74 | 'Precursor', 75 | 'False', 76 | 'Current', 77 | 'create', 78 | 'attached', 79 | 'detachable', 80 | 'as', 81 | 'and', 82 | 'implies', 83 | 'not', 84 | 'or' 85 | ]); 86 | var operators = wordObj([":=", "and then","and", "or","<<",">>"]); 87 | 88 | function chain(newtok, stream, state) { 89 | state.tokenize.push(newtok); 90 | return newtok(stream, state); 91 | } 92 | 93 | function tokenBase(stream, state) { 94 | if (stream.eatSpace()) return null; 95 | var ch = stream.next(); 96 | if (ch == '"'||ch == "'") { 97 | return chain(readQuoted(ch, "string"), stream, state); 98 | } else if (ch == "-"&&stream.eat("-")) { 99 | stream.skipToEnd(); 100 | return "comment"; 101 | } else if (ch == ":"&&stream.eat("=")) { 102 | return "operator"; 103 | } else if (/[0-9]/.test(ch)) { 104 | stream.eatWhile(/[xXbBCc0-9\.]/); 105 | stream.eat(/[\?\!]/); 106 | return "ident"; 107 | } else if (/[a-zA-Z_0-9]/.test(ch)) { 108 | stream.eatWhile(/[a-zA-Z_0-9]/); 109 | stream.eat(/[\?\!]/); 110 | return "ident"; 111 | } else if (/[=+\-\/*^%<>~]/.test(ch)) { 112 | stream.eatWhile(/[=+\-\/*^%<>~]/); 113 | return "operator"; 114 | } else { 115 | return null; 116 | } 117 | } 118 | 119 | function readQuoted(quote, style, unescaped) { 120 | return function(stream, state) { 121 | var escaped = false, ch; 122 | while ((ch = stream.next()) != null) { 123 | if (ch == quote && (unescaped || !escaped)) { 124 | state.tokenize.pop(); 125 | break; 126 | } 127 | escaped = !escaped && ch == "%"; 128 | } 129 | return style; 130 | }; 131 | } 132 | 133 | return { 134 | startState: function() { 135 | return {tokenize: [tokenBase]}; 136 | }, 137 | 138 | token: function(stream, state) { 139 | var style = state.tokenize[state.tokenize.length-1](stream, state); 140 | if (style == "ident") { 141 | var word = stream.current(); 142 | style = keywords.propertyIsEnumerable(stream.current()) ? "keyword" 143 | : operators.propertyIsEnumerable(stream.current()) ? "operator" 144 | : /^[A-Z][A-Z_0-9]*$/g.test(word) ? "tag" 145 | : /^0[bB][0-1]+$/g.test(word) ? "number" 146 | : /^0[cC][0-7]+$/g.test(word) ? "number" 147 | : /^0[xX][a-fA-F0-9]+$/g.test(word) ? "number" 148 | : /^([0-9]+\.[0-9]*)|([0-9]*\.[0-9]+)$/g.test(word) ? "number" 149 | : /^[0-9]+$/g.test(word) ? "number" 150 | : "variable"; 151 | } 152 | return style; 153 | }, 154 | lineComment: "--" 155 | }; 156 | }); 157 | 158 | CodeMirror.defineMIME("text/x-eiffel", "eiffel"); 159 | 160 | }); 161 | -------------------------------------------------------------------------------- /mode/factor/factor.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | // Factor syntax highlight - simple mode 5 | // 6 | // by Dimage Sapelkin (https://github.com/kerabromsmu) 7 | 8 | (function(mod) { 9 | if (typeof exports == "object" && typeof module == "object") // CommonJS 10 | mod(require("../../lib/codemirror"), require("../../addon/mode/simple")); 11 | else if (typeof define == "function" && define.amd) // AMD 12 | define(["../../lib/codemirror", "../../addon/mode/simple"], mod); 13 | else // Plain browser env 14 | mod(CodeMirror); 15 | })(function(CodeMirror) { 16 | "use strict"; 17 | 18 | CodeMirror.defineSimpleMode("factor", { 19 | // The start state contains the rules that are intially used 20 | start: [ 21 | // comments 22 | {regex: /#?!.*/, token: "comment"}, 23 | // strings """, multiline --> state 24 | {regex: /"""/, token: "string", next: "string3"}, 25 | {regex: /(STRING:)(\s)/, token: ["keyword", null], next: "string2"}, 26 | {regex: /\S*?"/, token: "string", next: "string"}, 27 | // numbers: dec, hex, unicode, bin, fractional, complex 28 | {regex: /(?:0x[\d,a-f]+)|(?:0o[0-7]+)|(?:0b[0,1]+)|(?:\-?\d+.?\d*)(?=\s)/, token: "number"}, 29 | //{regex: /[+-]?/} //fractional 30 | // definition: defining word, defined word, etc 31 | {regex: /((?:GENERIC)|\:?\:)(\s+)(\S+)(\s+)(\()/, token: ["keyword", null, "def", null, "bracket"], next: "stack"}, 32 | // method definition: defining word, type, defined word, etc 33 | {regex: /(M\:)(\s+)(\S+)(\s+)(\S+)/, token: ["keyword", null, "def", null, "tag"]}, 34 | // vocabulary using --> state 35 | {regex: /USING\:/, token: "keyword", next: "vocabulary"}, 36 | // vocabulary definition/use 37 | {regex: /(USE\:|IN\:)(\s+)(\S+)(?=\s|$)/, token: ["keyword", null, "tag"]}, 38 | // definition: a defining word, defined word 39 | {regex: /(\S+\:)(\s+)(\S+)(?=\s|$)/, token: ["keyword", null, "def"]}, 40 | // "keywords", incl. ; t f . [ ] { } defining words 41 | {regex: /(?:;|\\|t|f|if|loop|while|until|do|PRIVATE>| and the like 43 | {regex: /\S+[\)>\.\*\?]+(?=\s|$)/, token: "builtin"}, 44 | {regex: /[\)><]+\S+(?=\s|$)/, token: "builtin"}, 45 | // operators 46 | {regex: /(?:[\+\-\=\/\*<>])(?=\s|$)/, token: "keyword"}, 47 | // any id (?) 48 | {regex: /\S+/, token: "variable"}, 49 | {regex: /\s+|./, token: null} 50 | ], 51 | vocabulary: [ 52 | {regex: /;/, token: "keyword", next: "start"}, 53 | {regex: /\S+/, token: "tag"}, 54 | {regex: /\s+|./, token: null} 55 | ], 56 | string: [ 57 | {regex: /(?:[^\\]|\\.)*?"/, token: "string", next: "start"}, 58 | {regex: /.*/, token: "string"} 59 | ], 60 | string2: [ 61 | {regex: /^;/, token: "keyword", next: "start"}, 62 | {regex: /.*/, token: "string"} 63 | ], 64 | string3: [ 65 | {regex: /(?:[^\\]|\\.)*?"""/, token: "string", next: "start"}, 66 | {regex: /.*/, token: "string"} 67 | ], 68 | stack: [ 69 | {regex: /\)/, token: "bracket", next: "start"}, 70 | {regex: /--/, token: "bracket"}, 71 | {regex: /\S+/, token: "meta"}, 72 | {regex: /\s+|./, token: null} 73 | ], 74 | // The meta property contains global information about the mode. It 75 | // can contain properties like lineComment, which are supported by 76 | // all modes, and also directives like dontIndentStates, which are 77 | // specific to simple modes. 78 | meta: { 79 | dontIndentStates: ["start", "vocabulary", "string", "string3", "stack"], 80 | lineComment: [ "!", "#!" ] 81 | } 82 | }); 83 | 84 | CodeMirror.defineMIME("text/x-factor", "factor"); 85 | }); 86 | -------------------------------------------------------------------------------- /mode/fcl/fcl.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineMode("fcl", function(config) { 15 | var indentUnit = config.indentUnit; 16 | 17 | var keywords = { 18 | "term": true, 19 | "method": true, "accu": true, 20 | "rule": true, "then": true, "is": true, "and": true, "or": true, 21 | "if": true, "default": true 22 | }; 23 | 24 | var start_blocks = { 25 | "var_input": true, 26 | "var_output": true, 27 | "fuzzify": true, 28 | "defuzzify": true, 29 | "function_block": true, 30 | "ruleblock": true 31 | }; 32 | 33 | var end_blocks = { 34 | "end_ruleblock": true, 35 | "end_defuzzify": true, 36 | "end_function_block": true, 37 | "end_fuzzify": true, 38 | "end_var": true 39 | }; 40 | 41 | var atoms = { 42 | "true": true, "false": true, "nan": true, 43 | "real": true, "min": true, "max": true, "cog": true, "cogs": true 44 | }; 45 | 46 | var isOperatorChar = /[+\-*&^%:=<>!|\/]/; 47 | 48 | function tokenBase(stream, state) { 49 | var ch = stream.next(); 50 | 51 | if (/[\d\.]/.test(ch)) { 52 | if (ch == ".") { 53 | stream.match(/^[0-9]+([eE][\-+]?[0-9]+)?/); 54 | } else if (ch == "0") { 55 | stream.match(/^[xX][0-9a-fA-F]+/) || stream.match(/^0[0-7]+/); 56 | } else { 57 | stream.match(/^[0-9]*\.?[0-9]*([eE][\-+]?[0-9]+)?/); 58 | } 59 | return "number"; 60 | } 61 | 62 | if (ch == "/" || ch == "(") { 63 | if (stream.eat("*")) { 64 | state.tokenize = tokenComment; 65 | return tokenComment(stream, state); 66 | } 67 | if (stream.eat("/")) { 68 | stream.skipToEnd(); 69 | return "comment"; 70 | } 71 | } 72 | if (isOperatorChar.test(ch)) { 73 | stream.eatWhile(isOperatorChar); 74 | return "operator"; 75 | } 76 | stream.eatWhile(/[\w\$_\xa1-\uffff]/); 77 | 78 | var cur = stream.current().toLowerCase(); 79 | if (keywords.propertyIsEnumerable(cur) || 80 | start_blocks.propertyIsEnumerable(cur) || 81 | end_blocks.propertyIsEnumerable(cur)) { 82 | return "keyword"; 83 | } 84 | if (atoms.propertyIsEnumerable(cur)) return "atom"; 85 | return "variable"; 86 | } 87 | 88 | 89 | function tokenComment(stream, state) { 90 | var maybeEnd = false, ch; 91 | while (ch = stream.next()) { 92 | if ((ch == "/" || ch == ")") && maybeEnd) { 93 | state.tokenize = tokenBase; 94 | break; 95 | } 96 | maybeEnd = (ch == "*"); 97 | } 98 | return "comment"; 99 | } 100 | 101 | function Context(indented, column, type, align, prev) { 102 | this.indented = indented; 103 | this.column = column; 104 | this.type = type; 105 | this.align = align; 106 | this.prev = prev; 107 | } 108 | 109 | function pushContext(state, col, type) { 110 | return state.context = new Context(state.indented, col, type, null, state.context); 111 | } 112 | 113 | function popContext(state) { 114 | if (!state.context.prev) return; 115 | var t = state.context.type; 116 | if (t == "end_block") 117 | state.indented = state.context.indented; 118 | return state.context = state.context.prev; 119 | } 120 | 121 | // Interface 122 | 123 | return { 124 | startState: function(basecolumn) { 125 | return { 126 | tokenize: null, 127 | context: new Context((basecolumn || 0) - indentUnit, 0, "top", false), 128 | indented: 0, 129 | startOfLine: true 130 | }; 131 | }, 132 | 133 | token: function(stream, state) { 134 | var ctx = state.context; 135 | if (stream.sol()) { 136 | if (ctx.align == null) ctx.align = false; 137 | state.indented = stream.indentation(); 138 | state.startOfLine = true; 139 | } 140 | if (stream.eatSpace()) return null; 141 | 142 | var style = (state.tokenize || tokenBase)(stream, state); 143 | if (style == "comment") return style; 144 | if (ctx.align == null) ctx.align = true; 145 | 146 | var cur = stream.current().toLowerCase(); 147 | 148 | if (start_blocks.propertyIsEnumerable(cur)) pushContext(state, stream.column(), "end_block"); 149 | else if (end_blocks.propertyIsEnumerable(cur)) popContext(state); 150 | 151 | state.startOfLine = false; 152 | return style; 153 | }, 154 | 155 | indent: function(state, textAfter) { 156 | if (state.tokenize != tokenBase && state.tokenize != null) return 0; 157 | var ctx = state.context; 158 | 159 | var closing = end_blocks.propertyIsEnumerable(textAfter); 160 | if (ctx.align) return ctx.column + (closing ? 0 : 1); 161 | else return ctx.indented + (closing ? 0 : indentUnit); 162 | }, 163 | 164 | electricChars: "ryk", 165 | fold: "brace", 166 | blockCommentStart: "(*", 167 | blockCommentEnd: "*)", 168 | lineComment: "//" 169 | }; 170 | }); 171 | 172 | CodeMirror.defineMIME("text/x-fcl", "fcl"); 173 | }); 174 | -------------------------------------------------------------------------------- /mode/forth/forth.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | // Author: Aliaksei Chapyzhenka 5 | 6 | (function(mod) { 7 | if (typeof exports == "object" && typeof module == "object") // CommonJS 8 | mod(require("../../lib/codemirror")); 9 | else if (typeof define == "function" && define.amd) // AMD 10 | define(["../../lib/codemirror"], mod); 11 | else // Plain browser env 12 | mod(CodeMirror); 13 | })(function(CodeMirror) { 14 | "use strict"; 15 | 16 | function toWordList(words) { 17 | var ret = []; 18 | words.split(' ').forEach(function(e){ 19 | ret.push({name: e}); 20 | }); 21 | return ret; 22 | } 23 | 24 | var coreWordList = toWordList( 25 | 'INVERT AND OR XOR\ 26 | 2* 2/ LSHIFT RSHIFT\ 27 | 0= = 0< < > U< MIN MAX\ 28 | 2DROP 2DUP 2OVER 2SWAP ?DUP DEPTH DROP DUP OVER ROT SWAP\ 29 | >R R> R@\ 30 | + - 1+ 1- ABS NEGATE\ 31 | S>D * M* UM*\ 32 | FM/MOD SM/REM UM/MOD */ */MOD / /MOD MOD\ 33 | HERE , @ ! CELL+ CELLS C, C@ C! CHARS 2@ 2!\ 34 | ALIGN ALIGNED +! ALLOT\ 35 | CHAR [CHAR] [ ] BL\ 36 | FIND EXECUTE IMMEDIATE COUNT LITERAL STATE\ 37 | ; DOES> >BODY\ 38 | EVALUATE\ 39 | SOURCE >IN\ 40 | <# # #S #> HOLD SIGN BASE >NUMBER HEX DECIMAL\ 41 | FILL MOVE\ 42 | . CR EMIT SPACE SPACES TYPE U. .R U.R\ 43 | ACCEPT\ 44 | TRUE FALSE\ 45 | <> U> 0<> 0>\ 46 | NIP TUCK ROLL PICK\ 47 | 2>R 2R@ 2R>\ 48 | WITHIN UNUSED MARKER\ 49 | I J\ 50 | TO\ 51 | COMPILE, [COMPILE]\ 52 | SAVE-INPUT RESTORE-INPUT\ 53 | PAD ERASE\ 54 | 2LITERAL DNEGATE\ 55 | D- D+ D0< D0= D2* D2/ D< D= DMAX DMIN D>S DABS\ 56 | M+ M*/ D. D.R 2ROT DU<\ 57 | CATCH THROW\ 58 | FREE RESIZE ALLOCATE\ 59 | CS-PICK CS-ROLL\ 60 | GET-CURRENT SET-CURRENT FORTH-WORDLIST GET-ORDER SET-ORDER\ 61 | PREVIOUS SEARCH-WORDLIST WORDLIST FIND ALSO ONLY FORTH DEFINITIONS ORDER\ 62 | -TRAILING /STRING SEARCH COMPARE CMOVE CMOVE> BLANK SLITERAL'); 63 | 64 | var immediateWordList = toWordList('IF ELSE THEN BEGIN WHILE REPEAT UNTIL RECURSE [IF] [ELSE] [THEN] ?DO DO LOOP +LOOP UNLOOP LEAVE EXIT AGAIN CASE OF ENDOF ENDCASE'); 65 | 66 | CodeMirror.defineMode('forth', function() { 67 | function searchWordList (wordList, word) { 68 | var i; 69 | for (i = wordList.length - 1; i >= 0; i--) { 70 | if (wordList[i].name === word.toUpperCase()) { 71 | return wordList[i]; 72 | } 73 | } 74 | return undefined; 75 | } 76 | return { 77 | startState: function() { 78 | return { 79 | state: '', 80 | base: 10, 81 | coreWordList: coreWordList, 82 | immediateWordList: immediateWordList, 83 | wordList: [] 84 | }; 85 | }, 86 | token: function (stream, stt) { 87 | var mat; 88 | if (stream.eatSpace()) { 89 | return null; 90 | } 91 | if (stt.state === '') { // interpretation 92 | if (stream.match(/^(\]|:NONAME)(\s|$)/i)) { 93 | stt.state = ' compilation'; 94 | return 'builtin compilation'; 95 | } 96 | mat = stream.match(/^(\:)\s+(\S+)(\s|$)+/); 97 | if (mat) { 98 | stt.wordList.push({name: mat[2].toUpperCase()}); 99 | stt.state = ' compilation'; 100 | return 'def' + stt.state; 101 | } 102 | mat = stream.match(/^(VARIABLE|2VARIABLE|CONSTANT|2CONSTANT|CREATE|POSTPONE|VALUE|WORD)\s+(\S+)(\s|$)+/i); 103 | if (mat) { 104 | stt.wordList.push({name: mat[2].toUpperCase()}); 105 | return 'def' + stt.state; 106 | } 107 | mat = stream.match(/^(\'|\[\'\])\s+(\S+)(\s|$)+/); 108 | if (mat) { 109 | return 'builtin' + stt.state; 110 | } 111 | } else { // compilation 112 | // ; [ 113 | if (stream.match(/^(\;|\[)(\s)/)) { 114 | stt.state = ''; 115 | stream.backUp(1); 116 | return 'builtin compilation'; 117 | } 118 | if (stream.match(/^(\;|\[)($)/)) { 119 | stt.state = ''; 120 | return 'builtin compilation'; 121 | } 122 | if (stream.match(/^(POSTPONE)\s+\S+(\s|$)+/)) { 123 | return 'builtin'; 124 | } 125 | } 126 | 127 | // dynamic wordlist 128 | mat = stream.match(/^(\S+)(\s+|$)/); 129 | if (mat) { 130 | if (searchWordList(stt.wordList, mat[1]) !== undefined) { 131 | return 'variable' + stt.state; 132 | } 133 | 134 | // comments 135 | if (mat[1] === '\\') { 136 | stream.skipToEnd(); 137 | return 'comment' + stt.state; 138 | } 139 | 140 | // core words 141 | if (searchWordList(stt.coreWordList, mat[1]) !== undefined) { 142 | return 'builtin' + stt.state; 143 | } 144 | if (searchWordList(stt.immediateWordList, mat[1]) !== undefined) { 145 | return 'keyword' + stt.state; 146 | } 147 | 148 | if (mat[1] === '(') { 149 | stream.eatWhile(function (s) { return s !== ')'; }); 150 | stream.eat(')'); 151 | return 'comment' + stt.state; 152 | } 153 | 154 | // // strings 155 | if (mat[1] === '.(') { 156 | stream.eatWhile(function (s) { return s !== ')'; }); 157 | stream.eat(')'); 158 | return 'string' + stt.state; 159 | } 160 | if (mat[1] === 'S"' || mat[1] === '."' || mat[1] === 'C"') { 161 | stream.eatWhile(function (s) { return s !== '"'; }); 162 | stream.eat('"'); 163 | return 'string' + stt.state; 164 | } 165 | 166 | // numbers 167 | if (mat[1] - 0xfffffffff) { 168 | return 'number' + stt.state; 169 | } 170 | // if (mat[1].match(/^[-+]?[0-9]+\.[0-9]*/)) { 171 | // return 'number' + stt.state; 172 | // } 173 | 174 | return 'atom' + stt.state; 175 | } 176 | } 177 | }; 178 | }); 179 | CodeMirror.defineMIME("text/x-forth", "forth"); 180 | }); 181 | -------------------------------------------------------------------------------- /mode/gfm/gfm.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror"), require("../markdown/markdown"), require("../../addon/mode/overlay")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror", "../markdown/markdown", "../../addon/mode/overlay"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | var urlRE = /^((?:(?:aaas?|about|acap|adiumxtra|af[ps]|aim|apt|attachment|aw|beshare|bitcoin|bolo|callto|cap|chrome(?:-extension)?|cid|coap|com-eventbrite-attendee|content|crid|cvs|data|dav|dict|dlna-(?:playcontainer|playsingle)|dns|doi|dtn|dvb|ed2k|facetime|feed|file|finger|fish|ftp|geo|gg|git|gizmoproject|go|gopher|gtalk|h323|hcp|https?|iax|icap|icon|im|imap|info|ipn|ipp|irc[6s]?|iris(?:\.beep|\.lwz|\.xpc|\.xpcs)?|itms|jar|javascript|jms|keyparc|lastfm|ldaps?|magnet|mailto|maps|market|message|mid|mms|ms-help|msnim|msrps?|mtqp|mumble|mupdate|mvn|news|nfs|nih?|nntp|notes|oid|opaquelocktoken|palm|paparazzi|platform|pop|pres|proxy|psyc|query|res(?:ource)?|rmi|rsync|rtmp|rtsp|secondlife|service|session|sftp|sgn|shttp|sieve|sips?|skype|sm[bs]|snmp|soap\.beeps?|soldat|spotify|ssh|steam|svn|tag|teamspeak|tel(?:net)?|tftp|things|thismessage|tip|tn3270|tv|udp|unreal|urn|ut2004|vemmi|ventrilo|view-source|webcal|wss?|wtai|wyciwyg|xcon(?:-userid)?|xfire|xmlrpc\.beeps?|xmpp|xri|ymsgr|z39\.50[rs]?):(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]|\([^\s()<>]*\))+(?:\([^\s()<>]*\)|[^\s`*!()\[\]{};:'".,<>?«»“”‘’]))/i 15 | 16 | CodeMirror.defineMode("gfm", function(config, modeConfig) { 17 | var codeDepth = 0; 18 | function blankLine(state) { 19 | state.code = false; 20 | return null; 21 | } 22 | var gfmOverlay = { 23 | startState: function() { 24 | return { 25 | code: false, 26 | codeBlock: false, 27 | ateSpace: false 28 | }; 29 | }, 30 | copyState: function(s) { 31 | return { 32 | code: s.code, 33 | codeBlock: s.codeBlock, 34 | ateSpace: s.ateSpace 35 | }; 36 | }, 37 | token: function(stream, state) { 38 | state.combineTokens = null; 39 | 40 | // Hack to prevent formatting override inside code blocks (block and inline) 41 | if (state.codeBlock) { 42 | if (stream.match(/^```+/)) { 43 | state.codeBlock = false; 44 | return null; 45 | } 46 | stream.skipToEnd(); 47 | return null; 48 | } 49 | if (stream.sol()) { 50 | state.code = false; 51 | } 52 | if (stream.sol() && stream.match(/^```+/)) { 53 | stream.skipToEnd(); 54 | state.codeBlock = true; 55 | return null; 56 | } 57 | // If this block is changed, it may need to be updated in Markdown mode 58 | if (stream.peek() === '`') { 59 | stream.next(); 60 | var before = stream.pos; 61 | stream.eatWhile('`'); 62 | var difference = 1 + stream.pos - before; 63 | if (!state.code) { 64 | codeDepth = difference; 65 | state.code = true; 66 | } else { 67 | if (difference === codeDepth) { // Must be exact 68 | state.code = false; 69 | } 70 | } 71 | return null; 72 | } else if (state.code) { 73 | stream.next(); 74 | return null; 75 | } 76 | // Check if space. If so, links can be formatted later on 77 | if (stream.eatSpace()) { 78 | state.ateSpace = true; 79 | return null; 80 | } 81 | if (stream.sol() || state.ateSpace) { 82 | state.ateSpace = false; 83 | if (modeConfig.gitHubSpice !== false) { 84 | if(stream.match(/^(?:[a-zA-Z0-9\-_]+\/)?(?:[a-zA-Z0-9\-_]+@)?(?=.{0,6}\d)(?:[a-f0-9]{7,40}\b)/)) { 85 | // User/Project@SHA 86 | // User@SHA 87 | // SHA 88 | state.combineTokens = true; 89 | return "link"; 90 | } else if (stream.match(/^(?:[a-zA-Z0-9\-_]+\/)?(?:[a-zA-Z0-9\-_]+)?#[0-9]+\b/)) { 91 | // User/Project#Num 92 | // User#Num 93 | // #Num 94 | state.combineTokens = true; 95 | return "link"; 96 | } 97 | } 98 | } 99 | if (stream.match(urlRE) && 100 | stream.string.slice(stream.start - 2, stream.start) != "](" && 101 | (stream.start == 0 || /\W/.test(stream.string.charAt(stream.start - 1)))) { 102 | // URLs 103 | // Taken from http://daringfireball.net/2010/07/improved_regex_for_matching_urls 104 | // And then (issue #1160) simplified to make it not crash the Chrome Regexp engine 105 | // And then limited url schemes to the CommonMark list, so foo:bar isn't matched as a URL 106 | state.combineTokens = true; 107 | return "link"; 108 | } 109 | stream.next(); 110 | return null; 111 | }, 112 | blankLine: blankLine 113 | }; 114 | 115 | var markdownConfig = { 116 | taskLists: true, 117 | strikethrough: true, 118 | emoji: true 119 | }; 120 | for (var attr in modeConfig) { 121 | markdownConfig[attr] = modeConfig[attr]; 122 | } 123 | markdownConfig.name = "markdown"; 124 | return CodeMirror.overlayMode(CodeMirror.getMode(config, markdownConfig), gfmOverlay); 125 | 126 | }, "markdown"); 127 | 128 | CodeMirror.defineMIME("text/x-gfm", "gfm"); 129 | }); 130 | -------------------------------------------------------------------------------- /mode/haml/haml.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror"), require("../htmlmixed/htmlmixed"), require("../ruby/ruby")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror", "../htmlmixed/htmlmixed", "../ruby/ruby"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | // full haml mode. This handled embedded ruby and html fragments too 15 | CodeMirror.defineMode("haml", function(config) { 16 | var htmlMode = CodeMirror.getMode(config, {name: "htmlmixed"}); 17 | var rubyMode = CodeMirror.getMode(config, "ruby"); 18 | 19 | function rubyInQuote(endQuote) { 20 | return function(stream, state) { 21 | var ch = stream.peek(); 22 | if (ch == endQuote && state.rubyState.tokenize.length == 1) { 23 | // step out of ruby context as it seems to complete processing all the braces 24 | stream.next(); 25 | state.tokenize = html; 26 | return "closeAttributeTag"; 27 | } else { 28 | return ruby(stream, state); 29 | } 30 | }; 31 | } 32 | 33 | function ruby(stream, state) { 34 | if (stream.match("-#")) { 35 | stream.skipToEnd(); 36 | return "comment"; 37 | } 38 | return rubyMode.token(stream, state.rubyState); 39 | } 40 | 41 | function html(stream, state) { 42 | var ch = stream.peek(); 43 | 44 | // handle haml declarations. All declarations that cant be handled here 45 | // will be passed to html mode 46 | if (state.previousToken.style == "comment" ) { 47 | if (state.indented > state.previousToken.indented) { 48 | stream.skipToEnd(); 49 | return "commentLine"; 50 | } 51 | } 52 | 53 | if (state.startOfLine) { 54 | if (ch == "!" && stream.match("!!")) { 55 | stream.skipToEnd(); 56 | return "tag"; 57 | } else if (stream.match(/^%[\w:#\.]+=/)) { 58 | state.tokenize = ruby; 59 | return "hamlTag"; 60 | } else if (stream.match(/^%[\w:]+/)) { 61 | return "hamlTag"; 62 | } else if (ch == "/" ) { 63 | stream.skipToEnd(); 64 | return "comment"; 65 | } 66 | } 67 | 68 | if (state.startOfLine || state.previousToken.style == "hamlTag") { 69 | if ( ch == "#" || ch == ".") { 70 | stream.match(/[\w-#\.]*/); 71 | return "hamlAttribute"; 72 | } 73 | } 74 | 75 | // donot handle --> as valid ruby, make it HTML close comment instead 76 | if (state.startOfLine && !stream.match("-->", false) && (ch == "=" || ch == "-" )) { 77 | state.tokenize = ruby; 78 | return state.tokenize(stream, state); 79 | } 80 | 81 | if (state.previousToken.style == "hamlTag" || 82 | state.previousToken.style == "closeAttributeTag" || 83 | state.previousToken.style == "hamlAttribute") { 84 | if (ch == "(") { 85 | state.tokenize = rubyInQuote(")"); 86 | return state.tokenize(stream, state); 87 | } else if (ch == "{") { 88 | if (!stream.match(/^\{%.*/)) { 89 | state.tokenize = rubyInQuote("}"); 90 | return state.tokenize(stream, state); 91 | } 92 | } 93 | } 94 | 95 | return htmlMode.token(stream, state.htmlState); 96 | } 97 | 98 | return { 99 | // default to html mode 100 | startState: function() { 101 | var htmlState = CodeMirror.startState(htmlMode); 102 | var rubyState = CodeMirror.startState(rubyMode); 103 | return { 104 | htmlState: htmlState, 105 | rubyState: rubyState, 106 | indented: 0, 107 | previousToken: { style: null, indented: 0}, 108 | tokenize: html 109 | }; 110 | }, 111 | 112 | copyState: function(state) { 113 | return { 114 | htmlState : CodeMirror.copyState(htmlMode, state.htmlState), 115 | rubyState: CodeMirror.copyState(rubyMode, state.rubyState), 116 | indented: state.indented, 117 | previousToken: state.previousToken, 118 | tokenize: state.tokenize 119 | }; 120 | }, 121 | 122 | token: function(stream, state) { 123 | if (stream.sol()) { 124 | state.indented = stream.indentation(); 125 | state.startOfLine = true; 126 | } 127 | if (stream.eatSpace()) return null; 128 | var style = state.tokenize(stream, state); 129 | state.startOfLine = false; 130 | // dont record comment line as we only want to measure comment line with 131 | // the opening comment block 132 | if (style && style != "commentLine") { 133 | state.previousToken = { style: style, indented: state.indented }; 134 | } 135 | // if current state is ruby and the previous token is not `,` reset the 136 | // tokenize to html 137 | if (stream.eol() && state.tokenize == ruby) { 138 | stream.backUp(1); 139 | var ch = stream.peek(); 140 | stream.next(); 141 | if (ch && ch != ",") { 142 | state.tokenize = html; 143 | } 144 | } 145 | // reprocess some of the specific style tag when finish setting previousToken 146 | if (style == "hamlTag") { 147 | style = "tag"; 148 | } else if (style == "commentLine") { 149 | style = "comment"; 150 | } else if (style == "hamlAttribute") { 151 | style = "attribute"; 152 | } else if (style == "closeAttributeTag") { 153 | style = null; 154 | } 155 | return style; 156 | } 157 | }; 158 | }, "htmlmixed", "ruby"); 159 | 160 | CodeMirror.defineMIME("text/x-haml", "haml"); 161 | }); 162 | -------------------------------------------------------------------------------- /mode/handlebars/handlebars.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror"), require("../../addon/mode/simple"), require("../../addon/mode/multiplex")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror", "../../addon/mode/simple", "../../addon/mode/multiplex"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineSimpleMode("handlebars-tags", { 15 | start: [ 16 | { regex: /\{\{\{/, push: "handlebars_raw", token: "tag" }, 17 | { regex: /\{\{!--/, push: "dash_comment", token: "comment" }, 18 | { regex: /\{\{!/, push: "comment", token: "comment" }, 19 | { regex: /\{\{/, push: "handlebars", token: "tag" } 20 | ], 21 | handlebars_raw: [ 22 | { regex: /\}\}\}/, pop: true, token: "tag" }, 23 | ], 24 | handlebars: [ 25 | { regex: /\}\}/, pop: true, token: "tag" }, 26 | 27 | // Double and single quotes 28 | { regex: /"(?:[^\\"]|\\.)*"?/, token: "string" }, 29 | { regex: /'(?:[^\\']|\\.)*'?/, token: "string" }, 30 | 31 | // Handlebars keywords 32 | { regex: />|[#\/]([A-Za-z_]\w*)/, token: "keyword" }, 33 | { regex: /(?:else|this)\b/, token: "keyword" }, 34 | 35 | // Numeral 36 | { regex: /\d+/i, token: "number" }, 37 | 38 | // Atoms like = and . 39 | { regex: /=|~|@|true|false/, token: "atom" }, 40 | 41 | // Paths 42 | { regex: /(?:\.\.\/)*(?:[A-Za-z_][\w\.]*)+/, token: "variable-2" } 43 | ], 44 | dash_comment: [ 45 | { regex: /--\}\}/, pop: true, token: "comment" }, 46 | 47 | // Commented code 48 | { regex: /./, token: "comment"} 49 | ], 50 | comment: [ 51 | { regex: /\}\}/, pop: true, token: "comment" }, 52 | { regex: /./, token: "comment" } 53 | ], 54 | meta: { 55 | blockCommentStart: "{{--", 56 | blockCommentEnd: "--}}" 57 | } 58 | }); 59 | 60 | CodeMirror.defineMode("handlebars", function(config, parserConfig) { 61 | var handlebars = CodeMirror.getMode(config, "handlebars-tags"); 62 | if (!parserConfig || !parserConfig.base) return handlebars; 63 | return CodeMirror.multiplexingMode( 64 | CodeMirror.getMode(config, parserConfig.base), 65 | {open: "{{", close: /\}\}\}?/, mode: handlebars, parseDelimiters: true} 66 | ); 67 | }); 68 | 69 | CodeMirror.defineMIME("text/x-handlebars-template", "handlebars"); 70 | }); 71 | -------------------------------------------------------------------------------- /mode/haskell-literate/haskell-literate.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function (mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror"), require("../haskell/haskell")) 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror", "../haskell/haskell"], mod) 9 | else // Plain browser env 10 | mod(CodeMirror) 11 | })(function (CodeMirror) { 12 | "use strict" 13 | 14 | CodeMirror.defineMode("haskell-literate", function (config, parserConfig) { 15 | var baseMode = CodeMirror.getMode(config, (parserConfig && parserConfig.base) || "haskell") 16 | 17 | return { 18 | startState: function () { 19 | return { 20 | inCode: false, 21 | baseState: CodeMirror.startState(baseMode) 22 | } 23 | }, 24 | token: function (stream, state) { 25 | if (stream.sol()) { 26 | if (state.inCode = stream.eat(">")) 27 | return "meta" 28 | } 29 | if (state.inCode) { 30 | return baseMode.token(stream, state.baseState) 31 | } else { 32 | stream.skipToEnd() 33 | return "comment" 34 | } 35 | }, 36 | innerMode: function (state) { 37 | return state.inCode ? {state: state.baseState, mode: baseMode} : null 38 | } 39 | } 40 | }, "haskell") 41 | 42 | CodeMirror.defineMIME("text/x-literate-haskell", "haskell-literate") 43 | }); 44 | -------------------------------------------------------------------------------- /mode/htmlembedded/htmlembedded.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror"), require("../htmlmixed/htmlmixed"), 7 | require("../../addon/mode/multiplex")); 8 | else if (typeof define == "function" && define.amd) // AMD 9 | define(["../../lib/codemirror", "../htmlmixed/htmlmixed", 10 | "../../addon/mode/multiplex"], mod); 11 | else // Plain browser env 12 | mod(CodeMirror); 13 | })(function(CodeMirror) { 14 | "use strict"; 15 | 16 | CodeMirror.defineMode("htmlembedded", function(config, parserConfig) { 17 | var closeComment = parserConfig.closeComment || "--%>" 18 | return CodeMirror.multiplexingMode(CodeMirror.getMode(config, "htmlmixed"), { 19 | open: parserConfig.openComment || "<%--", 20 | close: closeComment, 21 | delimStyle: "comment", 22 | mode: {token: function(stream) { 23 | stream.skipTo(closeComment) || stream.skipToEnd() 24 | return "comment" 25 | }} 26 | }, { 27 | open: parserConfig.open || parserConfig.scriptStartRegex || "<%", 28 | close: parserConfig.close || parserConfig.scriptEndRegex || "%>", 29 | mode: CodeMirror.getMode(config, parserConfig.scriptingModeSpec) 30 | }); 31 | }, "htmlmixed"); 32 | 33 | CodeMirror.defineMIME("application/x-ejs", {name: "htmlembedded", scriptingModeSpec:"javascript"}); 34 | CodeMirror.defineMIME("application/x-aspx", {name: "htmlembedded", scriptingModeSpec:"text/x-csharp"}); 35 | CodeMirror.defineMIME("application/x-jsp", {name: "htmlembedded", scriptingModeSpec:"text/x-java"}); 36 | CodeMirror.defineMIME("application/x-erb", {name: "htmlembedded", scriptingModeSpec:"ruby"}); 37 | }); 38 | -------------------------------------------------------------------------------- /mode/htmlmixed/htmlmixed.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror"), require("../xml/xml"), require("../javascript/javascript"), require("../css/css")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror", "../xml/xml", "../javascript/javascript", "../css/css"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | var defaultTags = { 15 | script: [ 16 | ["lang", /(javascript|babel)/i, "javascript"], 17 | ["type", /^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^module$|^$/i, "javascript"], 18 | ["type", /./, "text/plain"], 19 | [null, null, "javascript"] 20 | ], 21 | style: [ 22 | ["lang", /^css$/i, "css"], 23 | ["type", /^(text\/)?(x-)?(stylesheet|css)$/i, "css"], 24 | ["type", /./, "text/plain"], 25 | [null, null, "css"] 26 | ] 27 | }; 28 | 29 | function maybeBackup(stream, pat, style) { 30 | var cur = stream.current(), close = cur.search(pat); 31 | if (close > -1) { 32 | stream.backUp(cur.length - close); 33 | } else if (cur.match(/<\/?$/)) { 34 | stream.backUp(cur.length); 35 | if (!stream.match(pat, false)) stream.match(cur); 36 | } 37 | return style; 38 | } 39 | 40 | var attrRegexpCache = {}; 41 | function getAttrRegexp(attr) { 42 | var regexp = attrRegexpCache[attr]; 43 | if (regexp) return regexp; 44 | return attrRegexpCache[attr] = new RegExp("\\s+" + attr + "\\s*=\\s*('|\")?([^'\"]+)('|\")?\\s*"); 45 | } 46 | 47 | function getAttrValue(text, attr) { 48 | var match = text.match(getAttrRegexp(attr)) 49 | return match ? /^\s*(.*?)\s*$/.exec(match[2])[1] : "" 50 | } 51 | 52 | function getTagRegexp(tagName, anchored) { 53 | return new RegExp((anchored ? "^" : "") + "<\/\s*" + tagName + "\s*>", "i"); 54 | } 55 | 56 | function addTags(from, to) { 57 | for (var tag in from) { 58 | var dest = to[tag] || (to[tag] = []); 59 | var source = from[tag]; 60 | for (var i = source.length - 1; i >= 0; i--) 61 | dest.unshift(source[i]) 62 | } 63 | } 64 | 65 | function findMatchingMode(tagInfo, tagText) { 66 | for (var i = 0; i < tagInfo.length; i++) { 67 | var spec = tagInfo[i]; 68 | if (!spec[0] || spec[1].test(getAttrValue(tagText, spec[0]))) return spec[2]; 69 | } 70 | } 71 | 72 | CodeMirror.defineMode("htmlmixed", function (config, parserConfig) { 73 | var htmlMode = CodeMirror.getMode(config, { 74 | name: "xml", 75 | htmlMode: true, 76 | multilineTagIndentFactor: parserConfig.multilineTagIndentFactor, 77 | multilineTagIndentPastTag: parserConfig.multilineTagIndentPastTag 78 | }); 79 | 80 | var tags = {}; 81 | var configTags = parserConfig && parserConfig.tags, configScript = parserConfig && parserConfig.scriptTypes; 82 | addTags(defaultTags, tags); 83 | if (configTags) addTags(configTags, tags); 84 | if (configScript) for (var i = configScript.length - 1; i >= 0; i--) 85 | tags.script.unshift(["type", configScript[i].matches, configScript[i].mode]) 86 | 87 | function html(stream, state) { 88 | var style = htmlMode.token(stream, state.htmlState), tag = /\btag\b/.test(style), tagName 89 | if (tag && !/[<>\s\/]/.test(stream.current()) && 90 | (tagName = state.htmlState.tagName && state.htmlState.tagName.toLowerCase()) && 91 | tags.hasOwnProperty(tagName)) { 92 | state.inTag = tagName + " " 93 | } else if (state.inTag && tag && />$/.test(stream.current())) { 94 | var inTag = /^([\S]+) (.*)/.exec(state.inTag) 95 | state.inTag = null 96 | var modeSpec = stream.current() == ">" && findMatchingMode(tags[inTag[1]], inTag[2]) 97 | var mode = CodeMirror.getMode(config, modeSpec) 98 | var endTagA = getTagRegexp(inTag[1], true), endTag = getTagRegexp(inTag[1], false); 99 | state.token = function (stream, state) { 100 | if (stream.match(endTagA, false)) { 101 | state.token = html; 102 | state.localState = state.localMode = null; 103 | return null; 104 | } 105 | return maybeBackup(stream, endTag, state.localMode.token(stream, state.localState)); 106 | }; 107 | state.localMode = mode; 108 | state.localState = CodeMirror.startState(mode, htmlMode.indent(state.htmlState, "", "")); 109 | } else if (state.inTag) { 110 | state.inTag += stream.current() 111 | if (stream.eol()) state.inTag += " " 112 | } 113 | return style; 114 | }; 115 | 116 | return { 117 | startState: function () { 118 | var state = CodeMirror.startState(htmlMode); 119 | return {token: html, inTag: null, localMode: null, localState: null, htmlState: state}; 120 | }, 121 | 122 | copyState: function (state) { 123 | var local; 124 | if (state.localState) { 125 | local = CodeMirror.copyState(state.localMode, state.localState); 126 | } 127 | return {token: state.token, inTag: state.inTag, 128 | localMode: state.localMode, localState: local, 129 | htmlState: CodeMirror.copyState(htmlMode, state.htmlState)}; 130 | }, 131 | 132 | token: function (stream, state) { 133 | return state.token(stream, state); 134 | }, 135 | 136 | indent: function (state, textAfter, line) { 137 | if (!state.localMode || /^\s*<\//.test(textAfter)) 138 | return htmlMode.indent(state.htmlState, textAfter, line); 139 | else if (state.localMode.indent) 140 | return state.localMode.indent(state.localState, textAfter, line); 141 | else 142 | return CodeMirror.Pass; 143 | }, 144 | 145 | innerMode: function (state) { 146 | return {state: state.localState || state.htmlState, mode: state.localMode || htmlMode}; 147 | } 148 | }; 149 | }, "xml", "javascript", "css"); 150 | 151 | CodeMirror.defineMIME("text/html", "htmlmixed"); 152 | }); 153 | -------------------------------------------------------------------------------- /mode/http/http.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineMode("http", function() { 15 | function failFirstLine(stream, state) { 16 | stream.skipToEnd(); 17 | state.cur = header; 18 | return "error"; 19 | } 20 | 21 | function start(stream, state) { 22 | if (stream.match(/^HTTP\/\d\.\d/)) { 23 | state.cur = responseStatusCode; 24 | return "keyword"; 25 | } else if (stream.match(/^[A-Z]+/) && /[ \t]/.test(stream.peek())) { 26 | state.cur = requestPath; 27 | return "keyword"; 28 | } else { 29 | return failFirstLine(stream, state); 30 | } 31 | } 32 | 33 | function responseStatusCode(stream, state) { 34 | var code = stream.match(/^\d+/); 35 | if (!code) return failFirstLine(stream, state); 36 | 37 | state.cur = responseStatusText; 38 | var status = Number(code[0]); 39 | if (status >= 100 && status < 200) { 40 | return "positive informational"; 41 | } else if (status >= 200 && status < 300) { 42 | return "positive success"; 43 | } else if (status >= 300 && status < 400) { 44 | return "positive redirect"; 45 | } else if (status >= 400 && status < 500) { 46 | return "negative client-error"; 47 | } else if (status >= 500 && status < 600) { 48 | return "negative server-error"; 49 | } else { 50 | return "error"; 51 | } 52 | } 53 | 54 | function responseStatusText(stream, state) { 55 | stream.skipToEnd(); 56 | state.cur = header; 57 | return null; 58 | } 59 | 60 | function requestPath(stream, state) { 61 | stream.eatWhile(/\S/); 62 | state.cur = requestProtocol; 63 | return "string-2"; 64 | } 65 | 66 | function requestProtocol(stream, state) { 67 | if (stream.match(/^HTTP\/\d\.\d$/)) { 68 | state.cur = header; 69 | return "keyword"; 70 | } else { 71 | return failFirstLine(stream, state); 72 | } 73 | } 74 | 75 | function header(stream) { 76 | if (stream.sol() && !stream.eat(/[ \t]/)) { 77 | if (stream.match(/^.*?:/)) { 78 | return "atom"; 79 | } else { 80 | stream.skipToEnd(); 81 | return "error"; 82 | } 83 | } else { 84 | stream.skipToEnd(); 85 | return "string"; 86 | } 87 | } 88 | 89 | function body(stream) { 90 | stream.skipToEnd(); 91 | return null; 92 | } 93 | 94 | return { 95 | token: function(stream, state) { 96 | var cur = state.cur; 97 | if (cur != header && cur != body && stream.eatSpace()) return null; 98 | return cur(stream, state); 99 | }, 100 | 101 | blankLine: function(state) { 102 | state.cur = body; 103 | }, 104 | 105 | startState: function() { 106 | return {cur: start}; 107 | } 108 | }; 109 | }); 110 | 111 | CodeMirror.defineMIME("message/http", "http"); 112 | 113 | }); 114 | -------------------------------------------------------------------------------- /mode/jinja2/jinja2.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineMode("jinja2", function() { 15 | var keywords = ["and", "as", "block", "endblock", "by", "cycle", "debug", "else", "elif", 16 | "extends", "filter", "endfilter", "firstof", "for", 17 | "endfor", "if", "endif", "ifchanged", "endifchanged", 18 | "ifequal", "endifequal", "ifnotequal", 19 | "endifnotequal", "in", "include", "load", "not", "now", "or", 20 | "parsed", "regroup", "reversed", "spaceless", 21 | "endspaceless", "ssi", "templatetag", "openblock", 22 | "closeblock", "openvariable", "closevariable", 23 | "openbrace", "closebrace", "opencomment", 24 | "closecomment", "widthratio", "url", "with", "endwith", 25 | "get_current_language", "trans", "endtrans", "noop", "blocktrans", 26 | "endblocktrans", "get_available_languages", 27 | "get_current_language_bidi", "plural"], 28 | operator = /^[+\-*&%=<>!?|~^]/, 29 | sign = /^[:\[\(\{]/, 30 | atom = ["true", "false"], 31 | number = /^(\d[+\-\*\/])?\d+(\.\d+)?/; 32 | 33 | keywords = new RegExp("((" + keywords.join(")|(") + "))\\b"); 34 | atom = new RegExp("((" + atom.join(")|(") + "))\\b"); 35 | 36 | function tokenBase (stream, state) { 37 | var ch = stream.peek(); 38 | 39 | //Comment 40 | if (state.incomment) { 41 | if(!stream.skipTo("#}")) { 42 | stream.skipToEnd(); 43 | } else { 44 | stream.eatWhile(/\#|}/); 45 | state.incomment = false; 46 | } 47 | return "comment"; 48 | //Tag 49 | } else if (state.intag) { 50 | //After operator 51 | if(state.operator) { 52 | state.operator = false; 53 | if(stream.match(atom)) { 54 | return "atom"; 55 | } 56 | if(stream.match(number)) { 57 | return "number"; 58 | } 59 | } 60 | //After sign 61 | if(state.sign) { 62 | state.sign = false; 63 | if(stream.match(atom)) { 64 | return "atom"; 65 | } 66 | if(stream.match(number)) { 67 | return "number"; 68 | } 69 | } 70 | 71 | if(state.instring) { 72 | if(ch == state.instring) { 73 | state.instring = false; 74 | } 75 | stream.next(); 76 | return "string"; 77 | } else if(ch == "'" || ch == '"') { 78 | state.instring = ch; 79 | stream.next(); 80 | return "string"; 81 | } else if(stream.match(state.intag + "}") || stream.eat("-") && stream.match(state.intag + "}")) { 82 | state.intag = false; 83 | return "tag"; 84 | } else if(stream.match(operator)) { 85 | state.operator = true; 86 | return "operator"; 87 | } else if(stream.match(sign)) { 88 | state.sign = true; 89 | } else { 90 | if(stream.eat(" ") || stream.sol()) { 91 | if(stream.match(keywords)) { 92 | return "keyword"; 93 | } 94 | if(stream.match(atom)) { 95 | return "atom"; 96 | } 97 | if(stream.match(number)) { 98 | return "number"; 99 | } 100 | if(stream.sol()) { 101 | stream.next(); 102 | } 103 | } else { 104 | stream.next(); 105 | } 106 | 107 | } 108 | return "variable"; 109 | } else if (stream.eat("{")) { 110 | if (stream.eat("#")) { 111 | state.incomment = true; 112 | if(!stream.skipTo("#}")) { 113 | stream.skipToEnd(); 114 | } else { 115 | stream.eatWhile(/\#|}/); 116 | state.incomment = false; 117 | } 118 | return "comment"; 119 | //Open tag 120 | } else if (ch = stream.eat(/\{|%/)) { 121 | //Cache close tag 122 | state.intag = ch; 123 | if(ch == "{") { 124 | state.intag = "}"; 125 | } 126 | stream.eat("-"); 127 | return "tag"; 128 | } 129 | } 130 | stream.next(); 131 | }; 132 | 133 | return { 134 | startState: function () { 135 | return {tokenize: tokenBase}; 136 | }, 137 | token: function (stream, state) { 138 | return state.tokenize(stream, state); 139 | }, 140 | blockCommentStart: "{#", 141 | blockCommentEnd: "#}" 142 | }; 143 | }); 144 | 145 | CodeMirror.defineMIME("text/jinja2", "jinja2"); 146 | }); 147 | -------------------------------------------------------------------------------- /mode/jsx/jsx.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror"), require("../xml/xml"), require("../javascript/javascript")) 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror", "../xml/xml", "../javascript/javascript"], mod) 9 | else // Plain browser env 10 | mod(CodeMirror) 11 | })(function(CodeMirror) { 12 | "use strict" 13 | 14 | // Depth means the amount of open braces in JS context, in XML 15 | // context 0 means not in tag, 1 means in tag, and 2 means in tag 16 | // and js block comment. 17 | function Context(state, mode, depth, prev) { 18 | this.state = state; this.mode = mode; this.depth = depth; this.prev = prev 19 | } 20 | 21 | function copyContext(context) { 22 | return new Context(CodeMirror.copyState(context.mode, context.state), 23 | context.mode, 24 | context.depth, 25 | context.prev && copyContext(context.prev)) 26 | } 27 | 28 | CodeMirror.defineMode("jsx", function(config, modeConfig) { 29 | var xmlMode = CodeMirror.getMode(config, {name: "xml", allowMissing: true, multilineTagIndentPastTag: false, allowMissingTagName: true}) 30 | var jsMode = CodeMirror.getMode(config, modeConfig && modeConfig.base || "javascript") 31 | 32 | function flatXMLIndent(state) { 33 | var tagName = state.tagName 34 | state.tagName = null 35 | var result = xmlMode.indent(state, "", "") 36 | state.tagName = tagName 37 | return result 38 | } 39 | 40 | function token(stream, state) { 41 | if (state.context.mode == xmlMode) 42 | return xmlToken(stream, state, state.context) 43 | else 44 | return jsToken(stream, state, state.context) 45 | } 46 | 47 | function xmlToken(stream, state, cx) { 48 | if (cx.depth == 2) { // Inside a JS /* */ comment 49 | if (stream.match(/^.*?\*\//)) cx.depth = 1 50 | else stream.skipToEnd() 51 | return "comment" 52 | } 53 | 54 | if (stream.peek() == "{") { 55 | xmlMode.skipAttribute(cx.state) 56 | 57 | var indent = flatXMLIndent(cx.state), xmlContext = cx.state.context 58 | // If JS starts on same line as tag 59 | if (xmlContext && stream.match(/^[^>]*>\s*$/, false)) { 60 | while (xmlContext.prev && !xmlContext.startOfLine) 61 | xmlContext = xmlContext.prev 62 | // If tag starts the line, use XML indentation level 63 | if (xmlContext.startOfLine) indent -= config.indentUnit 64 | // Else use JS indentation level 65 | else if (cx.prev.state.lexical) indent = cx.prev.state.lexical.indented 66 | // Else if inside of tag 67 | } else if (cx.depth == 1) { 68 | indent += config.indentUnit 69 | } 70 | 71 | state.context = new Context(CodeMirror.startState(jsMode, indent), 72 | jsMode, 0, state.context) 73 | return null 74 | } 75 | 76 | if (cx.depth == 1) { // Inside of tag 77 | if (stream.peek() == "<") { // Tag inside of tag 78 | xmlMode.skipAttribute(cx.state) 79 | state.context = new Context(CodeMirror.startState(xmlMode, flatXMLIndent(cx.state)), 80 | xmlMode, 0, state.context) 81 | return null 82 | } else if (stream.match("//")) { 83 | stream.skipToEnd() 84 | return "comment" 85 | } else if (stream.match("/*")) { 86 | cx.depth = 2 87 | return token(stream, state) 88 | } 89 | } 90 | 91 | var style = xmlMode.token(stream, cx.state), cur = stream.current(), stop 92 | if (/\btag\b/.test(style)) { 93 | if (/>$/.test(cur)) { 94 | if (cx.state.context) cx.depth = 0 95 | else state.context = state.context.prev 96 | } else if (/^ -1) { 100 | stream.backUp(cur.length - stop) 101 | } 102 | return style 103 | } 104 | 105 | function jsToken(stream, state, cx) { 106 | if (stream.peek() == "<" && jsMode.expressionAllowed(stream, cx.state)) { 107 | jsMode.skipExpression(cx.state) 108 | state.context = new Context(CodeMirror.startState(xmlMode, jsMode.indent(cx.state, "", "")), 109 | xmlMode, 0, state.context) 110 | return null 111 | } 112 | 113 | var style = jsMode.token(stream, cx.state) 114 | if (!style && cx.depth != null) { 115 | var cur = stream.current() 116 | if (cur == "{") { 117 | cx.depth++ 118 | } else if (cur == "}") { 119 | if (--cx.depth == 0) state.context = state.context.prev 120 | } 121 | } 122 | return style 123 | } 124 | 125 | return { 126 | startState: function() { 127 | return {context: new Context(CodeMirror.startState(jsMode), jsMode)} 128 | }, 129 | 130 | copyState: function(state) { 131 | return {context: copyContext(state.context)} 132 | }, 133 | 134 | token: token, 135 | 136 | indent: function(state, textAfter, fullLine) { 137 | return state.context.mode.indent(state.context.state, textAfter, fullLine) 138 | }, 139 | 140 | innerMode: function(state) { 141 | return state.context 142 | } 143 | } 144 | }, "xml", "javascript") 145 | 146 | CodeMirror.defineMIME("text/jsx", "jsx") 147 | CodeMirror.defineMIME("text/typescript-jsx", {name: "jsx", base: {name: "javascript", typescript: true}}) 148 | }); 149 | -------------------------------------------------------------------------------- /mode/mbox/mbox.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | var rfc2822 = [ 15 | "From", "Sender", "Reply-To", "To", "Cc", "Bcc", "Message-ID", 16 | "In-Reply-To", "References", "Resent-From", "Resent-Sender", "Resent-To", 17 | "Resent-Cc", "Resent-Bcc", "Resent-Message-ID", "Return-Path", "Received" 18 | ]; 19 | var rfc2822NoEmail = [ 20 | "Date", "Subject", "Comments", "Keywords", "Resent-Date" 21 | ]; 22 | 23 | CodeMirror.registerHelper("hintWords", "mbox", rfc2822.concat(rfc2822NoEmail)); 24 | 25 | var whitespace = /^[ \t]/; 26 | var separator = /^From /; // See RFC 4155 27 | var rfc2822Header = new RegExp("^(" + rfc2822.join("|") + "): "); 28 | var rfc2822HeaderNoEmail = new RegExp("^(" + rfc2822NoEmail.join("|") + "): "); 29 | var header = /^[^:]+:/; // Optional fields defined in RFC 2822 30 | var email = /^[^ ]+@[^ ]+/; 31 | var untilEmail = /^.*?(?=[^ ]+?@[^ ]+)/; 32 | var bracketedEmail = /^<.*?>/; 33 | var untilBracketedEmail = /^.*?(?=<.*>)/; 34 | 35 | function styleForHeader(header) { 36 | if (header === "Subject") return "header"; 37 | return "string"; 38 | } 39 | 40 | function readToken(stream, state) { 41 | if (stream.sol()) { 42 | // From last line 43 | state.inSeparator = false; 44 | if (state.inHeader && stream.match(whitespace)) { 45 | // Header folding 46 | return null; 47 | } else { 48 | state.inHeader = false; 49 | state.header = null; 50 | } 51 | 52 | if (stream.match(separator)) { 53 | state.inHeaders = true; 54 | state.inSeparator = true; 55 | return "atom"; 56 | } 57 | 58 | var match; 59 | var emailPermitted = false; 60 | if ((match = stream.match(rfc2822HeaderNoEmail)) || 61 | (emailPermitted = true) && (match = stream.match(rfc2822Header))) { 62 | state.inHeaders = true; 63 | state.inHeader = true; 64 | state.emailPermitted = emailPermitted; 65 | state.header = match[1]; 66 | return "atom"; 67 | } 68 | 69 | // Use vim's heuristics: recognize custom headers only if the line is in a 70 | // block of legitimate headers. 71 | if (state.inHeaders && (match = stream.match(header))) { 72 | state.inHeader = true; 73 | state.emailPermitted = true; 74 | state.header = match[1]; 75 | return "atom"; 76 | } 77 | 78 | state.inHeaders = false; 79 | stream.skipToEnd(); 80 | return null; 81 | } 82 | 83 | if (state.inSeparator) { 84 | if (stream.match(email)) return "link"; 85 | if (stream.match(untilEmail)) return "atom"; 86 | stream.skipToEnd(); 87 | return "atom"; 88 | } 89 | 90 | if (state.inHeader) { 91 | var style = styleForHeader(state.header); 92 | 93 | if (state.emailPermitted) { 94 | if (stream.match(bracketedEmail)) return style + " link"; 95 | if (stream.match(untilBracketedEmail)) return style; 96 | } 97 | stream.skipToEnd(); 98 | return style; 99 | } 100 | 101 | stream.skipToEnd(); 102 | return null; 103 | }; 104 | 105 | CodeMirror.defineMode("mbox", function() { 106 | return { 107 | startState: function() { 108 | return { 109 | // Is in a mbox separator 110 | inSeparator: false, 111 | // Is in a mail header 112 | inHeader: false, 113 | // If bracketed email is permitted. Only applicable when inHeader 114 | emailPermitted: false, 115 | // Name of current header 116 | header: null, 117 | // Is in a region of mail headers 118 | inHeaders: false 119 | }; 120 | }, 121 | token: readToken, 122 | blankLine: function(state) { 123 | state.inHeaders = state.inSeparator = state.inHeader = false; 124 | } 125 | }; 126 | }); 127 | 128 | CodeMirror.defineMIME("application/mbox", "mbox"); 129 | }); 130 | -------------------------------------------------------------------------------- /mode/mumps/mumps.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | /* 5 | This MUMPS Language script was constructed using vbscript.js as a template. 6 | */ 7 | 8 | (function(mod) { 9 | if (typeof exports == "object" && typeof module == "object") // CommonJS 10 | mod(require("../../lib/codemirror")); 11 | else if (typeof define == "function" && define.amd) // AMD 12 | define(["../../lib/codemirror"], mod); 13 | else // Plain browser env 14 | mod(CodeMirror); 15 | })(function(CodeMirror) { 16 | "use strict"; 17 | 18 | CodeMirror.defineMode("mumps", function() { 19 | function wordRegexp(words) { 20 | return new RegExp("^((" + words.join(")|(") + "))\\b", "i"); 21 | } 22 | 23 | var singleOperators = new RegExp("^[\\+\\-\\*/&#!_?\\\\<>=\\'\\[\\]]"); 24 | var doubleOperators = new RegExp("^(('=)|(<=)|(>=)|('>)|('<)|([[)|(]])|(^$))"); 25 | var singleDelimiters = new RegExp("^[\\.,:]"); 26 | var brackets = new RegExp("[()]"); 27 | var identifiers = new RegExp("^[%A-Za-z][A-Za-z0-9]*"); 28 | var commandKeywords = ["break","close","do","else","for","goto", "halt", "hang", "if", "job","kill","lock","merge","new","open", "quit", "read", "set", "tcommit", "trollback", "tstart", "use", "view", "write", "xecute", "b","c","d","e","f","g", "h", "i", "j","k","l","m","n","o", "q", "r", "s", "tc", "tro", "ts", "u", "v", "w", "x"]; 29 | // The following list includes instrinsic functions _and_ special variables 30 | var intrinsicFuncsWords = ["\\$ascii", "\\$char", "\\$data", "\\$ecode", "\\$estack", "\\$etrap", "\\$extract", "\\$find", "\\$fnumber", "\\$get", "\\$horolog", "\\$io", "\\$increment", "\\$job", "\\$justify", "\\$length", "\\$name", "\\$next", "\\$order", "\\$piece", "\\$qlength", "\\$qsubscript", "\\$query", "\\$quit", "\\$random", "\\$reverse", "\\$select", "\\$stack", "\\$test", "\\$text", "\\$translate", "\\$view", "\\$x", "\\$y", "\\$a", "\\$c", "\\$d", "\\$e", "\\$ec", "\\$es", "\\$et", "\\$f", "\\$fn", "\\$g", "\\$h", "\\$i", "\\$j", "\\$l", "\\$n", "\\$na", "\\$o", "\\$p", "\\$q", "\\$ql", "\\$qs", "\\$r", "\\$re", "\\$s", "\\$st", "\\$t", "\\$tr", "\\$v", "\\$z"]; 31 | var intrinsicFuncs = wordRegexp(intrinsicFuncsWords); 32 | var command = wordRegexp(commandKeywords); 33 | 34 | function tokenBase(stream, state) { 35 | if (stream.sol()) { 36 | state.label = true; 37 | state.commandMode = 0; 38 | } 39 | 40 | // The character has meaning in MUMPS. Ignoring consecutive 41 | // spaces would interfere with interpreting whether the next non-space 42 | // character belongs to the command or argument context. 43 | 44 | // Examine each character and update a mode variable whose interpretation is: 45 | // >0 => command 0 => argument <0 => command post-conditional 46 | var ch = stream.peek(); 47 | 48 | if (ch == " " || ch == "\t") { // Pre-process 49 | state.label = false; 50 | if (state.commandMode == 0) 51 | state.commandMode = 1; 52 | else if ((state.commandMode < 0) || (state.commandMode == 2)) 53 | state.commandMode = 0; 54 | } else if ((ch != ".") && (state.commandMode > 0)) { 55 | if (ch == ":") 56 | state.commandMode = -1; // SIS - Command post-conditional 57 | else 58 | state.commandMode = 2; 59 | } 60 | 61 | // Do not color parameter list as line tag 62 | if ((ch === "(") || (ch === "\u0009")) 63 | state.label = false; 64 | 65 | // MUMPS comment starts with ";" 66 | if (ch === ";") { 67 | stream.skipToEnd(); 68 | return "comment"; 69 | } 70 | 71 | // Number Literals // SIS/RLM - MUMPS permits canonic number followed by concatenate operator 72 | if (stream.match(/^[-+]?\d+(\.\d+)?([eE][-+]?\d+)?/)) 73 | return "number"; 74 | 75 | // Handle Strings 76 | if (ch == '"') { 77 | if (stream.skipTo('"')) { 78 | stream.next(); 79 | return "string"; 80 | } else { 81 | stream.skipToEnd(); 82 | return "error"; 83 | } 84 | } 85 | 86 | // Handle operators and Delimiters 87 | if (stream.match(doubleOperators) || stream.match(singleOperators)) 88 | return "operator"; 89 | 90 | // Prevents leading "." in DO block from falling through to error 91 | if (stream.match(singleDelimiters)) 92 | return null; 93 | 94 | if (brackets.test(ch)) { 95 | stream.next(); 96 | return "bracket"; 97 | } 98 | 99 | if (state.commandMode > 0 && stream.match(command)) 100 | return "variable-2"; 101 | 102 | if (stream.match(intrinsicFuncs)) 103 | return "builtin"; 104 | 105 | if (stream.match(identifiers)) 106 | return "variable"; 107 | 108 | // Detect dollar-sign when not a documented intrinsic function 109 | // "^" may introduce a GVN or SSVN - Color same as function 110 | if (ch === "$" || ch === "^") { 111 | stream.next(); 112 | return "builtin"; 113 | } 114 | 115 | // MUMPS Indirection 116 | if (ch === "@") { 117 | stream.next(); 118 | return "string-2"; 119 | } 120 | 121 | if (/[\w%]/.test(ch)) { 122 | stream.eatWhile(/[\w%]/); 123 | return "variable"; 124 | } 125 | 126 | // Handle non-detected items 127 | stream.next(); 128 | return "error"; 129 | } 130 | 131 | return { 132 | startState: function() { 133 | return { 134 | label: false, 135 | commandMode: 0 136 | }; 137 | }, 138 | 139 | token: function(stream, state) { 140 | var style = tokenBase(stream, state); 141 | if (state.label) return "tag"; 142 | return style; 143 | } 144 | }; 145 | }); 146 | 147 | CodeMirror.defineMIME("text/x-mumps", "mumps"); 148 | }); 149 | -------------------------------------------------------------------------------- /mode/octave/octave.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineMode("octave", function() { 15 | function wordRegexp(words) { 16 | return new RegExp("^((" + words.join(")|(") + "))\\b"); 17 | } 18 | 19 | var singleOperators = new RegExp("^[\\+\\-\\*/&|\\^~<>!@'\\\\]"); 20 | var singleDelimiters = new RegExp('^[\\(\\[\\{\\},:=;\\.]'); 21 | var doubleOperators = new RegExp("^((==)|(~=)|(<=)|(>=)|(<<)|(>>)|(\\.[\\+\\-\\*/\\^\\\\]))"); 22 | var doubleDelimiters = new RegExp("^((!=)|(\\+=)|(\\-=)|(\\*=)|(/=)|(&=)|(\\|=)|(\\^=))"); 23 | var tripleDelimiters = new RegExp("^((>>=)|(<<=))"); 24 | var expressionEnd = new RegExp("^[\\]\\)]"); 25 | var identifiers = new RegExp("^[_A-Za-z\xa1-\uffff][_A-Za-z0-9\xa1-\uffff]*"); 26 | 27 | var builtins = wordRegexp([ 28 | 'error', 'eval', 'function', 'abs', 'acos', 'atan', 'asin', 'cos', 29 | 'cosh', 'exp', 'log', 'prod', 'sum', 'log10', 'max', 'min', 'sign', 'sin', 'sinh', 30 | 'sqrt', 'tan', 'reshape', 'break', 'zeros', 'default', 'margin', 'round', 'ones', 31 | 'rand', 'syn', 'ceil', 'floor', 'size', 'clear', 'zeros', 'eye', 'mean', 'std', 'cov', 32 | 'det', 'eig', 'inv', 'norm', 'rank', 'trace', 'expm', 'logm', 'sqrtm', 'linspace', 'plot', 33 | 'title', 'xlabel', 'ylabel', 'legend', 'text', 'grid', 'meshgrid', 'mesh', 'num2str', 34 | 'fft', 'ifft', 'arrayfun', 'cellfun', 'input', 'fliplr', 'flipud', 'ismember' 35 | ]); 36 | 37 | var keywords = wordRegexp([ 38 | 'return', 'case', 'switch', 'else', 'elseif', 'end', 'endif', 'endfunction', 39 | 'if', 'otherwise', 'do', 'for', 'while', 'try', 'catch', 'classdef', 'properties', 'events', 40 | 'methods', 'global', 'persistent', 'endfor', 'endwhile', 'printf', 'sprintf', 'disp', 'until', 41 | 'continue', 'pkg' 42 | ]); 43 | 44 | 45 | // tokenizers 46 | function tokenTranspose(stream, state) { 47 | if (!stream.sol() && stream.peek() === '\'') { 48 | stream.next(); 49 | state.tokenize = tokenBase; 50 | return 'operator'; 51 | } 52 | state.tokenize = tokenBase; 53 | return tokenBase(stream, state); 54 | } 55 | 56 | 57 | function tokenComment(stream, state) { 58 | if (stream.match(/^.*%}/)) { 59 | state.tokenize = tokenBase; 60 | return 'comment'; 61 | }; 62 | stream.skipToEnd(); 63 | return 'comment'; 64 | } 65 | 66 | function tokenBase(stream, state) { 67 | // whitespaces 68 | if (stream.eatSpace()) return null; 69 | 70 | // Handle one line Comments 71 | if (stream.match('%{')){ 72 | state.tokenize = tokenComment; 73 | stream.skipToEnd(); 74 | return 'comment'; 75 | } 76 | 77 | if (stream.match(/^[%#]/)){ 78 | stream.skipToEnd(); 79 | return 'comment'; 80 | } 81 | 82 | // Handle Number Literals 83 | if (stream.match(/^[0-9\.+-]/, false)) { 84 | if (stream.match(/^[+-]?0x[0-9a-fA-F]+[ij]?/)) { 85 | stream.tokenize = tokenBase; 86 | return 'number'; }; 87 | if (stream.match(/^[+-]?\d*\.\d+([EeDd][+-]?\d+)?[ij]?/)) { return 'number'; }; 88 | if (stream.match(/^[+-]?\d+([EeDd][+-]?\d+)?[ij]?/)) { return 'number'; }; 89 | } 90 | if (stream.match(wordRegexp(['nan','NaN','inf','Inf']))) { return 'number'; }; 91 | 92 | // Handle Strings 93 | var m = stream.match(/^"(?:[^"]|"")*("|$)/) || stream.match(/^'(?:[^']|'')*('|$)/) 94 | if (m) { return m[1] ? 'string' : "string error"; } 95 | 96 | // Handle words 97 | if (stream.match(keywords)) { return 'keyword'; } ; 98 | if (stream.match(builtins)) { return 'builtin'; } ; 99 | if (stream.match(identifiers)) { return 'variable'; } ; 100 | 101 | if (stream.match(singleOperators) || stream.match(doubleOperators)) { return 'operator'; }; 102 | if (stream.match(singleDelimiters) || stream.match(doubleDelimiters) || stream.match(tripleDelimiters)) { return null; }; 103 | 104 | if (stream.match(expressionEnd)) { 105 | state.tokenize = tokenTranspose; 106 | return null; 107 | }; 108 | 109 | 110 | // Handle non-detected items 111 | stream.next(); 112 | return 'error'; 113 | }; 114 | 115 | 116 | return { 117 | startState: function() { 118 | return { 119 | tokenize: tokenBase 120 | }; 121 | }, 122 | 123 | token: function(stream, state) { 124 | var style = state.tokenize(stream, state); 125 | if (style === 'number' || style === 'variable'){ 126 | state.tokenize = tokenTranspose; 127 | } 128 | return style; 129 | }, 130 | 131 | lineComment: '%', 132 | 133 | fold: 'indent' 134 | }; 135 | }); 136 | 137 | CodeMirror.defineMIME("text/x-octave", "octave"); 138 | 139 | }); 140 | -------------------------------------------------------------------------------- /mode/pascal/pascal.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineMode("pascal", function() { 15 | function words(str) { 16 | var obj = {}, words = str.split(" "); 17 | for (var i = 0; i < words.length; ++i) obj[words[i]] = true; 18 | return obj; 19 | } 20 | var keywords = words( 21 | "absolute and array asm begin case const constructor destructor div do " + 22 | "downto else end file for function goto if implementation in inherited " + 23 | "inline interface label mod nil not object of operator or packed procedure " + 24 | "program record reintroduce repeat self set shl shr string then to type " + 25 | "unit until uses var while with xor as class dispinterface except exports " + 26 | "finalization finally initialization inline is library on out packed " + 27 | "property raise resourcestring threadvar try absolute abstract alias " + 28 | "assembler bitpacked break cdecl continue cppdecl cvar default deprecated " + 29 | "dynamic enumerator experimental export external far far16 forward generic " + 30 | "helper implements index interrupt iocheck local message name near " + 31 | "nodefault noreturn nostackframe oldfpccall otherwise overload override " + 32 | "pascal platform private protected public published read register " + 33 | "reintroduce result safecall saveregisters softfloat specialize static " + 34 | "stdcall stored strict unaligned unimplemented varargs virtual write"); 35 | var atoms = {"null": true}; 36 | 37 | var isOperatorChar = /[+\-*&%=<>!?|\/]/; 38 | 39 | function tokenBase(stream, state) { 40 | var ch = stream.next(); 41 | if (ch == "#" && state.startOfLine) { 42 | stream.skipToEnd(); 43 | return "meta"; 44 | } 45 | if (ch == '"' || ch == "'") { 46 | state.tokenize = tokenString(ch); 47 | return state.tokenize(stream, state); 48 | } 49 | if (ch == "(" && stream.eat("*")) { 50 | state.tokenize = tokenComment; 51 | return tokenComment(stream, state); 52 | } 53 | if (ch == "{") { 54 | state.tokenize = tokenCommentBraces; 55 | return tokenCommentBraces(stream, state); 56 | } 57 | if (/[\[\]\(\),;\:\.]/.test(ch)) { 58 | return null; 59 | } 60 | if (/\d/.test(ch)) { 61 | stream.eatWhile(/[\w\.]/); 62 | return "number"; 63 | } 64 | if (ch == "/") { 65 | if (stream.eat("/")) { 66 | stream.skipToEnd(); 67 | return "comment"; 68 | } 69 | } 70 | if (isOperatorChar.test(ch)) { 71 | stream.eatWhile(isOperatorChar); 72 | return "operator"; 73 | } 74 | stream.eatWhile(/[\w\$_]/); 75 | var cur = stream.current(); 76 | if (keywords.propertyIsEnumerable(cur)) return "keyword"; 77 | if (atoms.propertyIsEnumerable(cur)) return "atom"; 78 | return "variable"; 79 | } 80 | 81 | function tokenString(quote) { 82 | return function(stream, state) { 83 | var escaped = false, next, end = false; 84 | while ((next = stream.next()) != null) { 85 | if (next == quote && !escaped) {end = true; break;} 86 | escaped = !escaped && next == "\\"; 87 | } 88 | if (end || !escaped) state.tokenize = null; 89 | return "string"; 90 | }; 91 | } 92 | 93 | function tokenComment(stream, state) { 94 | var maybeEnd = false, ch; 95 | while (ch = stream.next()) { 96 | if (ch == ")" && maybeEnd) { 97 | state.tokenize = null; 98 | break; 99 | } 100 | maybeEnd = (ch == "*"); 101 | } 102 | return "comment"; 103 | } 104 | 105 | function tokenCommentBraces(stream, state) { 106 | var ch; 107 | while (ch = stream.next()) { 108 | if (ch == "}") { 109 | state.tokenize = null; 110 | break; 111 | } 112 | } 113 | return "comment"; 114 | } 115 | 116 | // Interface 117 | 118 | return { 119 | startState: function() { 120 | return {tokenize: null}; 121 | }, 122 | 123 | token: function(stream, state) { 124 | if (stream.eatSpace()) return null; 125 | var style = (state.tokenize || tokenBase)(stream, state); 126 | if (style == "comment" || style == "meta") return style; 127 | return style; 128 | }, 129 | 130 | electricChars: "{}" 131 | }; 132 | }); 133 | 134 | CodeMirror.defineMIME("text/x-pascal", "pascal"); 135 | 136 | }); 137 | -------------------------------------------------------------------------------- /mode/pegjs/pegjs.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror"), require("../javascript/javascript")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror", "../javascript/javascript"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineMode("pegjs", function (config) { 15 | var jsMode = CodeMirror.getMode(config, "javascript"); 16 | 17 | function identifier(stream) { 18 | return stream.match(/^[a-zA-Z_][a-zA-Z0-9_]*/); 19 | } 20 | 21 | return { 22 | startState: function () { 23 | return { 24 | inString: false, 25 | stringType: null, 26 | inComment: false, 27 | inCharacterClass: false, 28 | braced: 0, 29 | lhs: true, 30 | localState: null 31 | }; 32 | }, 33 | token: function (stream, state) { 34 | if (stream) 35 | 36 | //check for state changes 37 | if (!state.inString && !state.inComment && ((stream.peek() == '"') || (stream.peek() == "'"))) { 38 | state.stringType = stream.peek(); 39 | stream.next(); // Skip quote 40 | state.inString = true; // Update state 41 | } 42 | if (!state.inString && !state.inComment && stream.match(/^\/\*/)) { 43 | state.inComment = true; 44 | } 45 | 46 | //return state 47 | if (state.inString) { 48 | while (state.inString && !stream.eol()) { 49 | if (stream.peek() === state.stringType) { 50 | stream.next(); // Skip quote 51 | state.inString = false; // Clear flag 52 | } else if (stream.peek() === '\\') { 53 | stream.next(); 54 | stream.next(); 55 | } else { 56 | stream.match(/^.[^\\\"\']*/); 57 | } 58 | } 59 | return state.lhs ? "property string" : "string"; // Token style 60 | } else if (state.inComment) { 61 | while (state.inComment && !stream.eol()) { 62 | if (stream.match(/\*\//)) { 63 | state.inComment = false; // Clear flag 64 | } else { 65 | stream.match(/^.[^\*]*/); 66 | } 67 | } 68 | return "comment"; 69 | } else if (state.inCharacterClass) { 70 | while (state.inCharacterClass && !stream.eol()) { 71 | if (!(stream.match(/^[^\]\\]+/) || stream.match(/^\\./))) { 72 | state.inCharacterClass = false; 73 | } 74 | } 75 | } else if (stream.peek() === '[') { 76 | stream.next(); 77 | state.inCharacterClass = true; 78 | return 'bracket'; 79 | } else if (stream.match(/^\/\//)) { 80 | stream.skipToEnd(); 81 | return "comment"; 82 | } else if (state.braced || stream.peek() === '{') { 83 | if (state.localState === null) { 84 | state.localState = CodeMirror.startState(jsMode); 85 | } 86 | var token = jsMode.token(stream, state.localState); 87 | var text = stream.current(); 88 | if (!token) { 89 | for (var i = 0; i < text.length; i++) { 90 | if (text[i] === '{') { 91 | state.braced++; 92 | } else if (text[i] === '}') { 93 | state.braced--; 94 | } 95 | }; 96 | } 97 | return token; 98 | } else if (identifier(stream)) { 99 | if (stream.peek() === ':') { 100 | return 'variable'; 101 | } 102 | return 'variable-2'; 103 | } else if (['[', ']', '(', ')'].indexOf(stream.peek()) != -1) { 104 | stream.next(); 105 | return 'bracket'; 106 | } else if (!stream.eatSpace()) { 107 | stream.next(); 108 | } 109 | return null; 110 | } 111 | }; 112 | }, "javascript"); 113 | 114 | }); 115 | -------------------------------------------------------------------------------- /mode/properties/properties.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineMode("properties", function() { 15 | return { 16 | token: function(stream, state) { 17 | var sol = stream.sol() || state.afterSection; 18 | var eol = stream.eol(); 19 | 20 | state.afterSection = false; 21 | 22 | if (sol) { 23 | if (state.nextMultiline) { 24 | state.inMultiline = true; 25 | state.nextMultiline = false; 26 | } else { 27 | state.position = "def"; 28 | } 29 | } 30 | 31 | if (eol && ! state.nextMultiline) { 32 | state.inMultiline = false; 33 | state.position = "def"; 34 | } 35 | 36 | if (sol) { 37 | while(stream.eatSpace()) {} 38 | } 39 | 40 | var ch = stream.next(); 41 | 42 | if (sol && (ch === "#" || ch === "!" || ch === ";")) { 43 | state.position = "comment"; 44 | stream.skipToEnd(); 45 | return "comment"; 46 | } else if (sol && ch === "[") { 47 | state.afterSection = true; 48 | stream.skipTo("]"); stream.eat("]"); 49 | return "header"; 50 | } else if (ch === "=" || ch === ":") { 51 | state.position = "quote"; 52 | return null; 53 | } else if (ch === "\\" && state.position === "quote") { 54 | if (stream.eol()) { // end of line? 55 | // Multiline value 56 | state.nextMultiline = true; 57 | } 58 | } 59 | 60 | return state.position; 61 | }, 62 | 63 | startState: function() { 64 | return { 65 | position : "def", // Current position, "def", "quote" or "comment" 66 | nextMultiline : false, // Is the next line multiline value 67 | inMultiline : false, // Is the current line a multiline value 68 | afterSection : false // Did we just open a section 69 | }; 70 | } 71 | 72 | }; 73 | }); 74 | 75 | CodeMirror.defineMIME("text/x-properties", "properties"); 76 | CodeMirror.defineMIME("text/x-ini", "properties"); 77 | 78 | }); 79 | -------------------------------------------------------------------------------- /mode/protobuf/protobuf.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | function wordRegexp(words) { 15 | return new RegExp("^((" + words.join(")|(") + "))\\b", "i"); 16 | }; 17 | 18 | var keywordArray = [ 19 | "package", "message", "import", "syntax", 20 | "required", "optional", "repeated", "reserved", "default", "extensions", "packed", 21 | "bool", "bytes", "double", "enum", "float", "string", 22 | "int32", "int64", "uint32", "uint64", "sint32", "sint64", "fixed32", "fixed64", "sfixed32", "sfixed64", 23 | "option", "service", "rpc", "returns" 24 | ]; 25 | var keywords = wordRegexp(keywordArray); 26 | 27 | CodeMirror.registerHelper("hintWords", "protobuf", keywordArray); 28 | 29 | var identifiers = new RegExp("^[_A-Za-z\xa1-\uffff][_A-Za-z0-9\xa1-\uffff]*"); 30 | 31 | function tokenBase(stream) { 32 | // whitespaces 33 | if (stream.eatSpace()) return null; 34 | 35 | // Handle one line Comments 36 | if (stream.match("//")) { 37 | stream.skipToEnd(); 38 | return "comment"; 39 | } 40 | 41 | // Handle Number Literals 42 | if (stream.match(/^[0-9\.+-]/, false)) { 43 | if (stream.match(/^[+-]?0x[0-9a-fA-F]+/)) 44 | return "number"; 45 | if (stream.match(/^[+-]?\d*\.\d+([EeDd][+-]?\d+)?/)) 46 | return "number"; 47 | if (stream.match(/^[+-]?\d+([EeDd][+-]?\d+)?/)) 48 | return "number"; 49 | } 50 | 51 | // Handle Strings 52 | if (stream.match(/^"([^"]|(""))*"/)) { return "string"; } 53 | if (stream.match(/^'([^']|(''))*'/)) { return "string"; } 54 | 55 | // Handle words 56 | if (stream.match(keywords)) { return "keyword"; } 57 | if (stream.match(identifiers)) { return "variable"; } ; 58 | 59 | // Handle non-detected items 60 | stream.next(); 61 | return null; 62 | }; 63 | 64 | CodeMirror.defineMode("protobuf", function() { 65 | return { 66 | token: tokenBase, 67 | fold: "brace" 68 | }; 69 | }); 70 | 71 | CodeMirror.defineMIME("text/x-protobuf", "protobuf"); 72 | }); 73 | -------------------------------------------------------------------------------- /mode/rpm/rpm.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineMode("rpm-changes", function() { 15 | var headerSeperator = /^-+$/; 16 | var headerLine = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ?\d{1,2} \d{2}:\d{2}(:\d{2})? [A-Z]{3,4} \d{4} - /; 17 | var simpleEmail = /^[\w+.-]+@[\w.-]+/; 18 | 19 | return { 20 | token: function(stream) { 21 | if (stream.sol()) { 22 | if (stream.match(headerSeperator)) { return 'tag'; } 23 | if (stream.match(headerLine)) { return 'tag'; } 24 | } 25 | if (stream.match(simpleEmail)) { return 'string'; } 26 | stream.next(); 27 | return null; 28 | } 29 | }; 30 | }); 31 | 32 | CodeMirror.defineMIME("text/x-rpm-changes", "rpm-changes"); 33 | 34 | // Quick and dirty spec file highlighting 35 | 36 | CodeMirror.defineMode("rpm-spec", function() { 37 | var arch = /^(i386|i586|i686|x86_64|ppc64le|ppc64|ppc|ia64|s390x|s390|sparc64|sparcv9|sparc|noarch|alphaev6|alpha|hppa|mipsel)/; 38 | 39 | var preamble = /^[a-zA-Z0-9()]+:/; 40 | var section = /^%(debug_package|package|description|prep|build|install|files|clean|changelog|preinstall|preun|postinstall|postun|pretrans|posttrans|pre|post|triggerin|triggerun|verifyscript|check|triggerpostun|triggerprein|trigger)/; 41 | var control_flow_complex = /^%(ifnarch|ifarch|if)/; // rpm control flow macros 42 | var control_flow_simple = /^%(else|endif)/; // rpm control flow macros 43 | var operators = /^(\!|\?|\<\=|\<|\>\=|\>|\=\=|\&\&|\|\|)/; // operators in control flow macros 44 | 45 | return { 46 | startState: function () { 47 | return { 48 | controlFlow: false, 49 | macroParameters: false, 50 | section: false 51 | }; 52 | }, 53 | token: function (stream, state) { 54 | var ch = stream.peek(); 55 | if (ch == "#") { stream.skipToEnd(); return "comment"; } 56 | 57 | if (stream.sol()) { 58 | if (stream.match(preamble)) { return "header"; } 59 | if (stream.match(section)) { return "atom"; } 60 | } 61 | 62 | if (stream.match(/^\$\w+/)) { return "def"; } // Variables like '$RPM_BUILD_ROOT' 63 | if (stream.match(/^\$\{\w+\}/)) { return "def"; } // Variables like '${RPM_BUILD_ROOT}' 64 | 65 | if (stream.match(control_flow_simple)) { return "keyword"; } 66 | if (stream.match(control_flow_complex)) { 67 | state.controlFlow = true; 68 | return "keyword"; 69 | } 70 | if (state.controlFlow) { 71 | if (stream.match(operators)) { return "operator"; } 72 | if (stream.match(/^(\d+)/)) { return "number"; } 73 | if (stream.eol()) { state.controlFlow = false; } 74 | } 75 | 76 | if (stream.match(arch)) { 77 | if (stream.eol()) { state.controlFlow = false; } 78 | return "number"; 79 | } 80 | 81 | // Macros like '%make_install' or '%attr(0775,root,root)' 82 | if (stream.match(/^%[\w]+/)) { 83 | if (stream.match(/^\(/)) { state.macroParameters = true; } 84 | return "keyword"; 85 | } 86 | if (state.macroParameters) { 87 | if (stream.match(/^\d+/)) { return "number";} 88 | if (stream.match(/^\)/)) { 89 | state.macroParameters = false; 90 | return "keyword"; 91 | } 92 | } 93 | 94 | // Macros like '%{defined fedora}' 95 | if (stream.match(/^%\{\??[\w \-\:\!]+\}/)) { 96 | if (stream.eol()) { state.controlFlow = false; } 97 | return "def"; 98 | } 99 | 100 | //TODO: Include bash script sub-parser (CodeMirror supports that) 101 | stream.next(); 102 | return null; 103 | } 104 | }; 105 | }); 106 | 107 | CodeMirror.defineMIME("text/x-rpm-spec", "rpm-spec"); 108 | 109 | }); 110 | -------------------------------------------------------------------------------- /mode/rust/rust.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror"), require("../../addon/mode/simple")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror", "../../addon/mode/simple"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineSimpleMode("rust",{ 15 | start: [ 16 | // string and byte string 17 | {regex: /b?"/, token: "string", next: "string"}, 18 | // raw string and raw byte string 19 | {regex: /b?r"/, token: "string", next: "string_raw"}, 20 | {regex: /b?r#+"/, token: "string", next: "string_raw_hash"}, 21 | // character 22 | {regex: /'(?:[^'\\]|\\(?:[nrt0'"]|x[\da-fA-F]{2}|u\{[\da-fA-F]{6}\}))'/, token: "string-2"}, 23 | // byte 24 | {regex: /b'(?:[^']|\\(?:['\\nrt0]|x[\da-fA-F]{2}))'/, token: "string-2"}, 25 | 26 | {regex: /(?:(?:[0-9][0-9_]*)(?:(?:[Ee][+-]?[0-9_]+)|\.[0-9_]+(?:[Ee][+-]?[0-9_]+)?)(?:f32|f64)?)|(?:0(?:b[01_]+|(?:o[0-7_]+)|(?:x[0-9a-fA-F_]+))|(?:[0-9][0-9_]*))(?:u8|u16|u32|u64|i8|i16|i32|i64|isize|usize)?/, 27 | token: "number"}, 28 | {regex: /(let(?:\s+mut)?|fn|enum|mod|struct|type|union)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)/, token: ["keyword", null, "def"]}, 29 | {regex: /(?:abstract|alignof|as|async|await|box|break|continue|const|crate|do|dyn|else|enum|extern|fn|for|final|if|impl|in|loop|macro|match|mod|move|offsetof|override|priv|proc|pub|pure|ref|return|self|sizeof|static|struct|super|trait|type|typeof|union|unsafe|unsized|use|virtual|where|while|yield)\b/, token: "keyword"}, 30 | {regex: /\b(?:Self|isize|usize|char|bool|u8|u16|u32|u64|f16|f32|f64|i8|i16|i32|i64|str|Option)\b/, token: "atom"}, 31 | {regex: /\b(?:true|false|Some|None|Ok|Err)\b/, token: "builtin"}, 32 | {regex: /\b(fn)(\s+)([a-zA-Z_][a-zA-Z0-9_]*)/, 33 | token: ["keyword", null ,"def"]}, 34 | {regex: /#!?\[.*\]/, token: "meta"}, 35 | {regex: /\/\/.*/, token: "comment"}, 36 | {regex: /\/\*/, token: "comment", next: "comment"}, 37 | {regex: /[-+\/*=<>!]+/, token: "operator"}, 38 | {regex: /[a-zA-Z_]\w*!/,token: "variable-3"}, 39 | {regex: /[a-zA-Z_]\w*/, token: "variable"}, 40 | {regex: /[\{\[\(]/, indent: true}, 41 | {regex: /[\}\]\)]/, dedent: true} 42 | ], 43 | string: [ 44 | {regex: /"/, token: "string", next: "start"}, 45 | {regex: /(?:[^\\"]|\\(?:.|$))*/, token: "string"} 46 | ], 47 | string_raw: [ 48 | {regex: /"/, token: "string", next: "start"}, 49 | {regex: /[^"]*/, token: "string"} 50 | ], 51 | string_raw_hash: [ 52 | {regex: /"#+/, token: "string", next: "start"}, 53 | {regex: /(?:[^"]|"(?!#))*/, token: "string"} 54 | ], 55 | comment: [ 56 | {regex: /.*?\*\//, token: "comment", next: "start"}, 57 | {regex: /.*/, token: "comment"} 58 | ], 59 | meta: { 60 | dontIndentStates: ["comment"], 61 | electricInput: /^\s*\}$/, 62 | blockCommentStart: "/*", 63 | blockCommentEnd: "*/", 64 | lineComment: "//", 65 | fold: "brace" 66 | } 67 | }); 68 | 69 | 70 | CodeMirror.defineMIME("text/x-rustsrc", "rust"); 71 | CodeMirror.defineMIME("text/rust", "rust"); 72 | }); 73 | -------------------------------------------------------------------------------- /mode/shell/shell.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineMode('shell', function() { 15 | 16 | var words = {}; 17 | function define(style, dict) { 18 | for(var i = 0; i < dict.length; i++) { 19 | words[dict[i]] = style; 20 | } 21 | }; 22 | 23 | var commonAtoms = ["true", "false"]; 24 | var commonKeywords = ["if", "then", "do", "else", "elif", "while", "until", "for", "in", "esac", "fi", 25 | "fin", "fil", "done", "exit", "set", "unset", "export", "function"]; 26 | var commonCommands = ["ab", "awk", "bash", "beep", "cat", "cc", "cd", "chown", "chmod", "chroot", "clear", 27 | "cp", "curl", "cut", "diff", "echo", "find", "gawk", "gcc", "get", "git", "grep", "hg", "kill", "killall", 28 | "ln", "ls", "make", "mkdir", "openssl", "mv", "nc", "nl", "node", "npm", "ping", "ps", "restart", "rm", 29 | "rmdir", "sed", "service", "sh", "shopt", "shred", "source", "sort", "sleep", "ssh", "start", "stop", 30 | "su", "sudo", "svn", "tee", "telnet", "top", "touch", "vi", "vim", "wall", "wc", "wget", "who", "write", 31 | "yes", "zsh"]; 32 | 33 | CodeMirror.registerHelper("hintWords", "shell", commonAtoms.concat(commonKeywords, commonCommands)); 34 | 35 | define('atom', commonAtoms); 36 | define('keyword', commonKeywords); 37 | define('builtin', commonCommands); 38 | 39 | function tokenBase(stream, state) { 40 | if (stream.eatSpace()) return null; 41 | 42 | var sol = stream.sol(); 43 | var ch = stream.next(); 44 | 45 | if (ch === '\\') { 46 | stream.next(); 47 | return null; 48 | } 49 | if (ch === '\'' || ch === '"' || ch === '`') { 50 | state.tokens.unshift(tokenString(ch, ch === "`" ? "quote" : "string")); 51 | return tokenize(stream, state); 52 | } 53 | if (ch === '#') { 54 | if (sol && stream.eat('!')) { 55 | stream.skipToEnd(); 56 | return 'meta'; // 'comment'? 57 | } 58 | stream.skipToEnd(); 59 | return 'comment'; 60 | } 61 | if (ch === '$') { 62 | state.tokens.unshift(tokenDollar); 63 | return tokenize(stream, state); 64 | } 65 | if (ch === '+' || ch === '=') { 66 | return 'operator'; 67 | } 68 | if (ch === '-') { 69 | stream.eat('-'); 70 | stream.eatWhile(/\w/); 71 | return 'attribute'; 72 | } 73 | if (/\d/.test(ch)) { 74 | stream.eatWhile(/\d/); 75 | if(stream.eol() || !/\w/.test(stream.peek())) { 76 | return 'number'; 77 | } 78 | } 79 | stream.eatWhile(/[\w-]/); 80 | var cur = stream.current(); 81 | if (stream.peek() === '=' && /\w+/.test(cur)) return 'def'; 82 | return words.hasOwnProperty(cur) ? words[cur] : null; 83 | } 84 | 85 | function tokenString(quote, style) { 86 | var close = quote == "(" ? ")" : quote == "{" ? "}" : quote 87 | return function(stream, state) { 88 | var next, escaped = false; 89 | while ((next = stream.next()) != null) { 90 | if (next === close && !escaped) { 91 | state.tokens.shift(); 92 | break; 93 | } else if (next === '$' && !escaped && quote !== "'" && stream.peek() != close) { 94 | escaped = true; 95 | stream.backUp(1); 96 | state.tokens.unshift(tokenDollar); 97 | break; 98 | } else if (!escaped && quote !== close && next === quote) { 99 | state.tokens.unshift(tokenString(quote, style)) 100 | return tokenize(stream, state) 101 | } else if (!escaped && /['"]/.test(next) && !/['"]/.test(quote)) { 102 | state.tokens.unshift(tokenStringStart(next, "string")); 103 | stream.backUp(1); 104 | break; 105 | } 106 | escaped = !escaped && next === '\\'; 107 | } 108 | return style; 109 | }; 110 | }; 111 | 112 | function tokenStringStart(quote, style) { 113 | return function(stream, state) { 114 | state.tokens[0] = tokenString(quote, style) 115 | stream.next() 116 | return tokenize(stream, state) 117 | } 118 | } 119 | 120 | var tokenDollar = function(stream, state) { 121 | if (state.tokens.length > 1) stream.eat('$'); 122 | var ch = stream.next() 123 | if (/['"({]/.test(ch)) { 124 | state.tokens[0] = tokenString(ch, ch == "(" ? "quote" : ch == "{" ? "def" : "string"); 125 | return tokenize(stream, state); 126 | } 127 | if (!/\d/.test(ch)) stream.eatWhile(/\w/); 128 | state.tokens.shift(); 129 | return 'def'; 130 | }; 131 | 132 | function tokenize(stream, state) { 133 | return (state.tokens[0] || tokenBase) (stream, state); 134 | }; 135 | 136 | return { 137 | startState: function() {return {tokens:[]};}, 138 | token: function(stream, state) { 139 | return tokenize(stream, state); 140 | }, 141 | closeBrackets: "()[]{}''\"\"``", 142 | lineComment: '#', 143 | fold: "brace" 144 | }; 145 | }); 146 | 147 | CodeMirror.defineMIME('text/x-sh', 'shell'); 148 | // Apache uses a slightly different Media Type for Shell scripts 149 | // http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types 150 | CodeMirror.defineMIME('application/x-sh', 'shell'); 151 | 152 | }); 153 | -------------------------------------------------------------------------------- /mode/sieve/sieve.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineMode("sieve", function(config) { 15 | function words(str) { 16 | var obj = {}, words = str.split(" "); 17 | for (var i = 0; i < words.length; ++i) obj[words[i]] = true; 18 | return obj; 19 | } 20 | 21 | var keywords = words("if elsif else stop require"); 22 | var atoms = words("true false not"); 23 | var indentUnit = config.indentUnit; 24 | 25 | function tokenBase(stream, state) { 26 | 27 | var ch = stream.next(); 28 | if (ch == "/" && stream.eat("*")) { 29 | state.tokenize = tokenCComment; 30 | return tokenCComment(stream, state); 31 | } 32 | 33 | if (ch === '#') { 34 | stream.skipToEnd(); 35 | return "comment"; 36 | } 37 | 38 | if (ch == "\"") { 39 | state.tokenize = tokenString(ch); 40 | return state.tokenize(stream, state); 41 | } 42 | 43 | if (ch == "(") { 44 | state._indent.push("("); 45 | // add virtual angel wings so that editor behaves... 46 | // ...more sane incase of broken brackets 47 | state._indent.push("{"); 48 | return null; 49 | } 50 | 51 | if (ch === "{") { 52 | state._indent.push("{"); 53 | return null; 54 | } 55 | 56 | if (ch == ")") { 57 | state._indent.pop(); 58 | state._indent.pop(); 59 | } 60 | 61 | if (ch === "}") { 62 | state._indent.pop(); 63 | return null; 64 | } 65 | 66 | if (ch == ",") 67 | return null; 68 | 69 | if (ch == ";") 70 | return null; 71 | 72 | 73 | if (/[{}\(\),;]/.test(ch)) 74 | return null; 75 | 76 | // 1*DIGIT "K" / "M" / "G" 77 | if (/\d/.test(ch)) { 78 | stream.eatWhile(/[\d]/); 79 | stream.eat(/[KkMmGg]/); 80 | return "number"; 81 | } 82 | 83 | // ":" (ALPHA / "_") *(ALPHA / DIGIT / "_") 84 | if (ch == ":") { 85 | stream.eatWhile(/[a-zA-Z_]/); 86 | stream.eatWhile(/[a-zA-Z0-9_]/); 87 | 88 | return "operator"; 89 | } 90 | 91 | stream.eatWhile(/\w/); 92 | var cur = stream.current(); 93 | 94 | // "text:" *(SP / HTAB) (hash-comment / CRLF) 95 | // *(multiline-literal / multiline-dotstart) 96 | // "." CRLF 97 | if ((cur == "text") && stream.eat(":")) 98 | { 99 | state.tokenize = tokenMultiLineString; 100 | return "string"; 101 | } 102 | 103 | if (keywords.propertyIsEnumerable(cur)) 104 | return "keyword"; 105 | 106 | if (atoms.propertyIsEnumerable(cur)) 107 | return "atom"; 108 | 109 | return null; 110 | } 111 | 112 | function tokenMultiLineString(stream, state) 113 | { 114 | state._multiLineString = true; 115 | // the first line is special it may contain a comment 116 | if (!stream.sol()) { 117 | stream.eatSpace(); 118 | 119 | if (stream.peek() == "#") { 120 | stream.skipToEnd(); 121 | return "comment"; 122 | } 123 | 124 | stream.skipToEnd(); 125 | return "string"; 126 | } 127 | 128 | if ((stream.next() == ".") && (stream.eol())) 129 | { 130 | state._multiLineString = false; 131 | state.tokenize = tokenBase; 132 | } 133 | 134 | return "string"; 135 | } 136 | 137 | function tokenCComment(stream, state) { 138 | var maybeEnd = false, ch; 139 | while ((ch = stream.next()) != null) { 140 | if (maybeEnd && ch == "/") { 141 | state.tokenize = tokenBase; 142 | break; 143 | } 144 | maybeEnd = (ch == "*"); 145 | } 146 | return "comment"; 147 | } 148 | 149 | function tokenString(quote) { 150 | return function(stream, state) { 151 | var escaped = false, ch; 152 | while ((ch = stream.next()) != null) { 153 | if (ch == quote && !escaped) 154 | break; 155 | escaped = !escaped && ch == "\\"; 156 | } 157 | if (!escaped) state.tokenize = tokenBase; 158 | return "string"; 159 | }; 160 | } 161 | 162 | return { 163 | startState: function(base) { 164 | return {tokenize: tokenBase, 165 | baseIndent: base || 0, 166 | _indent: []}; 167 | }, 168 | 169 | token: function(stream, state) { 170 | if (stream.eatSpace()) 171 | return null; 172 | 173 | return (state.tokenize || tokenBase)(stream, state); 174 | }, 175 | 176 | indent: function(state, _textAfter) { 177 | var length = state._indent.length; 178 | if (_textAfter && (_textAfter[0] == "}")) 179 | length--; 180 | 181 | if (length <0) 182 | length = 0; 183 | 184 | return length * indentUnit; 185 | }, 186 | 187 | electricChars: "}" 188 | }; 189 | }); 190 | 191 | CodeMirror.defineMIME("application/sieve", "sieve"); 192 | 193 | }); 194 | -------------------------------------------------------------------------------- /mode/smalltalk/smalltalk.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineMode('smalltalk', function(config) { 15 | 16 | var specialChars = /[+\-\/\\*~<>=@%|&?!.,:;^]/; 17 | var keywords = /true|false|nil|self|super|thisContext/; 18 | 19 | var Context = function(tokenizer, parent) { 20 | this.next = tokenizer; 21 | this.parent = parent; 22 | }; 23 | 24 | var Token = function(name, context, eos) { 25 | this.name = name; 26 | this.context = context; 27 | this.eos = eos; 28 | }; 29 | 30 | var State = function() { 31 | this.context = new Context(next, null); 32 | this.expectVariable = true; 33 | this.indentation = 0; 34 | this.userIndentationDelta = 0; 35 | }; 36 | 37 | State.prototype.userIndent = function(indentation) { 38 | this.userIndentationDelta = indentation > 0 ? (indentation / config.indentUnit - this.indentation) : 0; 39 | }; 40 | 41 | var next = function(stream, context, state) { 42 | var token = new Token(null, context, false); 43 | var aChar = stream.next(); 44 | 45 | if (aChar === '"') { 46 | token = nextComment(stream, new Context(nextComment, context)); 47 | 48 | } else if (aChar === '\'') { 49 | token = nextString(stream, new Context(nextString, context)); 50 | 51 | } else if (aChar === '#') { 52 | if (stream.peek() === '\'') { 53 | stream.next(); 54 | token = nextSymbol(stream, new Context(nextSymbol, context)); 55 | } else { 56 | if (stream.eatWhile(/[^\s.{}\[\]()]/)) 57 | token.name = 'string-2'; 58 | else 59 | token.name = 'meta'; 60 | } 61 | 62 | } else if (aChar === '$') { 63 | if (stream.next() === '<') { 64 | stream.eatWhile(/[^\s>]/); 65 | stream.next(); 66 | } 67 | token.name = 'string-2'; 68 | 69 | } else if (aChar === '|' && state.expectVariable) { 70 | token.context = new Context(nextTemporaries, context); 71 | 72 | } else if (/[\[\]{}()]/.test(aChar)) { 73 | token.name = 'bracket'; 74 | token.eos = /[\[{(]/.test(aChar); 75 | 76 | if (aChar === '[') { 77 | state.indentation++; 78 | } else if (aChar === ']') { 79 | state.indentation = Math.max(0, state.indentation - 1); 80 | } 81 | 82 | } else if (specialChars.test(aChar)) { 83 | stream.eatWhile(specialChars); 84 | token.name = 'operator'; 85 | token.eos = aChar !== ';'; // ; cascaded message expression 86 | 87 | } else if (/\d/.test(aChar)) { 88 | stream.eatWhile(/[\w\d]/); 89 | token.name = 'number'; 90 | 91 | } else if (/[\w_]/.test(aChar)) { 92 | stream.eatWhile(/[\w\d_]/); 93 | token.name = state.expectVariable ? (keywords.test(stream.current()) ? 'keyword' : 'variable') : null; 94 | 95 | } else { 96 | token.eos = state.expectVariable; 97 | } 98 | 99 | return token; 100 | }; 101 | 102 | var nextComment = function(stream, context) { 103 | stream.eatWhile(/[^"]/); 104 | return new Token('comment', stream.eat('"') ? context.parent : context, true); 105 | }; 106 | 107 | var nextString = function(stream, context) { 108 | stream.eatWhile(/[^']/); 109 | return new Token('string', stream.eat('\'') ? context.parent : context, false); 110 | }; 111 | 112 | var nextSymbol = function(stream, context) { 113 | stream.eatWhile(/[^']/); 114 | return new Token('string-2', stream.eat('\'') ? context.parent : context, false); 115 | }; 116 | 117 | var nextTemporaries = function(stream, context) { 118 | var token = new Token(null, context, false); 119 | var aChar = stream.next(); 120 | 121 | if (aChar === '|') { 122 | token.context = context.parent; 123 | token.eos = true; 124 | 125 | } else { 126 | stream.eatWhile(/[^|]/); 127 | token.name = 'variable'; 128 | } 129 | 130 | return token; 131 | }; 132 | 133 | return { 134 | startState: function() { 135 | return new State; 136 | }, 137 | 138 | token: function(stream, state) { 139 | state.userIndent(stream.indentation()); 140 | 141 | if (stream.eatSpace()) { 142 | return null; 143 | } 144 | 145 | var token = state.context.next(stream, state.context, state); 146 | state.context = token.context; 147 | state.expectVariable = token.eos; 148 | 149 | return token.name; 150 | }, 151 | 152 | blankLine: function(state) { 153 | state.userIndent(0); 154 | }, 155 | 156 | indent: function(state, textAfter) { 157 | var i = state.context.next === next && textAfter && textAfter.charAt(0) === ']' ? -1 : state.userIndentationDelta; 158 | return (state.indentation + i) * config.indentUnit; 159 | }, 160 | 161 | electricChars: ']' 162 | }; 163 | 164 | }); 165 | 166 | CodeMirror.defineMIME('text/x-stsrc', {name: 'smalltalk'}); 167 | 168 | }); 169 | -------------------------------------------------------------------------------- /mode/solr/solr.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineMode("solr", function() { 15 | "use strict"; 16 | 17 | var isStringChar = /[^\s\|\!\+\-\*\?\~\^\&\:\(\)\[\]\{\}\"\\]/; 18 | var isOperatorChar = /[\|\!\+\-\*\?\~\^\&]/; 19 | var isOperatorString = /^(OR|AND|NOT|TO)$/i; 20 | 21 | function isNumber(word) { 22 | return parseFloat(word).toString() === word; 23 | } 24 | 25 | function tokenString(quote) { 26 | return function(stream, state) { 27 | var escaped = false, next; 28 | while ((next = stream.next()) != null) { 29 | if (next == quote && !escaped) break; 30 | escaped = !escaped && next == "\\"; 31 | } 32 | 33 | if (!escaped) state.tokenize = tokenBase; 34 | return "string"; 35 | }; 36 | } 37 | 38 | function tokenOperator(operator) { 39 | return function(stream, state) { 40 | var style = "operator"; 41 | if (operator == "+") 42 | style += " positive"; 43 | else if (operator == "-") 44 | style += " negative"; 45 | else if (operator == "|") 46 | stream.eat(/\|/); 47 | else if (operator == "&") 48 | stream.eat(/\&/); 49 | else if (operator == "^") 50 | style += " boost"; 51 | 52 | state.tokenize = tokenBase; 53 | return style; 54 | }; 55 | } 56 | 57 | function tokenWord(ch) { 58 | return function(stream, state) { 59 | var word = ch; 60 | while ((ch = stream.peek()) && ch.match(isStringChar) != null) { 61 | word += stream.next(); 62 | } 63 | 64 | state.tokenize = tokenBase; 65 | if (isOperatorString.test(word)) 66 | return "operator"; 67 | else if (isNumber(word)) 68 | return "number"; 69 | else if (stream.peek() == ":") 70 | return "field"; 71 | else 72 | return "string"; 73 | }; 74 | } 75 | 76 | function tokenBase(stream, state) { 77 | var ch = stream.next(); 78 | if (ch == '"') 79 | state.tokenize = tokenString(ch); 80 | else if (isOperatorChar.test(ch)) 81 | state.tokenize = tokenOperator(ch); 82 | else if (isStringChar.test(ch)) 83 | state.tokenize = tokenWord(ch); 84 | 85 | return (state.tokenize != tokenBase) ? state.tokenize(stream, state) : null; 86 | } 87 | 88 | return { 89 | startState: function() { 90 | return { 91 | tokenize: tokenBase 92 | }; 93 | }, 94 | 95 | token: function(stream, state) { 96 | if (stream.eatSpace()) return null; 97 | return state.tokenize(stream, state); 98 | } 99 | }; 100 | }); 101 | 102 | CodeMirror.defineMIME("text/x-solr", "solr"); 103 | 104 | }); 105 | -------------------------------------------------------------------------------- /mode/spreadsheet/spreadsheet.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineMode("spreadsheet", function () { 15 | return { 16 | startState: function () { 17 | return { 18 | stringType: null, 19 | stack: [] 20 | }; 21 | }, 22 | token: function (stream, state) { 23 | if (!stream) return; 24 | 25 | //check for state changes 26 | if (state.stack.length === 0) { 27 | //strings 28 | if ((stream.peek() == '"') || (stream.peek() == "'")) { 29 | state.stringType = stream.peek(); 30 | stream.next(); // Skip quote 31 | state.stack.unshift("string"); 32 | } 33 | } 34 | 35 | //return state 36 | //stack has 37 | switch (state.stack[0]) { 38 | case "string": 39 | while (state.stack[0] === "string" && !stream.eol()) { 40 | if (stream.peek() === state.stringType) { 41 | stream.next(); // Skip quote 42 | state.stack.shift(); // Clear flag 43 | } else if (stream.peek() === "\\") { 44 | stream.next(); 45 | stream.next(); 46 | } else { 47 | stream.match(/^.[^\\\"\']*/); 48 | } 49 | } 50 | return "string"; 51 | 52 | case "characterClass": 53 | while (state.stack[0] === "characterClass" && !stream.eol()) { 54 | if (!(stream.match(/^[^\]\\]+/) || stream.match(/^\\./))) 55 | state.stack.shift(); 56 | } 57 | return "operator"; 58 | } 59 | 60 | var peek = stream.peek(); 61 | 62 | //no stack 63 | switch (peek) { 64 | case "[": 65 | stream.next(); 66 | state.stack.unshift("characterClass"); 67 | return "bracket"; 68 | case ":": 69 | stream.next(); 70 | return "operator"; 71 | case "\\": 72 | if (stream.match(/\\[a-z]+/)) return "string-2"; 73 | else { 74 | stream.next(); 75 | return "atom"; 76 | } 77 | case ".": 78 | case ",": 79 | case ";": 80 | case "*": 81 | case "-": 82 | case "+": 83 | case "^": 84 | case "<": 85 | case "/": 86 | case "=": 87 | stream.next(); 88 | return "atom"; 89 | case "$": 90 | stream.next(); 91 | return "builtin"; 92 | } 93 | 94 | if (stream.match(/\d+/)) { 95 | if (stream.match(/^\w+/)) return "error"; 96 | return "number"; 97 | } else if (stream.match(/^[a-zA-Z_]\w*/)) { 98 | if (stream.match(/(?=[\(.])/, false)) return "keyword"; 99 | return "variable-2"; 100 | } else if (["[", "]", "(", ")", "{", "}"].indexOf(peek) != -1) { 101 | stream.next(); 102 | return "bracket"; 103 | } else if (!stream.eatSpace()) { 104 | stream.next(); 105 | } 106 | return null; 107 | } 108 | }; 109 | }); 110 | 111 | CodeMirror.defineMIME("text/x-spreadsheet", "spreadsheet"); 112 | }); 113 | -------------------------------------------------------------------------------- /mode/tcl/tcl.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | //tcl mode by Ford_Lawnmower :: Based on Velocity mode by Steve O'Hara 5 | 6 | (function(mod) { 7 | if (typeof exports == "object" && typeof module == "object") // CommonJS 8 | mod(require("../../lib/codemirror")); 9 | else if (typeof define == "function" && define.amd) // AMD 10 | define(["../../lib/codemirror"], mod); 11 | else // Plain browser env 12 | mod(CodeMirror); 13 | })(function(CodeMirror) { 14 | "use strict"; 15 | 16 | CodeMirror.defineMode("tcl", function() { 17 | function parseWords(str) { 18 | var obj = {}, words = str.split(" "); 19 | for (var i = 0; i < words.length; ++i) obj[words[i]] = true; 20 | return obj; 21 | } 22 | var keywords = parseWords("Tcl safe after append array auto_execok auto_import auto_load " + 23 | "auto_mkindex auto_mkindex_old auto_qualify auto_reset bgerror " + 24 | "binary break catch cd close concat continue dde eof encoding error " + 25 | "eval exec exit expr fblocked fconfigure fcopy file fileevent filename " + 26 | "filename flush for foreach format gets glob global history http if " + 27 | "incr info interp join lappend lindex linsert list llength load lrange " + 28 | "lreplace lsearch lset lsort memory msgcat namespace open package parray " + 29 | "pid pkg::create pkg_mkIndex proc puts pwd re_syntax read regex regexp " + 30 | "registry regsub rename resource return scan seek set socket source split " + 31 | "string subst switch tcl_endOfWord tcl_findLibrary tcl_startOfNextWord " + 32 | "tcl_wordBreakAfter tcl_startOfPreviousWord tcl_wordBreakBefore tcltest " + 33 | "tclvars tell time trace unknown unset update uplevel upvar variable " + 34 | "vwait"); 35 | var functions = parseWords("if elseif else and not or eq ne in ni for foreach while switch"); 36 | var isOperatorChar = /[+\-*&%=<>!?^\/\|]/; 37 | function chain(stream, state, f) { 38 | state.tokenize = f; 39 | return f(stream, state); 40 | } 41 | function tokenBase(stream, state) { 42 | var beforeParams = state.beforeParams; 43 | state.beforeParams = false; 44 | var ch = stream.next(); 45 | if ((ch == '"' || ch == "'") && state.inParams) { 46 | return chain(stream, state, tokenString(ch)); 47 | } else if (/[\[\]{}\(\),;\.]/.test(ch)) { 48 | if (ch == "(" && beforeParams) state.inParams = true; 49 | else if (ch == ")") state.inParams = false; 50 | return null; 51 | } else if (/\d/.test(ch)) { 52 | stream.eatWhile(/[\w\.]/); 53 | return "number"; 54 | } else if (ch == "#") { 55 | if (stream.eat("*")) 56 | return chain(stream, state, tokenComment); 57 | if (ch == "#" && stream.match(/ *\[ *\[/)) 58 | return chain(stream, state, tokenUnparsed); 59 | stream.skipToEnd(); 60 | return "comment"; 61 | } else if (ch == '"') { 62 | stream.skipTo(/"/); 63 | return "comment"; 64 | } else if (ch == "$") { 65 | stream.eatWhile(/[$_a-z0-9A-Z\.{:]/); 66 | stream.eatWhile(/}/); 67 | state.beforeParams = true; 68 | return "builtin"; 69 | } else if (isOperatorChar.test(ch)) { 70 | stream.eatWhile(isOperatorChar); 71 | return "comment"; 72 | } else { 73 | stream.eatWhile(/[\w\$_{}\xa1-\uffff]/); 74 | var word = stream.current().toLowerCase(); 75 | if (keywords && keywords.propertyIsEnumerable(word)) 76 | return "keyword"; 77 | if (functions && functions.propertyIsEnumerable(word)) { 78 | state.beforeParams = true; 79 | return "keyword"; 80 | } 81 | return null; 82 | } 83 | } 84 | function tokenString(quote) { 85 | return function(stream, state) { 86 | var escaped = false, next, end = false; 87 | while ((next = stream.next()) != null) { 88 | if (next == quote && !escaped) { 89 | end = true; 90 | break; 91 | } 92 | escaped = !escaped && next == "\\"; 93 | } 94 | if (end) state.tokenize = tokenBase; 95 | return "string"; 96 | }; 97 | } 98 | function tokenComment(stream, state) { 99 | var maybeEnd = false, ch; 100 | while (ch = stream.next()) { 101 | if (ch == "#" && maybeEnd) { 102 | state.tokenize = tokenBase; 103 | break; 104 | } 105 | maybeEnd = (ch == "*"); 106 | } 107 | return "comment"; 108 | } 109 | function tokenUnparsed(stream, state) { 110 | var maybeEnd = 0, ch; 111 | while (ch = stream.next()) { 112 | if (ch == "#" && maybeEnd == 2) { 113 | state.tokenize = tokenBase; 114 | break; 115 | } 116 | if (ch == "]") 117 | maybeEnd++; 118 | else if (ch != " ") 119 | maybeEnd = 0; 120 | } 121 | return "meta"; 122 | } 123 | return { 124 | startState: function() { 125 | return { 126 | tokenize: tokenBase, 127 | beforeParams: false, 128 | inParams: false 129 | }; 130 | }, 131 | token: function(stream, state) { 132 | if (stream.eatSpace()) return null; 133 | return state.tokenize(stream, state); 134 | }, 135 | lineComment: "#" 136 | }; 137 | }); 138 | CodeMirror.defineMIME("text/x-tcl", "tcl"); 139 | 140 | }); 141 | -------------------------------------------------------------------------------- /mode/tiddlywiki/tiddlywiki.css: -------------------------------------------------------------------------------- 1 | span.cm-underlined { 2 | text-decoration: underline; 3 | } 4 | span.cm-strikethrough { 5 | text-decoration: line-through; 6 | } 7 | span.cm-brace { 8 | color: #170; 9 | font-weight: bold; 10 | } 11 | span.cm-table { 12 | color: blue; 13 | font-weight: bold; 14 | } 15 | -------------------------------------------------------------------------------- /mode/tiki/tiki.css: -------------------------------------------------------------------------------- 1 | .cm-tw-syntaxerror { 2 | color: #FFF; 3 | background-color: #900; 4 | } 5 | 6 | .cm-tw-deleted { 7 | text-decoration: line-through; 8 | } 9 | 10 | .cm-tw-header5 { 11 | font-weight: bold; 12 | } 13 | .cm-tw-listitem:first-child { /*Added first child to fix duplicate padding when highlighting*/ 14 | padding-left: 10px; 15 | } 16 | 17 | .cm-tw-box { 18 | border-top-width: 0px !important; 19 | border-style: solid; 20 | border-width: 1px; 21 | border-color: inherit; 22 | } 23 | 24 | .cm-tw-underline { 25 | text-decoration: underline; 26 | } -------------------------------------------------------------------------------- /mode/toml/toml.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineMode("toml", function () { 15 | return { 16 | startState: function () { 17 | return { 18 | inString: false, 19 | stringType: "", 20 | lhs: true, 21 | inArray: 0 22 | }; 23 | }, 24 | token: function (stream, state) { 25 | //check for state changes 26 | if (!state.inString && ((stream.peek() == '"') || (stream.peek() == "'"))) { 27 | state.stringType = stream.peek(); 28 | stream.next(); // Skip quote 29 | state.inString = true; // Update state 30 | } 31 | if (stream.sol() && state.inArray === 0) { 32 | state.lhs = true; 33 | } 34 | //return state 35 | if (state.inString) { 36 | while (state.inString && !stream.eol()) { 37 | if (stream.peek() === state.stringType) { 38 | stream.next(); // Skip quote 39 | state.inString = false; // Clear flag 40 | } else if (stream.peek() === '\\') { 41 | stream.next(); 42 | stream.next(); 43 | } else { 44 | stream.match(/^.[^\\\"\']*/); 45 | } 46 | } 47 | return state.lhs ? "property string" : "string"; // Token style 48 | } else if (state.inArray && stream.peek() === ']') { 49 | stream.next(); 50 | state.inArray--; 51 | return 'bracket'; 52 | } else if (state.lhs && stream.peek() === '[' && stream.skipTo(']')) { 53 | stream.next();//skip closing ] 54 | // array of objects has an extra open & close [] 55 | if (stream.peek() === ']') stream.next(); 56 | return "atom"; 57 | } else if (stream.peek() === "#") { 58 | stream.skipToEnd(); 59 | return "comment"; 60 | } else if (stream.eatSpace()) { 61 | return null; 62 | } else if (state.lhs && stream.eatWhile(function (c) { return c != '=' && c != ' '; })) { 63 | return "property"; 64 | } else if (state.lhs && stream.peek() === "=") { 65 | stream.next(); 66 | state.lhs = false; 67 | return null; 68 | } else if (!state.lhs && stream.match(/^\d\d\d\d[\d\-\:\.T]*Z/)) { 69 | return 'atom'; //date 70 | } else if (!state.lhs && (stream.match('true') || stream.match('false'))) { 71 | return 'atom'; 72 | } else if (!state.lhs && stream.peek() === '[') { 73 | state.inArray++; 74 | stream.next(); 75 | return 'bracket'; 76 | } else if (!state.lhs && stream.match(/^\-?\d+(?:\.\d+)?/)) { 77 | return 'number'; 78 | } else if (!stream.eatSpace()) { 79 | stream.next(); 80 | } 81 | return null; 82 | } 83 | }; 84 | }); 85 | 86 | CodeMirror.defineMIME('text/x-toml', 'toml'); 87 | 88 | }); 89 | -------------------------------------------------------------------------------- /mode/tornado/tornado.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror"), require("../htmlmixed/htmlmixed"), 7 | require("../../addon/mode/overlay")); 8 | else if (typeof define == "function" && define.amd) // AMD 9 | define(["../../lib/codemirror", "../htmlmixed/htmlmixed", 10 | "../../addon/mode/overlay"], mod); 11 | else // Plain browser env 12 | mod(CodeMirror); 13 | })(function(CodeMirror) { 14 | "use strict"; 15 | 16 | CodeMirror.defineMode("tornado:inner", function() { 17 | var keywords = ["and","as","assert","autoescape","block","break","class","comment","context", 18 | "continue","datetime","def","del","elif","else","end","escape","except", 19 | "exec","extends","false","finally","for","from","global","if","import","in", 20 | "include","is","json_encode","lambda","length","linkify","load","module", 21 | "none","not","or","pass","print","put","raise","raw","return","self","set", 22 | "squeeze","super","true","try","url_escape","while","with","without","xhtml_escape","yield"]; 23 | keywords = new RegExp("^((" + keywords.join(")|(") + "))\\b"); 24 | 25 | function tokenBase (stream, state) { 26 | stream.eatWhile(/[^\{]/); 27 | var ch = stream.next(); 28 | if (ch == "{") { 29 | if (ch = stream.eat(/\{|%|#/)) { 30 | state.tokenize = inTag(ch); 31 | return "tag"; 32 | } 33 | } 34 | } 35 | function inTag (close) { 36 | if (close == "{") { 37 | close = "}"; 38 | } 39 | return function (stream, state) { 40 | var ch = stream.next(); 41 | if ((ch == close) && stream.eat("}")) { 42 | state.tokenize = tokenBase; 43 | return "tag"; 44 | } 45 | if (stream.match(keywords)) { 46 | return "keyword"; 47 | } 48 | return close == "#" ? "comment" : "string"; 49 | }; 50 | } 51 | return { 52 | startState: function () { 53 | return {tokenize: tokenBase}; 54 | }, 55 | token: function (stream, state) { 56 | return state.tokenize(stream, state); 57 | } 58 | }; 59 | }); 60 | 61 | CodeMirror.defineMode("tornado", function(config) { 62 | var htmlBase = CodeMirror.getMode(config, "text/html"); 63 | var tornadoInner = CodeMirror.getMode(config, "tornado:inner"); 64 | return CodeMirror.overlayMode(htmlBase, tornadoInner); 65 | }); 66 | 67 | CodeMirror.defineMIME("text/x-tornado", "tornado"); 68 | }); 69 | -------------------------------------------------------------------------------- /mode/troff/troff.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) 8 | define(["../../lib/codemirror"], mod); 9 | else 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineMode('troff', function() { 15 | 16 | var words = {}; 17 | 18 | function tokenBase(stream) { 19 | if (stream.eatSpace()) return null; 20 | 21 | var sol = stream.sol(); 22 | var ch = stream.next(); 23 | 24 | if (ch === '\\') { 25 | if (stream.match('fB') || stream.match('fR') || stream.match('fI') || 26 | stream.match('u') || stream.match('d') || 27 | stream.match('%') || stream.match('&')) { 28 | return 'string'; 29 | } 30 | if (stream.match('m[')) { 31 | stream.skipTo(']'); 32 | stream.next(); 33 | return 'string'; 34 | } 35 | if (stream.match('s+') || stream.match('s-')) { 36 | stream.eatWhile(/[\d-]/); 37 | return 'string'; 38 | } 39 | if (stream.match('\(') || stream.match('*\(')) { 40 | stream.eatWhile(/[\w-]/); 41 | return 'string'; 42 | } 43 | return 'string'; 44 | } 45 | if (sol && (ch === '.' || ch === '\'')) { 46 | if (stream.eat('\\') && stream.eat('\"')) { 47 | stream.skipToEnd(); 48 | return 'comment'; 49 | } 50 | } 51 | if (sol && ch === '.') { 52 | if (stream.match('B ') || stream.match('I ') || stream.match('R ')) { 53 | return 'attribute'; 54 | } 55 | if (stream.match('TH ') || stream.match('SH ') || stream.match('SS ') || stream.match('HP ')) { 56 | stream.skipToEnd(); 57 | return 'quote'; 58 | } 59 | if ((stream.match(/[A-Z]/) && stream.match(/[A-Z]/)) || (stream.match(/[a-z]/) && stream.match(/[a-z]/))) { 60 | return 'attribute'; 61 | } 62 | } 63 | stream.eatWhile(/[\w-]/); 64 | var cur = stream.current(); 65 | return words.hasOwnProperty(cur) ? words[cur] : null; 66 | } 67 | 68 | function tokenize(stream, state) { 69 | return (state.tokens[0] || tokenBase) (stream, state); 70 | }; 71 | 72 | return { 73 | startState: function() {return {tokens:[]};}, 74 | token: function(stream, state) { 75 | return tokenize(stream, state); 76 | } 77 | }; 78 | }); 79 | 80 | CodeMirror.defineMIME('text/troff', 'troff'); 81 | CodeMirror.defineMIME('text/x-troff', 'troff'); 82 | CodeMirror.defineMIME('application/x-troff', 'troff'); 83 | 84 | }); 85 | -------------------------------------------------------------------------------- /mode/turtle/turtle.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineMode("turtle", function(config) { 15 | var indentUnit = config.indentUnit; 16 | var curPunc; 17 | 18 | function wordRegexp(words) { 19 | return new RegExp("^(?:" + words.join("|") + ")$", "i"); 20 | } 21 | var ops = wordRegexp([]); 22 | var keywords = wordRegexp(["@prefix", "@base", "a"]); 23 | var operatorChars = /[*+\-<>=&|]/; 24 | 25 | function tokenBase(stream, state) { 26 | var ch = stream.next(); 27 | curPunc = null; 28 | if (ch == "<" && !stream.match(/^[\s\u00a0=]/, false)) { 29 | stream.match(/^[^\s\u00a0>]*>?/); 30 | return "atom"; 31 | } 32 | else if (ch == "\"" || ch == "'") { 33 | state.tokenize = tokenLiteral(ch); 34 | return state.tokenize(stream, state); 35 | } 36 | else if (/[{}\(\),\.;\[\]]/.test(ch)) { 37 | curPunc = ch; 38 | return null; 39 | } 40 | else if (ch == "#") { 41 | stream.skipToEnd(); 42 | return "comment"; 43 | } 44 | else if (operatorChars.test(ch)) { 45 | stream.eatWhile(operatorChars); 46 | return null; 47 | } 48 | else if (ch == ":") { 49 | return "operator"; 50 | } else { 51 | stream.eatWhile(/[_\w\d]/); 52 | if(stream.peek() == ":") { 53 | return "variable-3"; 54 | } else { 55 | var word = stream.current(); 56 | 57 | if(keywords.test(word)) { 58 | return "meta"; 59 | } 60 | 61 | if(ch >= "A" && ch <= "Z") { 62 | return "comment"; 63 | } else { 64 | return "keyword"; 65 | } 66 | } 67 | var word = stream.current(); 68 | if (ops.test(word)) 69 | return null; 70 | else if (keywords.test(word)) 71 | return "meta"; 72 | else 73 | return "variable"; 74 | } 75 | } 76 | 77 | function tokenLiteral(quote) { 78 | return function(stream, state) { 79 | var escaped = false, ch; 80 | while ((ch = stream.next()) != null) { 81 | if (ch == quote && !escaped) { 82 | state.tokenize = tokenBase; 83 | break; 84 | } 85 | escaped = !escaped && ch == "\\"; 86 | } 87 | return "string"; 88 | }; 89 | } 90 | 91 | function pushContext(state, type, col) { 92 | state.context = {prev: state.context, indent: state.indent, col: col, type: type}; 93 | } 94 | function popContext(state) { 95 | state.indent = state.context.indent; 96 | state.context = state.context.prev; 97 | } 98 | 99 | return { 100 | startState: function() { 101 | return {tokenize: tokenBase, 102 | context: null, 103 | indent: 0, 104 | col: 0}; 105 | }, 106 | 107 | token: function(stream, state) { 108 | if (stream.sol()) { 109 | if (state.context && state.context.align == null) state.context.align = false; 110 | state.indent = stream.indentation(); 111 | } 112 | if (stream.eatSpace()) return null; 113 | var style = state.tokenize(stream, state); 114 | 115 | if (style != "comment" && state.context && state.context.align == null && state.context.type != "pattern") { 116 | state.context.align = true; 117 | } 118 | 119 | if (curPunc == "(") pushContext(state, ")", stream.column()); 120 | else if (curPunc == "[") pushContext(state, "]", stream.column()); 121 | else if (curPunc == "{") pushContext(state, "}", stream.column()); 122 | else if (/[\]\}\)]/.test(curPunc)) { 123 | while (state.context && state.context.type == "pattern") popContext(state); 124 | if (state.context && curPunc == state.context.type) popContext(state); 125 | } 126 | else if (curPunc == "." && state.context && state.context.type == "pattern") popContext(state); 127 | else if (/atom|string|variable/.test(style) && state.context) { 128 | if (/[\}\]]/.test(state.context.type)) 129 | pushContext(state, "pattern", stream.column()); 130 | else if (state.context.type == "pattern" && !state.context.align) { 131 | state.context.align = true; 132 | state.context.col = stream.column(); 133 | } 134 | } 135 | 136 | return style; 137 | }, 138 | 139 | indent: function(state, textAfter) { 140 | var firstChar = textAfter && textAfter.charAt(0); 141 | var context = state.context; 142 | if (/[\]\}]/.test(firstChar)) 143 | while (context && context.type == "pattern") context = context.prev; 144 | 145 | var closing = context && firstChar == context.type; 146 | if (!context) 147 | return 0; 148 | else if (context.type == "pattern") 149 | return context.col; 150 | else if (context.align) 151 | return context.col + (closing ? 0 : 1); 152 | else 153 | return context.indent + (closing ? 0 : indentUnit); 154 | }, 155 | 156 | lineComment: "#" 157 | }; 158 | }); 159 | 160 | CodeMirror.defineMIME("text/turtle", "turtle"); 161 | 162 | }); 163 | -------------------------------------------------------------------------------- /mode/twig/twig.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror"), require("../../addon/mode/multiplex")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror", "../../addon/mode/multiplex"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineMode("twig:inner", function() { 15 | var keywords = ["and", "as", "autoescape", "endautoescape", "block", "do", "endblock", "else", "elseif", "extends", "for", "endfor", "embed", "endembed", "filter", "endfilter", "flush", "from", "if", "endif", "in", "is", "include", "import", "not", "or", "set", "spaceless", "endspaceless", "with", "endwith", "trans", "endtrans", "blocktrans", "endblocktrans", "macro", "endmacro", "use", "verbatim", "endverbatim"], 16 | operator = /^[+\-*&%=<>!?|~^]/, 17 | sign = /^[:\[\(\{]/, 18 | atom = ["true", "false", "null", "empty", "defined", "divisibleby", "divisible by", "even", "odd", "iterable", "sameas", "same as"], 19 | number = /^(\d[+\-\*\/])?\d+(\.\d+)?/; 20 | 21 | keywords = new RegExp("((" + keywords.join(")|(") + "))\\b"); 22 | atom = new RegExp("((" + atom.join(")|(") + "))\\b"); 23 | 24 | function tokenBase (stream, state) { 25 | var ch = stream.peek(); 26 | 27 | //Comment 28 | if (state.incomment) { 29 | if (!stream.skipTo("#}")) { 30 | stream.skipToEnd(); 31 | } else { 32 | stream.eatWhile(/\#|}/); 33 | state.incomment = false; 34 | } 35 | return "comment"; 36 | //Tag 37 | } else if (state.intag) { 38 | //After operator 39 | if (state.operator) { 40 | state.operator = false; 41 | if (stream.match(atom)) { 42 | return "atom"; 43 | } 44 | if (stream.match(number)) { 45 | return "number"; 46 | } 47 | } 48 | //After sign 49 | if (state.sign) { 50 | state.sign = false; 51 | if (stream.match(atom)) { 52 | return "atom"; 53 | } 54 | if (stream.match(number)) { 55 | return "number"; 56 | } 57 | } 58 | 59 | if (state.instring) { 60 | if (ch == state.instring) { 61 | state.instring = false; 62 | } 63 | stream.next(); 64 | return "string"; 65 | } else if (ch == "'" || ch == '"') { 66 | state.instring = ch; 67 | stream.next(); 68 | return "string"; 69 | } else if (stream.match(state.intag + "}") || stream.eat("-") && stream.match(state.intag + "}")) { 70 | state.intag = false; 71 | return "tag"; 72 | } else if (stream.match(operator)) { 73 | state.operator = true; 74 | return "operator"; 75 | } else if (stream.match(sign)) { 76 | state.sign = true; 77 | } else { 78 | if (stream.eat(" ") || stream.sol()) { 79 | if (stream.match(keywords)) { 80 | return "keyword"; 81 | } 82 | if (stream.match(atom)) { 83 | return "atom"; 84 | } 85 | if (stream.match(number)) { 86 | return "number"; 87 | } 88 | if (stream.sol()) { 89 | stream.next(); 90 | } 91 | } else { 92 | stream.next(); 93 | } 94 | 95 | } 96 | return "variable"; 97 | } else if (stream.eat("{")) { 98 | if (stream.eat("#")) { 99 | state.incomment = true; 100 | if (!stream.skipTo("#}")) { 101 | stream.skipToEnd(); 102 | } else { 103 | stream.eatWhile(/\#|}/); 104 | state.incomment = false; 105 | } 106 | return "comment"; 107 | //Open tag 108 | } else if (ch = stream.eat(/\{|%/)) { 109 | //Cache close tag 110 | state.intag = ch; 111 | if (ch == "{") { 112 | state.intag = "}"; 113 | } 114 | stream.eat("-"); 115 | return "tag"; 116 | } 117 | } 118 | stream.next(); 119 | }; 120 | 121 | return { 122 | startState: function () { 123 | return {}; 124 | }, 125 | token: function (stream, state) { 126 | return tokenBase(stream, state); 127 | } 128 | }; 129 | }); 130 | 131 | CodeMirror.defineMode("twig", function(config, parserConfig) { 132 | var twigInner = CodeMirror.getMode(config, "twig:inner"); 133 | if (!parserConfig || !parserConfig.base) return twigInner; 134 | return CodeMirror.multiplexingMode( 135 | CodeMirror.getMode(config, parserConfig.base), { 136 | open: /\{[{#%]/, close: /[}#%]\}/, mode: twigInner, parseDelimiters: true 137 | } 138 | ); 139 | }); 140 | CodeMirror.defineMIME("text/x-twig", "twig"); 141 | }); 142 | -------------------------------------------------------------------------------- /mode/vue/vue.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function (mod) { 5 | "use strict"; 6 | if (typeof exports === "object" && typeof module === "object") {// CommonJS 7 | mod(require("../../lib/codemirror"), 8 | require("../../addon/mode/overlay"), 9 | require("../xml/xml"), 10 | require("../javascript/javascript"), 11 | require("../coffeescript/coffeescript"), 12 | require("../css/css"), 13 | require("../sass/sass"), 14 | require("../stylus/stylus"), 15 | require("../pug/pug"), 16 | require("../handlebars/handlebars")); 17 | } else if (typeof define === "function" && define.amd) { // AMD 18 | define(["../../lib/codemirror", 19 | "../../addon/mode/overlay", 20 | "../xml/xml", 21 | "../javascript/javascript", 22 | "../coffeescript/coffeescript", 23 | "../css/css", 24 | "../sass/sass", 25 | "../stylus/stylus", 26 | "../pug/pug", 27 | "../handlebars/handlebars"], mod); 28 | } else { // Plain browser env 29 | mod(CodeMirror); 30 | } 31 | })(function (CodeMirror) { 32 | var tagLanguages = { 33 | script: [ 34 | ["lang", /coffee(script)?/, "coffeescript"], 35 | ["type", /^(?:text|application)\/(?:x-)?coffee(?:script)?$/, "coffeescript"], 36 | ["lang", /^babel$/, "javascript"], 37 | ["type", /^text\/babel$/, "javascript"], 38 | ["type", /^text\/ecmascript-\d+$/, "javascript"] 39 | ], 40 | style: [ 41 | ["lang", /^stylus$/i, "stylus"], 42 | ["lang", /^sass$/i, "sass"], 43 | ["lang", /^less$/i, "text/x-less"], 44 | ["lang", /^scss$/i, "text/x-scss"], 45 | ["type", /^(text\/)?(x-)?styl(us)?$/i, "stylus"], 46 | ["type", /^text\/sass/i, "sass"], 47 | ["type", /^(text\/)?(x-)?scss$/i, "text/x-scss"], 48 | ["type", /^(text\/)?(x-)?less$/i, "text/x-less"] 49 | ], 50 | template: [ 51 | ["lang", /^vue-template$/i, "vue"], 52 | ["lang", /^pug$/i, "pug"], 53 | ["lang", /^handlebars$/i, "handlebars"], 54 | ["type", /^(text\/)?(x-)?pug$/i, "pug"], 55 | ["type", /^text\/x-handlebars-template$/i, "handlebars"], 56 | [null, null, "vue-template"] 57 | ] 58 | }; 59 | 60 | CodeMirror.defineMode("vue-template", function (config, parserConfig) { 61 | var mustacheOverlay = { 62 | token: function (stream) { 63 | if (stream.match(/^\{\{.*?\}\}/)) return "meta mustache"; 64 | while (stream.next() && !stream.match("{{", false)) {} 65 | return null; 66 | } 67 | }; 68 | return CodeMirror.overlayMode(CodeMirror.getMode(config, parserConfig.backdrop || "text/html"), mustacheOverlay); 69 | }); 70 | 71 | CodeMirror.defineMode("vue", function (config) { 72 | return CodeMirror.getMode(config, {name: "htmlmixed", tags: tagLanguages}); 73 | }, "htmlmixed", "xml", "javascript", "coffeescript", "css", "sass", "stylus", "pug", "handlebars"); 74 | 75 | CodeMirror.defineMIME("script/x-vue", "vue"); 76 | CodeMirror.defineMIME("text/x-vue", "vue"); 77 | }); 78 | -------------------------------------------------------------------------------- /mode/wast/wast.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror"), require("../../addon/mode/simple")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror", "../../addon/mode/simple"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineSimpleMode('wast', { 15 | start: [ 16 | {regex: /[+\-]?(?:nan(?::0x[0-9a-fA-F]+)?|infinity|inf|0x[0-9a-fA-F]+\.?[0-9a-fA-F]*p[+\/-]?\d+|\d+(?:\.\d*)?[eE][+\-]?\d*|\d+\.\d*|0x[0-9a-fA-F]+|\d+)/, token: "number"}, 17 | {regex: /mut|nop|block|if|then|else|loop|br_if|br_table|br|call(_indirect)?|drop|end|return(_call(_indirect)?)?|local\.(get|set|tee)|global\.(get|set)|i(32|64)\.(store(8|16)|(load(8|16)_[su]))|i64\.(load32_[su]|store32)|[fi](32|64)\.(const|load|store)|f(32|64)\.(abs|add|ceil|copysign|div|eq|floor|[gl][et]|max|min|mul|nearest|neg?|sqrt|sub|trunc)|i(32|64)\.(a[dn]d|c[lt]z|(div|rem)_[su]|eqz?|[gl][te]_[su]|mul|ne|popcnt|rot[lr]|sh(l|r_[su])|sub|x?or)|i64\.extend_[su]_i32|i32\.wrap_i64|i(32|64)\.trunc_f(32|64)_[su]|f(32|64)\.convert_i(32|64)_[su]|f64\.promote_f32|f32\.demote_f64|f32\.reinterpret_i32|i32\.reinterpret_f32|f64\.reinterpret_i64|i64\.reinterpret_f64|select|unreachable|current_memory|memory(\.((atomic\.(notify|wait(32|64)))|grow|size))?|type|func|param|result|local|global|module|table|start|elem|data|align|offset|import|export|i64\.atomic\.(load32_u|store32|rmw32\.(a[dn]d|sub|x?or|(cmp)?xchg)_u)|i(32|64)\.atomic\.(load((8|16)_u)?|store(8|16)?|rmw(\.(a[dn]d|sub|x?or|(cmp)?xchg)|(8|16)\.(a[dn]d|sub|x?or|(cmp)?xchg)_u))|v128\.(load|store|const|not|andnot|and|or|xor|bitselect)|i(8x16|16x8|32x4|64x2)\.(shl|shr_[su])|i(8x16|16x8)\.(extract_lane_[su]|((add|sub)_saturate_[su])|avgr_u)|(i(8x16|16x8|32x4|64x2)|f(32x4|64x2))\.(splat|replace_lane|neg|add|sub)|i(8x16|16x8|32x4)\.(eq|ne|([lg][te]_[su])|abs|any_true|all_true|bitmask|((min|max)_[su]))|f(32x4|64x2)\.(eq|ne|[lg][te]|abs|sqrt|mul|div|min|max)|[fi](32x4|64x2)\.extract_lane|v8x16\.(shuffle|swizzle)|i16x8\.(load8x8_[su]|narrow_i32x4_[su]|widen_(low|high)_i8x16_[su]|mul)|i32x4\.(load16x4_[su]|widen_(low|high)_i16x8_[su]|mul|trunc_sat_f32x4_[su])|i64x2\.(load32x2_[su]|mul)|(v(8x16|16x8|32x4|64x2)\.load_splat)|i8x16\.narrow_i16x8_[su]|f32x4\.convert_i32x4_[su]/, token: "keyword"}, 18 | {regex: /\b(anyfunc|[fi](32|64))\b/, token: "atom"}, 19 | {regex: /\$([a-zA-Z0-9_`\+\-\*\/\\\^~=<>!\?@#$%&|:\.]+)/, token: "variable-2"}, 20 | {regex: /"(?:[^"\\\x00-\x1f\x7f]|\\[nt\\'"]|\\[0-9a-fA-F][0-9a-fA-F])*"/, token: "string"}, 21 | {regex: /\(;.*?/, token: "comment", next: "comment"}, 22 | {regex: /;;.*$/, token: "comment"}, 23 | {regex: /\(/, indent: true}, 24 | {regex: /\)/, dedent: true}, 25 | ], 26 | 27 | comment: [ 28 | {regex: /.*?;\)/, token: "comment", next: "start"}, 29 | {regex: /.*/, token: "comment"}, 30 | ], 31 | 32 | meta: { 33 | dontIndentStates: ['comment'], 34 | }, 35 | }); 36 | 37 | // https://github.com/WebAssembly/design/issues/981 mentions text/webassembly, 38 | // which seems like a reasonable choice, although it's not standard right now. 39 | CodeMirror.defineMIME("text/webassembly", "wast"); 40 | 41 | }); 42 | -------------------------------------------------------------------------------- /mode/yaml-frontmatter/yaml-frontmatter.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function (mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror"), require("../yaml/yaml")) 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror", "../yaml/yaml"], mod) 9 | else // Plain browser env 10 | mod(CodeMirror) 11 | })(function (CodeMirror) { 12 | 13 | var START = 0, FRONTMATTER = 1, BODY = 2 14 | 15 | // a mixed mode for Markdown text with an optional YAML front matter 16 | CodeMirror.defineMode("yaml-frontmatter", function (config, parserConfig) { 17 | var yamlMode = CodeMirror.getMode(config, "yaml") 18 | var innerMode = CodeMirror.getMode(config, parserConfig && parserConfig.base || "gfm") 19 | 20 | function curMode(state) { 21 | return state.state == BODY ? innerMode : yamlMode 22 | } 23 | 24 | return { 25 | startState: function () { 26 | return { 27 | state: START, 28 | inner: CodeMirror.startState(yamlMode) 29 | } 30 | }, 31 | copyState: function (state) { 32 | return { 33 | state: state.state, 34 | inner: CodeMirror.copyState(curMode(state), state.inner) 35 | } 36 | }, 37 | token: function (stream, state) { 38 | if (state.state == START) { 39 | if (stream.match(/---/, false)) { 40 | state.state = FRONTMATTER 41 | return yamlMode.token(stream, state.inner) 42 | } else { 43 | state.state = BODY 44 | state.inner = CodeMirror.startState(innerMode) 45 | return innerMode.token(stream, state.inner) 46 | } 47 | } else if (state.state == FRONTMATTER) { 48 | var end = stream.sol() && stream.match(/(---|\.\.\.)/, false) 49 | var style = yamlMode.token(stream, state.inner) 50 | if (end) { 51 | state.state = BODY 52 | state.inner = CodeMirror.startState(innerMode) 53 | } 54 | return style 55 | } else { 56 | return innerMode.token(stream, state.inner) 57 | } 58 | }, 59 | innerMode: function (state) { 60 | return {mode: curMode(state), state: state.inner} 61 | }, 62 | blankLine: function (state) { 63 | var mode = curMode(state) 64 | if (mode.blankLine) return mode.blankLine(state.inner) 65 | } 66 | } 67 | }) 68 | }); 69 | -------------------------------------------------------------------------------- /mode/yaml/yaml.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineMode("yaml", function() { 15 | 16 | var cons = ['true', 'false', 'on', 'off', 'yes', 'no']; 17 | var keywordRegex = new RegExp("\\b(("+cons.join(")|(")+"))$", 'i'); 18 | 19 | return { 20 | token: function(stream, state) { 21 | var ch = stream.peek(); 22 | var esc = state.escaped; 23 | state.escaped = false; 24 | /* comments */ 25 | if (ch == "#" && (stream.pos == 0 || /\s/.test(stream.string.charAt(stream.pos - 1)))) { 26 | stream.skipToEnd(); 27 | return "comment"; 28 | } 29 | 30 | if (stream.match(/^('([^']|\\.)*'?|"([^"]|\\.)*"?)/)) 31 | return "string"; 32 | 33 | if (state.literal && stream.indentation() > state.keyCol) { 34 | stream.skipToEnd(); return "string"; 35 | } else if (state.literal) { state.literal = false; } 36 | if (stream.sol()) { 37 | state.keyCol = 0; 38 | state.pair = false; 39 | state.pairStart = false; 40 | /* document start */ 41 | if(stream.match(/---/)) { return "def"; } 42 | /* document end */ 43 | if (stream.match(/\.\.\./)) { return "def"; } 44 | /* array list item */ 45 | if (stream.match(/\s*-\s+/)) { return 'meta'; } 46 | } 47 | /* inline pairs/lists */ 48 | if (stream.match(/^(\{|\}|\[|\])/)) { 49 | if (ch == '{') 50 | state.inlinePairs++; 51 | else if (ch == '}') 52 | state.inlinePairs--; 53 | else if (ch == '[') 54 | state.inlineList++; 55 | else 56 | state.inlineList--; 57 | return 'meta'; 58 | } 59 | 60 | /* list seperator */ 61 | if (state.inlineList > 0 && !esc && ch == ',') { 62 | stream.next(); 63 | return 'meta'; 64 | } 65 | /* pairs seperator */ 66 | if (state.inlinePairs > 0 && !esc && ch == ',') { 67 | state.keyCol = 0; 68 | state.pair = false; 69 | state.pairStart = false; 70 | stream.next(); 71 | return 'meta'; 72 | } 73 | 74 | /* start of value of a pair */ 75 | if (state.pairStart) { 76 | /* block literals */ 77 | if (stream.match(/^\s*(\||\>)\s*/)) { state.literal = true; return 'meta'; }; 78 | /* references */ 79 | if (stream.match(/^\s*(\&|\*)[a-z0-9\._-]+\b/i)) { return 'variable-2'; } 80 | /* numbers */ 81 | if (state.inlinePairs == 0 && stream.match(/^\s*-?[0-9\.\,]+\s?$/)) { return 'number'; } 82 | if (state.inlinePairs > 0 && stream.match(/^\s*-?[0-9\.\,]+\s?(?=(,|}))/)) { return 'number'; } 83 | /* keywords */ 84 | if (stream.match(keywordRegex)) { return 'keyword'; } 85 | } 86 | 87 | /* pairs (associative arrays) -> key */ 88 | if (!state.pair && stream.match(/^\s*(?:[,\[\]{}&*!|>'"%@`][^\s'":]|[^,\[\]{}#&*!|>'"%@`])[^#]*?(?=\s*:($|\s))/)) { 89 | state.pair = true; 90 | state.keyCol = stream.indentation(); 91 | return "atom"; 92 | } 93 | if (state.pair && stream.match(/^:\s*/)) { state.pairStart = true; return 'meta'; } 94 | 95 | /* nothing found, continue */ 96 | state.pairStart = false; 97 | state.escaped = (ch == '\\'); 98 | stream.next(); 99 | return null; 100 | }, 101 | startState: function() { 102 | return { 103 | pair: false, 104 | pairStart: false, 105 | keyCol: 0, 106 | inlinePairs: 0, 107 | inlineList: 0, 108 | literal: false, 109 | escaped: false 110 | }; 111 | }, 112 | lineComment: "#", 113 | fold: "indent" 114 | }; 115 | }); 116 | 117 | CodeMirror.defineMIME("text/x-yaml", "yaml"); 118 | CodeMirror.defineMIME("text/yaml", "yaml"); 119 | 120 | }); 121 | -------------------------------------------------------------------------------- /mode/z80/z80.js: -------------------------------------------------------------------------------- 1 | // CodeMirror, copyright (c) by Marijn Haverbeke and others 2 | // Distributed under an MIT license: https://codemirror.net/LICENSE 3 | 4 | (function(mod) { 5 | if (typeof exports == "object" && typeof module == "object") // CommonJS 6 | mod(require("../../lib/codemirror")); 7 | else if (typeof define == "function" && define.amd) // AMD 8 | define(["../../lib/codemirror"], mod); 9 | else // Plain browser env 10 | mod(CodeMirror); 11 | })(function(CodeMirror) { 12 | "use strict"; 13 | 14 | CodeMirror.defineMode('z80', function(_config, parserConfig) { 15 | var ez80 = parserConfig.ez80; 16 | var keywords1, keywords2; 17 | if (ez80) { 18 | keywords1 = /^(exx?|(ld|cp)([di]r?)?|[lp]ea|pop|push|ad[cd]|cpl|daa|dec|inc|neg|sbc|sub|and|bit|[cs]cf|x?or|res|set|r[lr]c?a?|r[lr]d|s[lr]a|srl|djnz|nop|[de]i|halt|im|in([di]mr?|ir?|irx|2r?)|ot(dmr?|[id]rx|imr?)|out(0?|[di]r?|[di]2r?)|tst(io)?|slp)(\.([sl]?i)?[sl])?\b/i; 19 | keywords2 = /^(((call|j[pr]|rst|ret[in]?)(\.([sl]?i)?[sl])?)|(rs|st)mix)\b/i; 20 | } else { 21 | keywords1 = /^(exx?|(ld|cp|in)([di]r?)?|pop|push|ad[cd]|cpl|daa|dec|inc|neg|sbc|sub|and|bit|[cs]cf|x?or|res|set|r[lr]c?a?|r[lr]d|s[lr]a|srl|djnz|nop|rst|[de]i|halt|im|ot[di]r|out[di]?)\b/i; 22 | keywords2 = /^(call|j[pr]|ret[in]?|b_?(call|jump))\b/i; 23 | } 24 | 25 | var variables1 = /^(af?|bc?|c|de?|e|hl?|l|i[xy]?|r|sp)\b/i; 26 | var variables2 = /^(n?[zc]|p[oe]?|m)\b/i; 27 | var errors = /^([hl][xy]|i[xy][hl]|slia|sll)\b/i; 28 | var numbers = /^([\da-f]+h|[0-7]+o|[01]+b|\d+d?)\b/i; 29 | 30 | return { 31 | startState: function() { 32 | return { 33 | context: 0 34 | }; 35 | }, 36 | token: function(stream, state) { 37 | if (!stream.column()) 38 | state.context = 0; 39 | 40 | if (stream.eatSpace()) 41 | return null; 42 | 43 | var w; 44 | 45 | if (stream.eatWhile(/\w/)) { 46 | if (ez80 && stream.eat('.')) { 47 | stream.eatWhile(/\w/); 48 | } 49 | w = stream.current(); 50 | 51 | if (stream.indentation()) { 52 | if ((state.context == 1 || state.context == 4) && variables1.test(w)) { 53 | state.context = 4; 54 | return 'var2'; 55 | } 56 | 57 | if (state.context == 2 && variables2.test(w)) { 58 | state.context = 4; 59 | return 'var3'; 60 | } 61 | 62 | if (keywords1.test(w)) { 63 | state.context = 1; 64 | return 'keyword'; 65 | } else if (keywords2.test(w)) { 66 | state.context = 2; 67 | return 'keyword'; 68 | } else if (state.context == 4 && numbers.test(w)) { 69 | return 'number'; 70 | } 71 | 72 | if (errors.test(w)) 73 | return 'error'; 74 | } else if (stream.match(numbers)) { 75 | return 'number'; 76 | } else { 77 | return null; 78 | } 79 | } else if (stream.eat(';')) { 80 | stream.skipToEnd(); 81 | return 'comment'; 82 | } else if (stream.eat('"')) { 83 | while (w = stream.next()) { 84 | if (w == '"') 85 | break; 86 | 87 | if (w == '\\') 88 | stream.next(); 89 | } 90 | return 'string'; 91 | } else if (stream.eat('\'')) { 92 | if (stream.match(/\\?.'/)) 93 | return 'number'; 94 | } else if (stream.eat('.') || stream.sol() && stream.eat('#')) { 95 | state.context = 5; 96 | 97 | if (stream.eatWhile(/\w/)) 98 | return 'def'; 99 | } else if (stream.eat('$')) { 100 | if (stream.eatWhile(/[\da-f]/i)) 101 | return 'number'; 102 | } else if (stream.eat('%')) { 103 | if (stream.eatWhile(/[01]/)) 104 | return 'number'; 105 | } else { 106 | stream.next(); 107 | } 108 | return null; 109 | } 110 | }; 111 | }); 112 | 113 | CodeMirror.defineMIME("text/x-z80", "z80"); 114 | CodeMirror.defineMIME("text/x-ez80", { name: "z80", ez80: true }); 115 | 116 | }); 117 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cm-editor-syntax-highlight-obsidian", 3 | "version": "0.1.3", 4 | "description": "Show syntax highlighing in code blocks the editor", 5 | "main": "main.js", 6 | "scripts": { 7 | "install-deps": "npm install", 8 | "update-deps": "npm update", 9 | "dev": "rollup --config rollup.config.js -w", 10 | "build": "rollup --config rollup.config.js" 11 | }, 12 | "keywords": [], 13 | "author": "death_au", 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/deathau/cm-editor-syntax-highlight-obsidian" 17 | }, 18 | "license": "MIT", 19 | "devDependencies": { 20 | "@rollup/plugin-commonjs": "^15.1.0", 21 | "@rollup/plugin-node-resolve": "^9.0.0", 22 | "@rollup/plugin-typescript": "^6.0.0", 23 | "@types/node": "^14.14.16", 24 | "obsidian": "https://github.com/obsidianmd/obsidian-api/tarball/master", 25 | "rollup": "^2.35.1", 26 | "rollup-plugin-scss": "^2.6.1", 27 | "sass": "^1.30.0", 28 | "tslib": "^2.0.3", 29 | "typescript": "^4.1.3" 30 | }, 31 | "dependencies": {} 32 | } 33 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import typescript from '@rollup/plugin-typescript'; 2 | import {nodeResolve} from '@rollup/plugin-node-resolve'; 3 | import commonjs from '@rollup/plugin-commonjs'; 4 | import scss from 'rollup-plugin-scss'; 5 | 6 | export default { 7 | input: 'main.ts', 8 | output: { 9 | dir: '.', 10 | sourcemap: 'inline', 11 | format: 'cjs', 12 | exports: 'default' 13 | }, 14 | external: ['obsidian'], 15 | plugins: [ 16 | typescript(), 17 | nodeResolve({browser: true}), 18 | commonjs(), 19 | scss({ output: 'styles.css', sass: require('sass') }) 20 | ] 21 | }; -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/deathau/cm-editor-syntax-highlight-obsidian/fb9a1a08a19491ceada0ebabad2ed5087885cb3b/screenshot.png -------------------------------------------------------------------------------- /styles.scss: -------------------------------------------------------------------------------- 1 | @use "sass:selector"; 2 | 3 | @mixin codeAndFrontmatter($child) { 4 | #{selector.unify(".cm-hmd-frontmatter", $child)}, 5 | #{selector.unify(".cm-math", $child)}, 6 | pre.HyperMD-codeblock #{$child} { 7 | @content; 8 | } 9 | } 10 | 11 | .cm-s-obsidian pre.HyperMD-codeblock span.cm-formatting-code-block { 12 | color: var(--text-muted); 13 | } 14 | 15 | .cm-s-obsidian pre.HyperMD-codeblock .cm-keyword { 16 | font-weight: normal; 17 | } 18 | 19 | .cm-s-obsidian { 20 | .theme-dark & { 21 | /* 22 | 23 | Name: yoncé 24 | Author: Thomas MacLean (http://github.com/thomasmaclean) 25 | 26 | Original yoncé color scheme by Mina Markham (https://github.com/minamarkham) 27 | 28 | */ 29 | .cm-hmd-frontmatter, 30 | pre.HyperMD-codeblock { 31 | color: #d4d4d4; 32 | } 33 | 34 | @include codeAndFrontmatter(".cm-keyword") { 35 | color: #00A7AA; 36 | font-weight: normal; 37 | } 38 | 39 | @include codeAndFrontmatter(".cm-atom") { 40 | color: #F39B35; 41 | } 42 | 43 | @include codeAndFrontmatter(".cm-number") { 44 | color: #A06FCA; 45 | } 46 | @include codeAndFrontmatter("span.cm-type") { 47 | color: #A06FCA; 48 | } 49 | 50 | /**/ 51 | @include codeAndFrontmatter(".cm-def") { 52 | color: #98E342; 53 | } 54 | 55 | @include codeAndFrontmatter(".cm-property") { 56 | color: #D4D4D4; 57 | } 58 | @include codeAndFrontmatter("span.cm-variable") { 59 | color: #D4D4D4; 60 | } 61 | 62 | @include codeAndFrontmatter("span.cm-variable-2") { 63 | color: #da7dae; 64 | } 65 | 66 | @include codeAndFrontmatter("span.cm-variable-3") { 67 | color: #A06FCA; 68 | } 69 | 70 | @include codeAndFrontmatter(".cm-type.cm-def") { 71 | color: #FC4384; 72 | } 73 | 74 | @include codeAndFrontmatter(".cm-property.cm-def") { 75 | color: #FC4384; 76 | } 77 | 78 | @include codeAndFrontmatter(".cm-callee") { 79 | color: #FC4384; 80 | } 81 | 82 | @include codeAndFrontmatter(".cm-operator") { 83 | color: #FC4384; 84 | } 85 | 86 | @include codeAndFrontmatter(".cm-qualifier") { 87 | color: #FC4384; 88 | } 89 | @include codeAndFrontmatter(".cm-tag") { 90 | color: #FC4384; 91 | } 92 | 93 | @include codeAndFrontmatter(".cm-tag.cm-bracket") { 94 | color: #D4D4D4; 95 | } 96 | 97 | @include codeAndFrontmatter(".cm-attribute") { 98 | color: #A06FCA; 99 | } 100 | 101 | @include codeAndFrontmatter(".cm-comment") { 102 | color: #696d70; 103 | } 104 | 105 | @include codeAndFrontmatter(".cm-comment.cm-tag") { 106 | color: #FC4384 107 | } 108 | 109 | @include codeAndFrontmatter(".cm-comment.cm-attribute") { 110 | color: #D4D4D4; 111 | } 112 | 113 | @include codeAndFrontmatter(".cm-string") { 114 | color: #E6DB74; 115 | } 116 | 117 | @include codeAndFrontmatter(".cm-string-2") { 118 | color: #F39B35; 119 | } 120 | 121 | @include codeAndFrontmatter(".cm-meta") { 122 | color: #D4D4D4; 123 | background: inherit; 124 | } 125 | 126 | @include codeAndFrontmatter(".cm-builtin") { 127 | color: #FC4384; 128 | } 129 | 130 | @include codeAndFrontmatter(".cm-header") { 131 | color: #da7dae; 132 | } 133 | 134 | @include codeAndFrontmatter(".cm-hr") { 135 | color: #98E342; 136 | } 137 | 138 | @include codeAndFrontmatter(".cm-link") { 139 | color: #696d70; 140 | } 141 | 142 | @include codeAndFrontmatter(".cm-error") { 143 | border-bottom: 1px solid #C42412; 144 | } 145 | 146 | @include codeAndFrontmatter(".CodeMirror-activeline-background") { 147 | background: #272727; 148 | } 149 | 150 | @include codeAndFrontmatter(".CodeMirror-matchingbracket") { 151 | outline: 1px solid grey; 152 | color: #D4D4D4 !important; 153 | } 154 | } 155 | } -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": ".", 4 | "inlineSourceMap": true, 5 | "inlineSources": true, 6 | "module": "ESNext", 7 | "target": "es5", 8 | "allowJs": true, 9 | "noImplicitAny": true, 10 | "moduleResolution": "node", 11 | "importHelpers": true, 12 | "lib": [ 13 | "dom", 14 | "es5", 15 | "scripthost", 16 | "es2015" 17 | ] 18 | }, 19 | "include": [ 20 | "**/*.ts" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /versions.json: -------------------------------------------------------------------------------- 1 | { 2 | "0.1.2": "0.10.0", 3 | "0.1.1": "0.9.7" 4 | } --------------------------------------------------------------------------------