🐛 Fixed #155, the code block overflow in the markdown file.

This commit is contained in:
elkan1788
2025-01-21 20:44:34 +08:00
parent 23e220b5f3
commit 65a7a9c536
4 changed files with 208 additions and 81 deletions

View File

@@ -39,25 +39,15 @@ markup:
goldmark:
renderer:
unsafe: true
# 高亮代码的样式
# Highlight style of code
highlight:
# # 高亮代码的样式名称可选monokai | emacs | api | dracula | friendly
# # 更多的样式https://xyproto.github.io/splash/docs/all.html
# # Highlight style: monokai | emacs | api | dracula | friendly
# # More: https://xyproto.github.io/splash/docs/all.html
# style: "monokai"
anchorLineNos: true
codeFences: true
guessSyntax: true
hl_Lines: ""
hl_inline: false
lineAnchors: ""
lineNoStart: 1
lineNos: false
lineNumbersInTable: false
noClasses: true
noHl: false
style: monokai
tabWidth: 2
lineNos: true
lineNumbersInTable: true
noClasses: false
tableOfContents:
# 开始/结束标题级别1-6 (建议从2开始)
# Heading title level of start or end: 1-6

View File

@@ -27,6 +27,23 @@ Hugo 通过 Chroma 提供非常快速的语法高亮显示,现 Hugo 中使用
### GO
```makrdown
{{</* highlight go "linenos=table,hl_lines=8 15-17,linenostart=199" */>}}
func GetTitleFunc(style string) func(s string) string {
switch strings.ToLower(style) {
case "go":
return strings.Title
case "chicago":
return transform.NewTitleConverter(transform.ChicagoStyle)
default:
return transform.NewTitleConverter(transform.APStyle)
}
}
{{</* / highlight */>}}
```
{{< highlight go "linenos=table,hl_lines=8 15-17,linenostart=199" >}}
func GetTitleFunc(style string) func(s string) string {
@@ -48,14 +65,14 @@ func GetTitleFunc(style string) func(s string) string {
import javax.swing.JFrame; //Importing class JFrame
import javax.swing.JLabel; //Importing class JLabel
public class HelloWorld {
public static void main(String[] args) {
JFrame frame = new JFrame(); //Creating frame
frame.setTitle("Hi!"); //Setting title frame
frame.add(new JLabel("Hello, world!"));//Adding text to frame
frame.pack(); //Setting size to smallest
frame.setLocationRelativeTo(null); //Centering frame
frame.setVisible(true); //Showing frame
}
public static void main(String[] args) {
JFrame frame = new JFrame(); //Creating frame
frame.setTitle("Hi!"); //Setting title frame
frame.add(new JLabel("Hello, world!"));//Adding text to frame
frame.pack(); //Setting size to smallest
frame.setLocationRelativeTo(null); //Centering frame
frame.setVisible(true); //Showing frame
}
}
```
@@ -143,5 +160,30 @@ FROM
WHERE column_name = "condition"
{{< / highlight >}}
### 自动猜测代码高亮显示
```
.highlight {
// 其他代码
......
> .chroma {
position: relative;
// 修复代码块溢出问题
pre {
overflow-wrap: break-word;
white-space: pre-wrap;
line-break: anywhere;
word-break: break-all;
overflow-x: auto;
}
}
}
}
```
除以上列举的代码高亮显示外还支持诸如C 语言、C++、HTML、CSS、Shell脚本等各主流的代码语言高亮显示可自行测试效果。