如果在某处记录了以编程方式实现此目的的简单方法(不是通过在浏览器字段中复制/粘贴并单击按钮进行转换),我深表歉意。在我的搜索和阅读中我找不到它。
我想以编程方式将 Markdown 和 CSS 文件转换为听起来可能称为“内联”CSS 的文件。例如:
这个 Markdown 文件(file.md
)
# Install
Install instructions
## Update
Update instructions
这个 CSS 文件(style.css
)
h1 {
font-size: 100px;
}
h2 {
color: red;
}
就变成这样了(file.html
)
<h1 style="font-size: 100px;"><a id="install"></a>Install</h1>
<p>Install instructions</p>
<h2 style="color: red;"><a id="update"><a>Update</h2>
<p>Update instructions</p>
我正在将 Markdown 转换为 HTMLPandoc https://pandoc.org/
pandoc -f markdown -t html file.md -o file.html
当我使用
pandoc -f markdown -t html file.md -o file.html --css=style.css --self-contained
(or --standalone
)
它返回
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang xml:lang>
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>file</title>
<style type="text/css">
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
span.underline{text-decoration: underline;}
div.column{display: inline-block; vertical-align: top; width: 50%;}
</style>
<style type="text/css">h1 {font-size: 100px;}h2 {color: red;}</style>
<!--[if lt IE 9]>
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
<![endif]-->
</head>
<body>
<h1><a id="install"></a>Install</h1>
<p>Install instructions</p>
<h2><a id="update"><a>Update</h2>
<p>Update instructions</p>
</body>
</html>
如上所述,这不是我的目标。我希望 CSS 严格“内联”:
<h1 style="font-size: 100px;"><a id="install"></a>Install</h1>
是否有人知道已经编写的工具或脚本可以通过编程方式实现此目的?我已经搜索过了,却一无所获。理想情况下我可以使用 Pandoc 来实现此目的,但我找不到方法。
我不在乎<head>
and <style>
HTML 块是否存在。该 HTML 将通过 cURL 发送到内容管理系统,该系统会删除除内部内容之外的所有 HTML 元素<body>
以及任何“内联”CSS。
感谢您的任何想法或为我指明方向。