Releases: FIameCaster/prism-code-editor
Release 3.1.0
New features
History extension
Previously, the browser's native undo/redo was used. While this often worked well enough, it has its limitations. In Chrome and Safari, all form elements share the same undo stack, and in Firefox, hiding an element with display: none
would clear its undo history. The new history extension has none of these issues. You can even transfer the history from an editor to another, but not without breaking the old editor.
The extension is tiny. Adding it to the demo website, only increases its JS bundle by 0.35kB gzipped.
The history extension has been added to the basic setup and the full setup. The extension can be accessed from PrismEditor.extensions
.
// Here's how to import the extension
import { editHistory } from "prism-code-editor/commands"
New theme
Prism's Tomorrow Night theme has been implemented. It's on the demo website if you want to try it.
Note: I forgot to add this file to the package. This was fixed in 3.1.2
import "prism-code-editor/themes/prism-tomorrow.css"
Improvements
- Significantly increased performance of the
getClosestToken()
utility, especially for long lines. This was achieved by using aTreeWalker
for the searching instead of usingquerySelector()
coupled withRange.toString()
to find the position of the tokens. The performance increase can be anywhere from a few times faster for short lines to a greater than 100x improvement for lines 1000s of characters long. Not sure why you'd view minified code in an editor, but that will perform much better now (9f8ebe6) - Decreased gzipped size of all Prism languages by more than 10kB (5%) through refactoring and optimization.
- An
input
event on the textarea now always updates the editor even if its value didn't change (7a3ddef)
Fixes
- Added
.js
extensions to most imports. The type declarations now work properly with amoduleResolution
ofNodeNext
orNode16
(b94978b) - Added
type="button"
to the copy button and all buttons in the search widget. If you had an editor inside a form, these buttons would previously submit the form when clicked. This is no longer the case (8ea416b) - Fixed potential empty matches that could lead to buggy highlighting in multiple languages (b28da8d)
- The
getLanguage()
utility now supports languages with hyphens in their name (d214971) - Changed the default tab size of the web components from 0 to 2 spaces. This wasn't a big issue since 0 would internally be replaced with 2 (e2ad6e5)
- Fixed alignment issue with the
highlightSelectionMatches()
extension in RTL mode (741bc85) - Fixed incorrect highlighting of capitalized generic functions in the TSX language (bf85599)
- Added a
language-jsx
alias to spread tokens inside JSX tags (bf85599)
Search widget improvments
- Selection change handlers no longer run with the incorrect selection after calling the
insertText()
utility if the search widget is open (7a3ddef) - Selection matches are no longer highlighted after replacing a match with the search widget (7a3ddef)
- The keyboard shortcuts for the 4 toggle buttons now uses
keyCode
instead ofcode
on Mac. This will work better with non-QWERTY keyboards on Mac (7a3ddef)
Release 3.0.1
- Fenced code blocks with more than three backticks are now supported in markdown (e40eaa7)
- Fixed empty script/style tags potentially breaking the highlighting of css/js inside later script/style tags (b84f011)
- The bracket level no longer gets reset back to zero when entering a nested token, so the rainbow brackets now work as expected again (0f304a2)
- The search match selected while typing in the search widget is now the match closest to where the cursor was last time the editor was focused. This means the editor's cursor will jump less around while searching (eb00bbc)
Release 3.0.0
Breaking changes
The modified Prism instance has been significantly changed and more of Prism v2's features have been added, most notably custom tokenizers. Below is a list of most changes:
- Everything Prism related is now exported from its own entry point
prism-code-editor/prism
- Prism grammars have been moved from
prism-code-editor/grammars/*
toprism-code-editor/prism/languages/*
- The
rest
property of grammars is now a rest symbol - Added custom tokenizers to grammars through a tokenize symbol
- Grammar related utilities like
clone
,extend
andinsertBefore
are now found underprism-code-editor/prism/utils
- Changed the signature of the
insertBefore
utility - Prism hooks have been removed since they were unused by all languages
- Dropped the
@types/prismjs
dependency since it's incompatible - Moved the
attr-equals
token out ofattr-value
in the markup/xml grammar. This can change some themes - Dropped support for CRLF and CR line breaks in all grammars
- Dropped the
clike
dependency from the following languages:c
,dart
,fsharp
,go
,groovy
,haxe
,java
,jolie
,kotlin
,latte
,purebasic
,qsharp
,qore
,ruby
,sqf
,squirrel
, andvala
xml
is now its own seperate language component thatmarkup
extends- Dropped the
markup
dependency fromjsx
- Removed the
t4-templating
language js-extras
has been removed and some of its features have been moved to thejavascript
grammar instead- The
markup-templating
language has been replaced by theembeddedIn
utility - Empty tokens can no longer be created by the tokenizer because empty matches are skipped
- The global regex flag on the pattern is now required for greedy tokens
Other breaking changes
There are also breaking changes unrelated to Prism:
- Removed the
TokenizeEnv
type - Changed the arguments for
tokenize
listeners. Instead of a singleTokenizeEnv
argument, the tokens, language, and value are passed as individual arguments in the aforementioned order (25cd60f) - Moved
ignoreTab
andsetIgnoreTab
toprism-code-editor/commands
(84b2515) - Removed support for a number as a search filter (ebc89fa)
- Changed the order of properties in the
Tag
tuples created by the tag matcher to be more sensible - Moved the
pce-readonly
andpce-no-selection
classes from the overlays to the scroll container. You might need to change some CSS selectors - The editor used is now passed as an third argument to the
autoIndent
andautoCloseTags
methods instead of being passed throughthis
(73e082e) - The
InputSelection
type has been made mutable (c48443e) createTagMatcher
no longer writes toeditor.extensions.matchTags
- Changed the classname of the tooltip container from
tooltip-wrapper
topce-tooltip
to avoid potential style collisions with external style sheets - Added
overflow-x: clip
to the tooltip container by default to prevent overflow in modern browsers
New features
- New public
highlightText
andhighlightTokens
functions allow you to easily do syntax highlighting outside of an editor - You can now use this library's Prism instance to do syntax highlighting in Node.js
- Tags aren't automatically closed while typing if there exists an unmatched closing tag with the same name. This is only the case with the tag matching extension added
- Added the class
pce-focus
to the editor when it's focused - Plain functions can now be used as editor extensions. These functions take the same arguments as the update method on the existing extensions, but won't be called again when the editor's options change
Fixes and improvements
- The tag- and bracket matching can no longer match together tags/brackets with different parent tokens
- The
jsdoc
language now works withjsx
andtsx
- Bracket matching has been enabled inside regex tokens
- Improved highlighting of regex tokens in all themes
- Added the missing property
rtl
to thePrismEditorElement
type (34ed0ff) - Fixed alignment issue with the
highlightCurrentWord
extension in RTL mode (1f7611d) - Almost any operator or punctuation is now allowed after javascript regex tokens (d88a25a)
- Fixed a very rare edge case where new highlighted lines would be inserted in the wrong position (326e6fc)
- Fixed issue with the markdown code block punctuation pattern (c7b9f7c)
- The Prism core is now almost 20% smaller and slightly faster than before (d142f64)
Website
- Added the
jsdoc
,js-templates
, andregex
languages - Added a tooltip to the bottom read-only editor to tell users it can't be edited
Release 2.4.1
Release 2.4.0
New features
Better comment toggling for JSX
When inside a JSX context, normal JavaScript comments can't be used. Therefore {/* */}
comments will now be used in JSX contexts.(2e38fd2)
A new property on languages getComments
was used to make this possible. You can read about it in the API docs.
New commands
- Shift+Ctrl+K (Shift+Cmd+K on MacOS): Delete line (617da31)
- Ctrl+Enter (Cmd+Enter on MacOS) Insert blank line (7ee34a4)
Fixes
- Tag matching and block comment folding now works properly in nested languages (9bab6a3)
- The JS templates and markup templating Prism languages can no longer break tag matching, bracket matching and code folding
Release 2.3.2
Fixed highlighting when there are tags inside object spread in JSX tags (9ec5299)
Fixed backtracking issues with the new tag patterns for JSX and markup
Improved an edge case when toggling comments in languages without line comments such as CSS or markup (edcc167)
Fixed a bug in the Prism core where the rest
property of grammars wasn't ignored by the matchGrammar
function
Release 2.3.1
Release 2.3.0
New features
- Added a parameter to
SearchAPI.search
which allows you to change the behavior of whole word search (a585839) - The
highlightSelectionMatches
andhighlightCurrentWord
extensions now expose their search API which can be used to e.g. get the positions of the current matches (38e9f0b) - Added source maps to the package for easier debugging (35c96d3)
Improvements and fixes
- The
matchTags
extension now correctly handles name spaced tags and matches tags inside attribute values (3e55338) - Improved the tag pattern i both JSX and markup. The attribute value has been made optional, and whitespace is now allowed around =, so
<div id=>
and<div id = "a">
are now highlighted as tags which improves typing experience. Lastly, JSX tag names and attribute names now allow non-ASCII characters (5553f09) - Small improvements to the JavaScript grammar (5553f09)
- Improved word boundries for searching in the
highlightCurrentWord
extension (ea955f7) - Fixed a couple bugs in the
highlightTagPunctuation
extension (6dbdb27) - Creating an editor or calling
setOptions
with thevalue
option explicitly set toundefined
no longer throws an error (5faa832) - Constants are now colored differently in the VS Code Light/Dark themes (2f4f534)
Release 2.2.4
- Improved whole word search behavior
- A Chrome bug patch for the search widget didn't always work. It now does
Release 2.2.3
- Fixed PrismJS/prism#3722 for the Kotlin grammar
- Improved whole word search
- Opening the search widget programmatically now starts a search with the find input's contents.
- Fixed opening punctuation of JSX fragments being highlighted by the
matchTags
extension