Skip to content

Commit

Permalink
feat: support header control
Browse files Browse the repository at this point in the history
  • Loading branch information
HEIGE-PCloud committed Apr 28, 2024
1 parent 373277a commit 267ee2b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
17 changes: 9 additions & 8 deletions exampleSite/content/posts/basic-markdown-syntax/index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -557,17 +557,18 @@ grunt.initConfig({
You can supply extra options to the code block.
| Option | Description |
| ------ | ----------- |
| `open` | Whether to expand the code block. The default value is determined by the `maxShownLines` option. |
| `lineNos` | Whether to show line numbers. |
| `wrap` | Whether to wrap lines when they overflow. |
| `title` | Set the title of the code block. |
| Option | Description | Type |
| ------ | ----------- | ---- |
| open | Whether to expand the code block. The default value is determined by the `maxShownLines` option. | bool |
| lineNos | Whether to show line numbers. | int |
| wrap | Whether to wrap lines when they overflow. | bool |
| title | Set the title of the code block. | string |
| header | Whether to display the code header and control buttons. | bool |
Here is an example
````markdown {open=true}
```go {open=true, lineNos=false, wrap=true, title="main.go"}
```go {open=true, lineNos=false, wrap=true, title="main.go", header=false}
package main

import "fmt"
Expand Down Expand Up @@ -614,7 +615,7 @@ func main() {
The rendered output looks like this:
```go {open=true, lineNos=false, wrap=true, title="main.go"}
```go {open=true, lineNos=false, wrap=true, title="main.go", header=false}
package main

import "fmt"
Expand Down
18 changes: 10 additions & 8 deletions exampleSite/content/posts/basic-markdown-syntax/index.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -558,17 +558,19 @@ grunt.initConfig({
您可以通过以下选项来自定义你的代码块:
| 选项 | 描述 |
| ------ | ----------- |
| `open` | 是否展开代码块。默认值由 `maxShownLines` 决定。 |
| `lineNos` | 是否显示行数。 |
| `wrap` | 长度溢出时是否换行。 |
| `title` | 自定义代码块的标题。 |
| 选项 | 描述 | 类型 |
| ------ | ----------- | ---- |
| open | 是否展开代码块。默认值由 `maxShownLines` 决定。 | bool |
| lineNos | 是否显示行数。 | int |
| wrap | 长度溢出时是否换行。 | bool |
| title | 自定义代码块的标题。 | string |
| header | 是否显示标题与控制按钮。 | bool |
以下是一个例子:
````markdown {open=true}
```go {open=true, lineNos=false, wrap=true, title="main.go"}
```go {open=true, lineNos=false, wrap=true, header=false, title="main.go"}
package main

import "fmt"
Expand Down Expand Up @@ -615,7 +617,7 @@ func main() {
输出的效果如下:
```go {open=true, lineNos=false, wrap=true, title="main.go"}
```go {open=true, lineNos=false, wrap=true, header=false, title="main.go"}
package main

import "fmt"
Expand Down
9 changes: 9 additions & 0 deletions exampleSite/content/posts/tests/codeblock-tests/index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,13 @@ int main()
std::cout << "Hello world!" << std::endl;
return 0;
}
```

```cpp {header=false}
#include <iostream>
int main()
{
std::cout << "Hello world!" << std::endl;
return 0;
}
```
3 changes: 2 additions & 1 deletion layouts/_default/_markup/render-codeblock.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
{{- $open = cond (eq .Attributes.open false) "is-closed" "is-open" -}}
{{- end -}}
{{- $wrap := cond (eq .Attributes.wrap true) "is-wrap" "" -}}

{{- $header := cond (eq .Attributes.header false) "tw-hidden" "" -}}
<div class="code-block highlight {{ $open }} {{ $lineNos }} {{ $wrap }} tw-group tw-my-2">
<div class="
code-block-title
{{ $header }}
tw-flex
tw-flex-row
tw-justify-between
Expand Down

0 comments on commit 267ee2b

Please sign in to comment.