Added support for code tabs

This commit is contained in:
squidfunk
2018-06-10 17:23:06 +02:00
committed by Martin Donath
parent 55aa14014b
commit 05e4d17cbf
6 changed files with 195 additions and 7 deletions

View File

@@ -108,7 +108,7 @@ Line numbers can be added by enabling the `linenums` flag in your `mkdocs.yml`:
``` yaml
markdown_extensions:
- codehilite:
linenums:true
linenums: true
```
Example:
@@ -134,6 +134,87 @@ Result:
if items[j] > items[j + 1]:
items[j], items[j + 1] = items[j + 1], items[j]
### Grouping code blocks
The [SuperFences][5] extension which is part of the [PyMdown Extensions][6]
package adds support for grouping code blocks with tabs. This is especially
useful for documenting projects with multiple language bindings.
Example:
````
``` bash tab="Bash"
#!/bin/bash
echo "Hello world!"
```
``` c tab="C"
#include <stdio.h>
int main(void) {
printf("Hello world!\n");
}
```
``` c++ tab="C++"
#include <iostream>
int main() {
std::cout << "Hello world!" << std::endl;
return 0;
}
```
``` c# tab="C#"
using System;
class Program {
static void Main(string[] args) {
Console.WriteLine("Hello world!");
}
}
```
````
Result:
``` bash tab="Bash"
#!/bin/bash
echo "Hello world!"
```
``` c tab="C"
#include <stdio.h>
int main(void) {
printf("Hello world!\n");
}
```
``` c++ tab="C++"
#include <iostream>
int main() {
std::cout << "Hello world!" << std::endl;
return 0;
}
```
``` c# tab="C#"
using System;
class Program {
static void Main(string[] args) {
Console.WriteLine("Hello world!");
}
}
```
[5]: https://facelessuser.github.io/pymdown-extensions/extensions/superfences/
[6]: https://facelessuser.github.io/pymdown-extensions
### Highlighting specific lines
Specific lines can be highlighted by passing the line numbers to the `hl_lines`
@@ -162,7 +243,6 @@ Result:
if items[j] > items[j + 1]:
items[j], items[j + 1] = items[j + 1], items[j]
## Supported languages <small>excerpt</small>
CodeHilite uses [Pygments][2], a generic syntax highlighter with support for