Usually my markdown document uses only one type of code language. For example, python is used to highlight all my code blocks.
```python
some code here.
```
```python
another piece of code
```
Since I need to type python for every piece of my code block, I would like to know if there is a way to define a default pre code highlighting language for the whole document. Then if it's defined, for example, cpp, all of the code blocks in the document will be highlighted using cpp syntax.
Thank you very much.
There is no solution that will work everywhere unfortunately, Markdown components are usually "standalone", with no overall configuration available.
Whilst there is no enforced standard of Markdown, CommonMark is the closest, and it makes no mention of a default language for code blocks:
The line with the opening code fence may optionally contain some text following the code fence; this is trimmed of leading and trailing spaces or tabs and called the info string.
...
An info string can be provided after the opening code fence. Although this spec doesn’t mandate any particular treatment of the info string, the first word is typically used to specify the language of the code block.
For example, if you're using Jekyll, this inside the _config.yml will do what you're asking:
kramdown:
syntax_highlighter_opts:
default_lang: python
If you're after a solution for a specific platform (or IDE etc), I'd recommend updating the question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With