使用指定的 css 将 markdown 转换为 html

发布于 2025-01-06 00:25:12 字数 542 浏览 2 评论 0原文

首先,我要说 - 我喜欢 Markdown。真的很喜欢它。它简单、优雅、性感,这就是我对标记语言的所有期望。如果可以的话,我会建议它:)

到目前为止,我一直在以一种非常好的和简单的方式使用它,Vim + python-markdown = 在我选择的浏览器中快速预览。

但是,它有一个缺点......CSS表被硬编码在插件内的某个地方,我无法更改它。 注意:我对 python 的了解为零,或者非常接近它。

是否有一个 markdown 到 -各种格式 - 插件,可以让你指定要使用的 css 页面,这样我就可以有几个并使用我当时希望的版本创建同一文档的多个版本?

它会是这样的

markdown  my-document-in.markdown  css-sheet.css  cool-looking-document.html

First, let me say - I love markdown. Truly love it. It's simple, it's elegant, it's sexy, it's everything I wish for in a markup language. If I could, I'd propose to it :)

So far I've been using it in a very nice and simple way, Vim + python-markdown = fast preview in my browser of choice.

But, it has one drawback ... the css sheet is hardcoded somewhere inside the plugin, and I can't change it. Note: I know zero python, or something very close to it.

Is there a markdown to -various formats- plugin that lets you specify a css page to use, so that I could have several and create several versions of the same document using the one I wish at that time?

It would go something like

markdown  my-document-in.markdown  css-sheet.css  cool-looking-document.html

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩人痒 2025-01-13 00:25:12

使用 https://github.com/trentm/python-markdown2/ (特别是 https://raw.github.com/trentm/python-markdown2/master/lib/markdown2.py) ,我写了一个小脚本,当它被称为generator.py input.markdown styles.css Pretty.html (假设你将其保存为generator.py)使用python-markdown2库将markdown转换为HTML,将css文件嵌入到顶部并将其写入 Pretty.html。

import markdown2
import os, sys


output = """<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <style type="text/css">
"""

cssin = open(sys.argv[2])
output += cssin.read()

output += """
    </style>
</head>

<body>
"""
mkin = open(sys.argv[1])
output += markdown2.markdown(mkin.read())

output += """</body>

</html>
"""

outfile = open(sys.argv[3])
outfile.write(output)
outfile.close()`

将 github 上的链接文件和上面的代码复制到一个文件夹中,它应该可以正常运行。我在本地测试过,可以用。希望它也能帮助你。

Using https://github.com/trentm/python-markdown2/ (specifically https://raw.github.com/trentm/python-markdown2/master/lib/markdown2.py), I wrote a small script which when called as generator.py input.markdown styles.css pretty.html (assuming you saved it as generator.py) uses the python-markdown2 library to convert the markdown to HTML, embeds the css file in the top and writes it to pretty.html.

import markdown2
import os, sys


output = """<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <style type="text/css">
"""

cssin = open(sys.argv[2])
output += cssin.read()

output += """
    </style>
</head>

<body>
"""
mkin = open(sys.argv[1])
output += markdown2.markdown(mkin.read())

output += """</body>

</html>
"""

outfile = open(sys.argv[3])
outfile.write(output)
outfile.close()`

Copy the linked file from github and the code above into a folder together and it should run fine. I've tested it locally and it works. Hope it can help you too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文