heekangpark9k downloadsImprove the display of code blocks in reading view with titles, line numbers, line highlights, and more.
Obsidian plugin developed by Heekang Park
[ English | 한국어 ]
With HK CodeBlock, you can add various features to code blocks.
Inspired from Prism.js's plugin, Better Code Block, Code Block Enhancer.
You can add title to the code block like this.
```python title:"Title of the code block"
print("Hello world")
```

You must put the title in quotes. You can use both single and double quotes.
You must use the title feature to use the collapse feature. You can collapse the code block like this.
```python title:"Title of the code block" collapse
print("Hello world")
```
Or like this.
```python title:"Title of the code block" collapse:true
print("Hello world")
```


If you want to explicitly expand the code block, you can do it like this.
```python title:"Title of the code block" collapse:false
print("Hello world")
```
You can add line numbers to the code block like this.
```python linenos
print("Hello world")
```
Or like this.
```python linenos:true
print("Hello world")
```

If you don't specify any options, the line numbers will start from the value set in the settings (default: 1). If you want the line numbers to start from a specific value, you can do it like this.
```python linenos:10
print("Hello world")
```

You can also use negative values.
```python linenos:-10
print("Hello world")
```

If you want to explicitly hide the line numbers, you can do it like this.
```python linenos:false
print("Hello world")
```
You can highlight specific lines in the code block with commas like this.
```python highlight:"2-4,8,10"
print("line 1")
print("line 2")
print("line 3")
print("line 4")
print("line 5")
print("line 6")
print("line 7")
print("line 8")
print("line 9")
print("line 10")
print("line 11")
```

You must put the line numbers in quotes. You can use both single and double quotes. You can also use a dash to specify a range of line numbers.
If you use the line numbers feature and set the line numbers don't start from 1, you must enter the line numbers to be highlighted according to that.
```python linenos:10 highlight:"10,11"
print("Hello world")
print("I love you")
print("Wow")
```

You can add the language indicator to the code block like this.
```python language
print("Hello world")
```
Or like this.
```python language:true
print("Hello world")
```

The displayed language is following the language of the code block by default, but if you want, you can specify it explicitly. In this case, you can change the language displayed while keeping the syntax highlighting done by the language of the code block.
```python language:"javascript"
print("Hello world")
```

You must put the language in quotes. You can use both single and double quotes.
If neither the language of the code block nor the language specified by the language option is specified, the language displayed is the value set in the settings (default: "plain text").
If you want to explicitly hide the language indicator, you can do it like this.
```python language:false
print("Hello world")
```
You can add a copy button to the code block like this.
```python copybtn
print("Hello world")
```
Or like this.
```python copybtn:true
print("Hello world")
```

If you want to explicitly hide the copy button, you can do it like this.
```python copybtn:false
print("Hello world")
```
You can add a prompt to the code block like this.
```bash prompt
mkdir test
```
Or like this.
```bash prompt:true
mkdir test
```

If you don't specify any options, the prompt will be the value set in the settings (default: "$"). If you want to use another prompt, you can do it like this.
```bash prompt:"#"
mkdir test
```

You must put the prompt in quotes. You can use both single and double quotes.
If there is a "" character at the end of the line, the prompt will not be displayed on the next line.
```bash prompt
docker run -it \
ubuntu:latest
```

If you want to explicitly hide the prompt, you can do it like this.
```bash prompt:false
mkdir test
```
You can add a result to the code block like this.
```python
print("Hello world!")
```
```result
Hello world!
```

Note that the Result Code Block must be placed immediately after the Code Block to which the result belongs. You must not put any other components between them.
Also note that the result code block is not dynamically generated. Result code blocks are just simple plain-text code blocks. You must enter the result manually.
You can use line numbers, line highlight features only in the result code block. Other features will be ignored even if you specify them.
```python
print("Hello world!")
```
```result linenos
Hello world!
```
```result highlight:"1"
Hello world!
```

The prompt of the result code block is the value set in the settings by default (default: "Result"). If you want to use another prompt, you can do it like this.
```python
import random
print(random.randint(1, 100))
```
```result prompt:"Result (may be different depending on your environment)"
42
```

You can change the default settings of each feature of HK Code Block in the settings.
MIT License
!important keywords in the theme CSS. HK Code Block does not use !important keywords at all in order to avoid conflicts with other themes or plugins. If you want to use HK Code Block plugin with those themes, you should modify the theme CSS files, or by using !important keywords, you should explicitly increase the priority of the HK Code Block CSS rules.If you find any bugs or have any feature requests, please report them on the GitHub Issues. Thank you!
Versions are controlled by the rule below.
- symbols in the highlight statement so that you can easily highlight multiple, continuous lines.as statement