league/commonmark to parse and render Markdown in your PHP project, you can easily integrate Phiki using our custom extension.
Usage
Enabling the gutter
You can enable the gutter by specifying thewithGutter argument in the PhikiExtension constructor.
Using multiple themes
You can also pass in an array of themes to thePhikiExtension constructor.
Meta information
You can add additional meta information to your Markdown code blocks to highlight and focus a specified set of lines.Highlighting lines
You can highlight lines in your code blocks using special annotations in the code block’s info string.Focusing lines
You can focus lines in your code blocks using special annotations in the code block’s info string.Sample CSS
Phiki does not style the highlighted or focused lines by default, so you will need to add your own CSS. You can use the following sample CSS to get started:Inline annotations
The meta information for highlighting and focusing lines can be difficult to use when you have a large code block or if you change the code frequently since it uses line numbers. That’s why Phiki also supports inline annotations using special comments in your code.Ranges
Inline annotations accept an optional range parameter to specify which lines should be highlighted or focused.start and end to mark the beginning and end of a range.
Highlighting lines
To highlight a line, you can add a trailing comment to the line you want to highlight.highlight class to the corresponding line element.
If you don’t want to write out highlight every time, you can use the hl or ~~ shorthands instead.
Focusing lines
To focus a line, you can add a trailing comment to the line you want to focus.focus class to the corresponding line element.
If you don’t want to write out focus every time, you can use the f or ** shorthands instead.
Diff annotations
Diff annotations are useful for displaying changes in a piece of code, e.g. inserting a line or removing a line.insert and remove classes to the corresponding line elements.
If you don’t want to write out the full keywords, you can use these shorthands:
add, del, or delete as alternative keywords for insert and remove respectively.
Gutter diff symbols
When the gutter is enabled, line numbers will be replaced with the following symbols based on which type of diff annotation is used:- Inserted lines show
+instead of the line number. - Removed lines show
-instead of the line number
Sample CSS
Highlighted lines
When you use an inline highlight annotation, Phiki will automatically try to find aneditor.lineHighlightBackground or editor.selectionHighlightBackground color inside of your chosen theme(s) and add a CSS variable to the <pre> element.
If it can’t find one, it will fallback to the default background color of the theme.
Phiki automatically adds the following CSS variables:
--phiki-line-highlight- Background color for highlighted lines
If you’re using multiple themes, Phiki will also add CSS variables for each theme so you can style them differently in dark mode, for example.
Focused lines
Phiki does not apply any styles to focused lines by default, so you will need to add your own CSS.Diff annotations
When you use diff annotations, Phiki will automatically try to findmarkup.inserted and markup.deleted colors inside of your chosen theme(s) and add CSS variables to the <pre> element.
Phiki automatically adds the following CSS variables to the <pre> element:
--phiki-diff-insert-bg- Background color for inserted lines--phiki-diff-insert-fg- Text color for inserted lines--phiki-diff-remove-bg- Background color for removed lines--phiki-diff-remove-fg- Text color for removed lines
If you’re using multiple themes, Phiki will also add CSS variables for each theme so you can style them differently in dark mode, for example.