一段简单的代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>行号</title>
</head>
<body>
<p>测试页面</p>
</body>
</html>
我想给它加行号,形成下面的形式
使用xmp标签是最简单的做法:
css 部分
div {
counter-reset: myCounter;
}
xmp::before {
counter-increment: myCounter 1;
content: counter(myCounter) '.';
}
html部分
<div>
<xmp><!DOCTYPE html></xmp>
<xmp><html lang="en"></xmp>
<xmp><head></xmp>
<xmp> <meta charset="UTF-8"></xmp>
<xmp> <title>行号</title></xmp>
<xmp></head></xmp>
<xmp><body></xmp>
<xmp> <p>测试页面</p></xmp>
<xmp></body></xmp>
<xmp></html></xmp>
</div>
xmp不是废弃了吗,我就改用pre,这下麻烦了html部分需要将<>分别转义成
<
>
下面的形式
<div>
<pre><!DOCTYPE html></pre>
<pre><html lang="en"></pre>
<pre><head></pre>
<pre> <meta charset="UTF-8"></pre>
<pre> <title>行号</title></pre>
<pre></head></pre>
<pre><body></pre>
<pre> <p>测试页面</p></pre>
<pre></body></pre>
<pre></html></pre>
</div>
好麻烦,有无简单的js方案来做?