For information about new features and improvements in Phiki 2.0, please refer to the rest of the documentation.
High impact changes
Phiki::codeToHtml() signature changed
This method now returns an instance of Phiki\Output\Html\PendingHtmlOutput instead of a raw string. This new object allows for more flexibility and lazy rendering of the final HTML output.
If you need to get the HTML string immediately, you can call the toString() and __toString() methods or cast it to a (string).
To improve the usability of this method, the following parameters have been removed:
withGutter– replaced with awithGutter()method on the returned object.withWrapper– if you were using this, see the “Medium impact changes” section below for more information.
Terminal support removed
The terminal output feature has been removed due to low usage and maintenance overhead. There is currently no alternative for this feature, but it may be reintroduced in a future separate package.Namespace changes
- The
Phiki\Environment\Environmentclass is nowPhiki\Environment. - The
Phiki\CommonMark\PhikiExtensionclass is nowPhiki\Adapters\CommonMark\PhikiExtension.
Custom environment support removed
The ability to pass a customPhiki\Environment instance to the Phiki constructor has been removed.
This was a rarely used feature that added unnecessary complexity to the codebase.
Changes to extension registration
Since the custom environment support has been removed, the method to register extensions has been moved to thePhiki class.
If you need to register an extension, you can use the Phiki::extend() method:
Changes to custom grammar and theme registration
Since the custom environment support has been removed, the methods to register custom grammars and themes have been moved to thePhiki class.
If you need to register a custom grammar, you can use the Phiki::grammar() method:
Phiki::theme() method:
Medium impact changes
API for accessing repositories changed
If you were previously using thegetGrammarRepository() or getThemeRepository() methods on the Phiki\Environment\Environment class, you can now access these repositories directly from the Phiki::$environment property.
readonly, so you cannot replace them, but you can still interact with them as you did before.
HtmlGenerator class removed
The Phiki\Generators\HtmlGenerator class has been removed. Its functionality has been integrated into the Phiki\Output\Html\PendingHtmlOutput class returned by Phiki::codeToHtml().
Automatic language detection removed
This feature has been removed due to its unreliability and the complexity it adds to the codebase. Phiki only supported two languages (php and js) for automatic detection which was not enough to be useful.
It’s now recommended that you always specify the language when using Phiki::codeToHtml() or the Phiki CommonMark extension.
withWrapper option removed
If you are passing withWrapper: true to Phiki::codeToHtml() or the Phiki CommonMark extension, this feature has now been removed.
It was originally added to support a feature on my personal site but was never officially documented. Since there are alternative methods to achieve the same result, it has been removed to simplify the codebase.
Low impact changes
Tokenizer rewrite
TheTokenizer class has been completely rewritten to improve performance and accuracy.
It now uses PHP’s mbstring extension since that uses Oniguruma under the hood, which is the same RegEx engine behind Shiki and vscode-textmate.
This will only affect you if you were extending the Tokenizer class since the underlying methods and properties have changed to accommodate the new implementation.
Highlighter rewrite
TheHighlighter class has also been rewritten to improve accuracy.
The previous implementation uses a very naive approach to applying styles to scoped tokens which resulted in “scope selectors” not being applied correctly.
This has now been resolved in the new implementation at the cost of some performance.
Namespace changes
Phiki\Tokenizeris nowPhiki\TextMate\TokenizerPhiki\Highlighteris nowPhiki\Highlighting\Highlighter