Skip to content

Commit

Permalink
feat: support wrap option
Browse files Browse the repository at this point in the history
  • Loading branch information
HEIGE-PCloud committed Apr 28, 2024
1 parent 614e63b commit 33c8d62
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
7 changes: 4 additions & 3 deletions exampleSite/content/posts/basic-markdown-syntax/index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -561,12 +561,13 @@ You can supply extra options to the code block.
| ------ | ----------- |
| `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. |
Here is an example
````markdown
```go {open=true, lineNos=false, title="main.go"}
````markdown {open=true}
```go {open=true, lineNos=false, wrap=true, title="main.go"}
package main

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

import "fmt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,12 +562,13 @@ grunt.initConfig({
| ------ | ----------- |
| `open` | 是否展开代码块。默认值由 `maxShownLines` 决定。 |
| `lineNos` | 是否显示行数 |
| `wrap` | 长度溢出是否换行。 |
| `title` | 自定义代码块的标题。 |
以下是一个例子
````markdown
```go {open=true, lineNos=false, title="main.go"}
````markdown {open=true}
```go {open=true, lineNos=false, wrap=true, title="main.go"}
package main

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

import "fmt"
Expand Down
5 changes: 5 additions & 0 deletions exampleSite/content/posts/tests/codeblock-tests/index.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ I2luY2x1ZGUgPGlvc3RyZWFtPgppbnQgbWFpbigpCnsKICAgIHN0ZDo6Y291dCA8PCAiSGVsbG8gd29y
I2luY2x1ZGUgPGlvc3RyZWFtPgppbnQgbWFpbigpCnsKICAgIHN0ZDo6Y291dCA8PCAiSGVsbG8gd29ybGQhIiA8PCBlbmRsOwogICAgcmV0dXJuIDA7Cn0K
```

```{wrap=true}
I2luY2x1ZGUgPGlvc3RyZWFtPgppbnQgbWFpbigpCnsKICAgIHN0ZDo6Y291dCA8PCAiSGVsbG8gd29ybGQhIiA8PCBlbmRsOwogICAgcmV0dXJuIDA7Cn0KI2luY2x1ZGUgPGlvc3RyZWFtPgppbnQgbWFpbigpCnsKICAgIHN0ZDo6Y291dCA8PCAiSGVsbG8gd29ybGQhIiA8PCBlbmRsOwogICAgcmV0dXJuIDA7Cn0KI2luY2x1ZGUgPGlvc3RyZWFtPgppbnQgbWFpbigpCnsKICAgIHN0ZDo6Y291dCA8PCAiSGVsbG8gd29ybGQhIiA8PCBlbmRsOwogICAgcmV0dXJuIDA7Cn0KI2luY2x1ZGUgPGlvc3RyZWFtPgppbnQgbWFpbigpCnsKICAgIHN0ZDo6Y291dCA8PCAiSGVsbG8gd29ybGQhIiA8PCBlbmRsOwogICAgcmV0dXJuIDA7Cn0K
I2luY2x1ZGUgPGlvc3RyZWFtPgppbnQgbWFpbigpCnsKICAgIHN0ZDo6Y291dCA8PCAiSGVsbG8gd29ybGQhIiA8PCBlbmRsOwogICAgcmV0dXJuIDA7Cn0K
```

```cpp {title="main.cpp"}
#include <iostream>
int main()
Expand Down
3 changes: 2 additions & 1 deletion layouts/_default/_markup/render-codeblock.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
{{- else -}}
{{- $open = cond (eq .Attributes.open false) "is-closed" "is-open" -}}
{{- end -}}
{{- $wrap := cond (eq .Attributes.wrap true) "is-wrap" "" -}}

<div class="code-block highlight {{ $open }} {{ $lineNos }} tw-group tw-my-2">
<div class="code-block highlight {{ $open }} {{ $lineNos }} {{ $wrap }} tw-group tw-my-2">
<div class="
code-block-title
tw-flex
Expand Down

0 comments on commit 33c8d62

Please sign in to comment.