parse "linenumbers" in code block

This commit is contained in:
hypengw 2026-01-09 09:51:29 +08:00 committed by Manuel Rüger
parent 5bb400cf51
commit c1c9a13391
2 changed files with 28 additions and 34 deletions

View File

@ -237,48 +237,38 @@ Placeholder
### Code Blocks ### Code Blocks
If you have long code blocks, you can make them collapsible with the [Code Block Macro]: ````text
```bash
```bash collapse
... ...
some long bash code block some long bash code block
... ...
``` ```
````
And you can also add a title: | Parameter | Default |
| ------------------------------ | ------- |
| `collapse` | false |
| `title` | none |
| `linenumbers` | false |
| `1` (any number for firstline) | 1 |
```bash collapse title Some long long bash function Example:
...
some long bash code block
...
```
Or linenumbers, by giving the first number
```bash 1 collapse title Some long long bash function
...
some long bash code block
...
```
And even themes
```bash 1 collapse midnight title Some long long bash function
...
some long bash code block
...
```
* `bash collapse`
If you have long code blocks, you can make them collapsible.
* `bash collapse title Some long long bash function`
And you can also add a title.
* `bash linenumbers collapse title Some long long bash function`
And linenumbers.
* `bash 1 collapse title Some long long bash function`
Or directly give a number as firstline number.
* `bash 1 collapse midnight title Some long long bash function`
And even themes.
* `- 1 collapse midnight title Some long long code`
Please note that, if you want to have a code block without a language Please note that, if you want to have a code block without a language
use `-` as the first character, if you want to have the other goodies use `-` as the first character, if you want to have the other goodies.
``` - 1 collapse midnight title Some long long code More details at Confluence [Code Block Macro](https://confluence.atlassian.com/doc/code-block-macro-139390.html) doc.
...
some long code block
...
```
[Code Block Macro]: https://confluence.atlassian.com/doc/code-block-macro-139390.html
### Block Quotes ### Block Quotes

View File

@ -108,6 +108,10 @@ func (r *ConfluenceFencedCodeBlockRenderer) renderFencedCodeBlock(writer util.Bu
collapse = false collapse = false
continue continue
} }
if option == "linenumbers" {
linenumbers = true
continue
}
var i int var i int
if _, err := fmt.Sscanf(option, "%d", &i); err == nil { if _, err := fmt.Sscanf(option, "%d", &i); err == nil {