components/prism-core.js


Log

Author Commit Date CI Message
Lea Verou 17d9aa8a 2014-11-14T20:30:10 insertBefore() with only two arguments appends (similar to how DOM insertBefore() behaves)
Lea Verou 436a7bd6 2014-11-14T19:43:50 Make insertBefore() update pointers to the object from other language definitions. Use case/Example: In dabblet, code-highlight.js adds some extra tokens to CSS. But CSS also extends markup to highlight CSS in style elements/attributes and that happens *before* the extra CSS tokens were added. However, because references were not updated, CSS highlighted in markup was using the original CSS definition, without the added tokens. I’m surprised we haven’t caught this earlier, I’d expect it to affect many advanced uses of Prism.
Lea Verou 4b9e11c6 2014-11-14T19:19:31 CSS highlighting in HTML style attribute
Andreas Rohner 08037e5b 2014-09-05T11:01:02 Fix for DFS bug with new pattern array feature This patch implements support for the new pattern array feature in the Prism.languages.DFS function and fixes a bug in the autolinker plugin. It adds an optional parameter to the callback of Prism.languages.DFS, which contains the type of the current object as oposed to the key in the parent. In most cases both key and type are exactly the same. Only if the parent is an array the key will contain the index number and the type will contain the attribute name of the array in the parent object. The key can be used to replace the object in the parent and the type can be used to provide the necessary context.
Andreas Rohner 3309890f 2014-08-12T13:48:47 Add option to define aliases for tokens This patch adds an option called `alias`, which allows the definition of additional CSS classes for token names. This can be useful, to combine the styling of a well known token, which is already supported by most of the themes, with a semantically correct token name. The option can be set to a string literal or an array of string literals. In the following example the token name `latex-equation` is not supported by any theme, but it will be highlighted the same as a string. 'latex-equation': { pattern: /\$(\\?.)*?\$/g, alias: 'string' }
Aleksandr Zverev ba3bcd23 2014-08-20T14:42:08 Fixed missed encode call for webworkers
Andreas Rohner 43e4e693 2014-08-10T23:26:10 Allow multiple regex per token name by using arrays In most languages there are multiple different ways of declaring the same constructs (e.g. comments, strings, ...) and sometimes it is difficult or unpractical to match all of them with one single regular expression. This patch adds the possibility to use an array of pattern objects. For example there is a minor bug in the current definition of the `clike` language, that could be solved with this patch: The character immediately in front of a single line comment is highlighted as a comment as well. something// something This is because both definitions for single and multiline comments have to be matched with a single regex and the `lookbehind` parameter can only be applied to the first captured string. With this patch one could split the two definitions up and use `lookbehind` for both, thereby eliminating the bug. 'comment': [ { pattern: /(^|[^\\])\/\*[\w\W]*?\*\//g, lookbehind: true }, { pattern: /(^|[^\\:])\/\/.*?(\r?\n|$)/g, lookbehind: true } ],
Andreas Rohner fef8cd49 2014-08-10T08:24:02 Allow multiple tokens to be mapped to the same CSS class In most languages there are different ways of declaring the same constructs, but with the current implementation of Prism it is only possible to define one pattern for a particular token type. This is not a problem, as long as it is possible to match everything with one regex. But sometimes it isn't easily possible to do that, especially if things like `lookbehind` or `inside` are needed for one part but not for the other. This patch splits the token type into two parts, whereby the second part is optional: {token type}#{description} For example there is a minor bug in the current definition of the `clike` language, that could be solved with this patch: The character immediately in front of a single line comment is highlighted as a comment as well. something// something This is because both definitions for single and multiline comments have to be matched with a single regex and the `lookbehind` parameter can only be applied to the first captured string. With this patch one could split the two definitions up and use `lookbehind` for both, thereby eliminating the bug. 'comment': { pattern: /(^|[^\\])\/\*[\w\W]*?\*\//g, lookbehind: true }, 'comment#single-line': { pattern: /(^|[^\\:])\/\/.*?(\r?\n|$)/g, lookbehind: true },
Jannik Zschiesche 502ed6c1 2014-07-23T10:49:30 Don't set the `self` variable with `var` Firefox directly shadows the global variable `self` if it is present (= in a worker). So we need to set `self` without `var self` but directly.
Jannik Zschiesche eb1cd1c9 2014-07-23T09:49:34 Fix workers The issue is that in workers `window` is undefined. Therefore, in the first line, `self` will be set to `{}`. This will destroy the check for workers later on: ```js if (!self.document) { if (!self.addEventListener) { // in Node.js return self.Prism; } // In worker // ... } ``` because `self.addEventListener` will then be undefined (due to `self = {}`). The fix is to make the check for the environment more clever: 1. check for the browser: `(typeof window !== 'undefined')` 2. check for a worker: `(typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope)` (from http://stackoverflow.com/questions/7931182/reliably-detect-if-the-script-is-executing-in-a-web-worker) 3. assume we are in node
Thomas Ingram cddff711 2014-05-24T15:59:23 Simplify encoding logic
Thomas Ingram 8557daa9 2014-05-24T14:23:52 Remove leftover `console.log`
Thomas Ingram c0a0353d 2014-05-23T13:40:52 Stop prematurely escaping code block Refactor Prism.highlight to HTML encode tokens before calling Token.stringify. This is a breaking change for nearly all grammars! Previously Prism was encoding HTML entities *before* passing the code block to the parser. Now it encodes HTML entities *after* the tokens have been parsed (before rendering to HTML).
Thomas Ingram 9f6cff9b 2014-05-23T13:01:26 Whitespace cleanup
Lea Verou 62561684 2014-05-22T17:36:51 Reversed change in Core
Lea Verou 0bf2a8e5 2014-05-22T17:28:57 Updated minified files
Geraint Luff 8a7157be 2013-11-12T22:33:44 Add Node.js support
George Kats 2c1d8363 2013-06-24T23:58:39 Fix highlight plugin for worker.
Lea Verou 1d899d7d 2013-06-14T11:46:34 Fixed parsing for entities and <> chars
Rob Brackett 2b204348 2013-06-01T22:01:58 Merge branch 'gh-pages' into bug-109-zero-length-lookbehind. Manually adjusted whitespace collision in prism.js. Conflicts: prism.js
Rob Brackett 8f746360 2013-05-23T11:53:04 Use separate vars to track whether lookbehind is being used and the length of the lookbehind. Fixes #109.
Siavash Askari Nasr 29b28801 2013-05-21T16:01:30 Added 'before-insert' hook. After when code is highlighted and before being inserted to document.
Miles Johnson e962299c 2013-05-18T17:29:21 Updated PHP patterns Fixed PHP + Markup
Lea Verou 801aab58 2013-05-11T04:37:44 Added parent access to wrap hook
Lea Verou c3a69913 2013-05-09T21:01:17 Added language id to wrap hook
Lea Verou 358fbbd6 2013-01-27T03:50:38 Replaced iteration with Array#map
Lea Verou 1b40db97 2012-11-10T00:23:33 Made Java & JavaScript inherit from a generic C-style language definition; Added methods for language definition inheritance; Added simple dependency management in downloader
Lea Verou 54fdc1f4 2012-09-13T20:06:11 Removed pointless trim()
Lea Verou ddd1eb89 2012-08-01T12:02:46 Applied #15 to prism-core.js
Lea Verou e1cd33df 2012-08-01T02:47:23 Made the page a bit more IE friendly, added a first version of the IE8 plugin (WIP)
Lea Verou c75bbc24 2012-07-31T19:08:31 Fixed bug with classnames
Lea Verou ec8fb796 2012-07-31T17:47:56 Added helper method Prism.languages.DFS
Lea Verou 54e2eeab 2012-07-29T00:26:50 Added (and documented) Prism.languages.insertBefore
Lea Verou 4da6cfcd 2012-07-27T00:08:10 Removed useless code
Lea Verou 6763cd53 2012-07-26T18:48:34 Fixed bug where block code wasn’t styled properly
Lea Verou 9ea52e2a 2012-07-26T18:41:49 Removed IE8 support
Lea Verou cfaf681d 2012-07-26T18:17:55 Removed the need for .prism
Lea Verou 1b5ab23a 2012-07-23T19:32:27 Added setting to turn automatic highlighting off and to set a default language
Lea Verou bd4e8d15 2012-07-23T18:54:30 ALL THE THINGS! Most notably: Simple templating, API changes, show invisibles plugin, download (build) page
Lea Verou de85c1ae 2012-07-16T14:49:10 Made the language matching a bit more lax. Now it can be on the <pre> element even when it has <code> children. Also, it can be lang-xxxx instead of language-xxxx.
Lea Verou f2339ea1 2012-07-15T22:36:05 Added line highlight plugin
Lea Verou 2c473547 2012-07-15T16:35:06 Fixed regexes further, documented lookbehind feature
Lea Verou 6f1dc184 2012-07-15T14:04:25 Fixed regex & single line comment conflicts
Lea Verou bdb8fae8 2012-07-13T15:11:03 Added hooks system, moved entity tooltips to the Markup language, as a plugin
Lea Verou 764fe408 2012-07-13T02:42:17 Made Prism.wrap() more extensible (See #8)
Lea Verou 6e9c4e1b 2012-07-12T17:12:58 Fixed horrible bug, added highlighting for XML namespaces
Lea Verou cdee2b54 2012-07-11T22:01:44 IE8 support
Lea Verou 8ecdd7c4 2012-07-11T14:22:23 Removed switch for automatic highlighting
Lea Verou 27e5464c 2012-07-11T03:14:55 Safeguarded against Object.prototype additions
Lea Verou 4552f5c7 2012-07-10T22:48:14 First commit