我正在尝试从降价文件生成网页。此示例生成所需的网页视觉呈现:
header.html
<!DOCTYPE html>
<html>
<head>
<style>
code {
display: block;
white-space: pre;
padding: 20px;
line-height: 125%;
background: #eee;
border: 1px solid #ccc;
margin: 1em 0;
}
p:nth-of-type(1) code {
display: inline-block;
padding: 0;
color: red;
}
</style>
</head>
<body>
body.md
Assuming you have the IP `1.1.1.1` or `2.2.2.2`, then execute the following:
```
echo "hello world";
echo "another command here";
echo "you are done";
```
footer.html
</body>
</html>
当我运行命令时:
apt-get install markdown;
markdown body.md > body.html;
cat header.html body.html footer.html > index.html;
我在网络浏览器中看到:
这正是我想要看到的!
但是,我想删除
p:nth-of-type(1) code
规则,因为我不想编写自定义CSS选择器来针对每一个内联
<code>
块。我有数千页的标记文档要转换为html。手动逐页浏览以选择
<代码>
块是内联的,并且哪个是块级元素太耗时了。
有没有更简单的方法
a) 编写一个CSS选择器
p>code
当且仅当
p
具有且仅具有一个子元素,并且该子元素属于元素类型
code
或b)告诉
markdown
将css类添加到的命令
<代码>
要素
或者c)完全不同的东西,让我写一个通用的css规则来针对内联代码元素和块级代码元素?