Scipress has first-class support for embedding code in posts, in Markdown. Code snippets come in two flavors - inline code and fenced code blocks.
Code in Scipress is powered by
- shiki - syntax highlighting
- rehype-pretty-code - titles, captions, highlights, etc.
- CodePen - runnable code blocks
Inline code¶
You can create inline code by wrapping a code snippet within backticks.
Use pip install <package name>
to install a Python package.
Syntax highlighting¶
Append {:lang}
to the end of inline code to highlight language-specific syntax.
Use str.replace(' ', '-')
to replace spaces with dashes.
Fenced code blocks¶
You can create a fenced code block by wrapping one or more lines of code within three backticks above and below.
Syntax highlighting¶
Enable language-specific syntax highlighting by appending one of the supported language codes to the opening backticks.
Line highlighting¶
You can highlight
- a range of lines using
{j-k}
or - a specifc line using
{m}
or - a combination using
{a-b, c-d, ... m, j, k, ...}
Word highlighting¶
You can highlight
- a specific word in a code block using
/word/
or"word"
- the ith instance of a word in a code block using
/word/i
- the i-jth instances of a word in a code block using
/word/i-j
Runnable code¶
You can make runnable code snippets with codepen.io. After creating a new code pen, use the ::codepen
leaf directive, passing in the src
attribute to embed it in your post.
Example¶
Additional parameters¶
CodePen's source URL supports various query parameters that allow you to customize the settings of your embedded codepen. These include
-
default-tab
Which tab to show by default?Example: src="https://codepen.io/XYZ/embed/xxId?default-tab=css
-
theme-id
Which theme to show? Can belight
ordark
. Omit this parameter to use the codepen's default.Example: src="https://codepen.io/XYZ/embed/xxId?theme-id=light
-
editable
Should this codepen be editable by readers? (Readers will not be able to modify the original codepen). Can betrue
orfalse
.Example: src="https://codepen.io/XYZ/embed/xxId?editable=true