From c1c9a13391183b8f4e37a96005f6ecf121622390 Mon Sep 17 00:00:00 2001 From: hypengw Date: Fri, 9 Jan 2026 09:51:29 +0800 Subject: [PATCH] parse "linenumbers" in code block --- README.md | 58 +++++++++++++++---------------------- renderer/fencedcodeblock.go | 4 +++ 2 files changed, 28 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 0fa1429..38f2c2a 100644 --- a/README.md +++ b/README.md @@ -237,48 +237,38 @@ Placeholder ### Code Blocks -If you have long code blocks, you can make them collapsible with the [Code Block Macro]: - -```bash collapse +````text +```bash ... 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 -... -some long bash code block -... -``` +Example: -Or linenumbers, by giving the first number +* `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 + use `-` as the first character, if you want to have the other goodies. -```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 -... -``` - -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 - -``` - 1 collapse midnight title Some long long code -... -some long code block -... -``` - -[Code Block Macro]: https://confluence.atlassian.com/doc/code-block-macro-139390.html +More details at Confluence [Code Block Macro](https://confluence.atlassian.com/doc/code-block-macro-139390.html) doc. ### Block Quotes diff --git a/renderer/fencedcodeblock.go b/renderer/fencedcodeblock.go index bc89650..1e5e9b4 100644 --- a/renderer/fencedcodeblock.go +++ b/renderer/fencedcodeblock.go @@ -108,6 +108,10 @@ func (r *ConfluenceFencedCodeBlockRenderer) renderFencedCodeBlock(writer util.Bu collapse = false continue } + if option == "linenumbers" { + linenumbers = true + continue + } var i int if _, err := fmt.Sscanf(option, "%d", &i); err == nil {