components/prism-core.js


Log

Author Commit Date CI Message
Golmote e0cd47f8 2018-03-03T20:13:59 Core: Don't thow an error if lookbehing is used without anything matching.
Hisateru Tanaka 69f2e2cb 2017-12-06T04:10:50 Allow any element being root instead of document. (#1230) (better compatibility than #397)
Golmote d09982d8 2017-11-05T14:24:19 Core: Provide a way to load Prism from inside a Worker without listening to messages. (#1188) Using disableWorkerMessageHandler config.
Golmote c33be19a 2017-11-05T13:32:00 Core: Prevent error from throwing when element does not have a parentNode in highlightElement. Fix #1203
Golmote de996d7d 2017-10-21T10:17:56 Merge branch 'remove_spellcheck_attribute' of https://github.com/emmanuelgautier/prism into emmanuelgautier-remove_spellcheck_attribute # Conflicts: # components/prism-core.min.js
Golmote 25788eb5 2017-09-09T12:05:55 Merge branch 'RemoveIE8' of https://github.com/zeitgeist87/prism into zeitgeist87-RemoveIE8 # Conflicts: # components/prism-core.js # components/prism-core.min.js # plugins/line-highlight/prism-line-highlight.js # plugins/line-highlight/prism-line-highlight.min.js # prism.js
Andreas Rohner e13fdfa4 2017-02-08T17:19:22 Add minor optimizations for the greedy flag
Andreas Rohner 1736f4aa 2017-02-08T01:36:27 Fix corner cases for the greedy flag By refactoring the tokenize() method into two separate methods, it is possible to recursively clean up any broken tokens left by the greedy feature. This should fix the issue 1075.
Golmote 70cb4729 2017-05-08T11:44:21 Run before-highlight and after-highlight hooks even when no grammar is found. Fix #1134
Emmanuel Gautier 01e74afa 2017-02-28T12:42:27 remove comments spellcheck for amp validation
James DiGioia bafc4cb6 2017-01-24T16:31:10 Initial implementation of manual highlighting (#1087) * Initial implementation of manual highlighting Borrow the `manual` property of whatever already existing Prism instance there is. * Simplify setting of `Prism.manual` Cleans up the implementation w/ less code.
Golmote b8ce1e7c 2016-12-03T11:52:48 Merge branch 'gh-pages' of https://github.com/PrismJS/prism into gh-pages # Conflicts: # components/prism-core.min.js
Golmote 83bafbd4 2016-12-03T11:46:26 env.code can be modified by before-sanity-check hook even when using language-none. Fix #1066
Rob Wu 17e33bc0 2016-11-20T12:52:54 Reduce risk of XSS (#1051) * Skip non-own properties of env.attributes Use `Object.keys` instead of a for-in loop to find optional attributes. The former only grabs keys that are own properties, the latter also includes inherit properties from `Object.prototype`. This reduces the risk of XSS if an attacker somehow manages to manipulate the prototype chain of the Object prototype. * Fix root cause of XSS in autolinker plugin #1054 * command-line plugin: Safely encode attributes If an attacker has control over the values of the attributes "data-prompt", "data-user", or "data-host", then XSS was possible. This fixes the issue, by encoding quotes as the `"` entity. * show-language plugin: innerHTML -> textContent There is no need for `innerHTML` here. At best nothing happens, at worst XSS is possible (though the odds are negligible since the attacker would have to control the detected language). * toolbar plugin: innerHTML -> textContent
Andreas Rohner 32cd99ff 2016-10-24T21:21:37 Fix greedy-flag bug This bug occurs in the relatively rare case of a pattern matching the empty string. It was reported in issue #1039. If for example a HTML page contains an empty script tag `<script></script>` then the script pattern will match anything inside, which is the empty string. This empty string is then passed to the constructor of the Token class. Since `""` is falsy in Javascript the property `matchedStr` is set to `null`. But the property `matchedStr` is needed to calculate the current position for the greedy feature. A `null` value in `matchedStr` results in a `pos` that is `NaN`. This causes the bug described in issue #1039. Since the property `matchedStr` is only ever needed to calculate the length of the Token, it is more efficient to store the length directly instead of the string. As a side effect this also fixes issue #1039.
Golmote 3dc8c9e1 2016-07-11T20:36:16 Don't insert space before ">" when there is no attributes
Andreas Rohner 3780571b 2016-07-03T11:59:59 Remove IE8 plugin
Golmote c9bdcd35 2016-07-03T02:37:29 Manual merge of #988. Closes #988, fixes #987.
Golmote 9893489c 2016-06-18T14:18:27 Replace flags property of RegExp with a more compatible alternative
Andreas Rohner d80900cc 2016-06-04T19:52:38 Improvement to greedy-flag This patch expands the idea of the greedy flag and significantly improves it, by matching against the whole text instead of just the next couple of tokens. This does not only improve the results, but it should also slightly improve performance.
Chris Ruppel f130680c 2016-05-29T11:15:59 Use requestAnimationFrame instead of setTimeout
Chris Ruppel 4eb7ee45 2016-05-26T11:27:03 Allow for asynchronous loading of prism.js
Anders Grendstadbakk acd9508f 2016-05-17T14:23:02 Use toLowerCase on language names
Andreas Rohner 21dd0d14 2016-02-15T23:08:24 Use a HTML-comment to escape code
Andreas Rohner 49cf8991 2016-03-08T15:03:59 Fix minor bug with new greedy-feature This fixes a minor bug that causes invalid highlighting in some edge cases, where two greedy patterns overlap each other.
Andreas Rohner c88036ca 2016-02-19T22:27:22 Add tests for new greedy-pattern feature and fix bug in Kotlin This patch adds tests for the new greedy-pattern feature and fixes a small bug in the Kotlin language, that resulted from that. It also cleans up some of the comments and refactors a few lines in the tokenloop.
Andreas Rohner 90432f96 2016-02-18T01:22:40 Add comments to better document the greedy-pattern feature
Andreas Rohner 2705c509 2015-09-24T19:36:10 Partial solution for the "Comment-like substrings"-problem This patch introduces a new attribute called `greedy`. The attribute is a simple boolean flag. If there is no match for a greedy pattern it can concatenate the next two tokens into a single string and try to match on this string again. If a match is found on the second attempt, then the old tokens are deleted and replaced by the new match. This solves the "Comment-like substrings"-problem for exactly one comment at very little cost. With this patch the following code is highlighted correctly: "foo /* bar */ baz"; "foo // bar"; /lala"test"sdf/; This approach fails if there are more than one comments inside the string: "foo /* bar */ baz /* bar */ baz"; Signed-off-by: Andreas Rohner <andreas.rohner@gmx.net>
Lea Verou af8da8ec 2016-02-14T21:08:14 Implemented @zeitgeist87’s suggestion in #890 re: env.elements
Lea Verou 70a8602f 2016-02-13T15:21:28 Add before-highlightall hook Needed for unescaped markup plugin, as discussed in #887. Alternatively, we could reinstate @zeitgeist87’s PR about making the selector a config option. Thoughts?
Andreas Rohner b86c727a 2016-02-03T15:25:26 Fix DFS bug The DFS function uses an object as a key into another object. This doesn't work, because the key gets stringified to "[object Object]" and is therefore useless.
Andreas Rohner 7fab7a2d 2016-01-26T23:16:06 Reverse merge of last PR and remove the 'data-selector' attribute.
Andreas Rohner fa987435 2016-01-26T23:10:45 Use document.currentScript instead of document.getElementsByTagName()
Andreas Rohner 77c6ea17 2016-01-26T02:33:20 Allow users to use their own element selector Add the parameter 'data-selector' to the script tag, to allow users to set the selector used to query for code elements.
Valtteri Laitinen 417f54a1 2016-01-16T03:12:00 Simplify the “lang” regex Remove an useless (?!\*) part from the lang regex.
Andreas Rohner 02894e1e 2015-12-21T19:00:26 Prevent infinite recursion in DFS
Golmote 0e93b417 2015-09-24T09:16:57 Fix code indentation style
Andreas Rohner 09be99e7 2015-09-23T20:34:29 Improve performance by doing more work in the worker Currently the worker tokenizes the code and then turns it into a JSON string. This JSON string is sent back to the main thread as a message and parsed. Then it is turned into a HTML string and stored in the attribute env.highlightedCode. These conversions into JSON are unnecessary, because we can create the HTML string directly in the worker and send it as a message to the main thread. Signed-off-by: Andreas Rohner <andreas.rohner@gmx.net>
Golmote b2f14d96 2015-09-04T08:19:21 Merge branch 'plugin-jsonp' of https://github.com/nauzilus/prism into gh-pages Conflicts: components/prism-core.min.js
Golmote e42a2289 2015-09-03T22:47:50 Explicitly make the Worker close itself after highlighting, so that users have control on this behaviour when directly using Prism inside a Worker. Fix #492
Golmote 0356c58c 2015-09-03T19:09:48 Apply changes from #754 to all plugins so that none of them throw errors in node. Autolinker, Show invisibles and WPD can now be used with node. Removed unused minified CSS file. Also added missing space between attributes during wrapping.
Golmote de7a5cab 2015-09-03T18:42:16 Merge pull request #754 from valorkin/fix-correct-behaviour-in-nodejs Fix: node.js hacks for components and prism.js
Dmitriy Shekhovtsov 9f5c93c6 2015-09-03T13:45:26 Fix: node.js hacks for components and prism.js
Golmote ed9f2b21 2015-08-17T08:47:32 Move removal of initial line feed to a plugin
Golmote fd549959 2015-08-13T08:33:48 Fix complete hook behaviour + run gulp task
Golmote 5f133c80 2015-07-16T21:09:40 Fixed prism-core and prism-file-highlight to prevent errors in IE8. Used local variable _self instead of overwriting self. Closes #468.
Golmote 8030db91 2015-06-25T08:00:14 File Highlight: allow to specify the language (takes precedence over extension guess) + Set language on parent even if unknown. Fix #607
Ewald Grusk 1eb49594 2015-02-18T21:52:53 Make use of method `_.util.type`.
Daniel Flint c711660a 2015-01-15T09:00:47 Deep clone arrays
Golmote 703d47e6 2015-01-11T23:18:41 Simplified regexp for trailing line feeds
Golmote 9487b5be 2015-01-09T08:11:21 Removed unneeded escapes in RegExps, added some semicolons
Golmote 36999ddf 2015-01-08T19:51:55 Handle trailing \r\n and \r
Golmote 2d5089ed 2015-01-08T08:55:24 Remove leading line break Fixes #455
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