Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

代码行号 #113

Open
AccelYu opened this issue May 17, 2020 · 4 comments
Open

代码行号 #113

AccelYu opened this issue May 17, 2020 · 4 comments

Comments

@AccelYu
Copy link

AccelYu commented May 17, 2020

请问有办法让代码块显示行号吗?如果没有这个功能作者是否考虑加一下呢。

@mzlogin
Copy link
Owner

mzlogin commented May 30, 2020

可以通过 JS 实现,我试了下这个:https://github.com/JS-Zheng/code-line

效果:

image

但它可能改变原有代码样式,有的代码块首尾会有多余空行等 ,我觉得不完美,目前没加到模板里。

@yanglr
Copy link
Contributor

yanglr commented Jul 26, 2020

@mzlogin
Copy link
Owner

mzlogin commented Jul 27, 2020

我用prism.js做的效果,https://www.geekplayers.com/2019/12/03/leetcode976-largest-perimeter-triangle/
image

可以~这个挺好。

@yanglr
Copy link
Contributor

yanglr commented Jul 27, 2020

使用prism.js加入代码行号:

到prism.js官网https://prismjs.com/download.html进行定制,在页面底部预览,我选了代码高亮line numbertoolbarcopy to clipboard等功能。

Change the style in /css/syntax.css

.highlight pre code * {
white-space: pre !important; // this sets all children inside to nowrap
}

_include/header.md的head标签中加入css

_include/footer.md中的body标签中加入js 并调用 jquery

<script type="text/javascript">
  $('pre').addClass("line-numbers").css("white-space", "pre-wrap");
</script>

参考:
使用prismjs实现Jekyll代码语法高亮并显示行号_skillip.com-CSDN博客_prismjs 显示代码行数
https://blog.csdn.net/u013961139/article/details/78853544

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants