2

嗨,我正在尝试让我的 multimarkdown 文件的顶部看起来像:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml">
    <head><title>Test of markdown</title>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <link rel="stylesheet" type="text/css" href="../main.css" />
    </head>

我知道如何添加以下元标记:

Title: Test of markdown
CSS: ../main.css
Quotes language: english

这给了我:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8"/>
        <title>Test of markdown</title>
        <link type="text/css" rel="stylesheet" href="../main.css"/>
    </head>

但我不确定如何添加其余部分。将不胜感激任何帮助。谢谢

4

1 回答 1

1

我找不到任何本机markdown方法来执行此操作,但如果您真的觉得需要这样做,您可以在生成的 HTML 上运行一个小脚本。

这是一个简单的 Python 3 选项,可以帮助您入门。这可以通过多种方式进行改进,但希望保持简单。一个明显的想法是给它一个文件夹并让它处理文件夹中的每个 HTML 文件。但我希望这给出了这个想法。

示例代码:

filepath = input('What is the full file path to the file? - ')

htmldoctype = ' '.join([
    '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN"',
    '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
    '\n'
])

htmlinfo = ('<html xmlns="http://www.w3.org/1999/xhtml">\n')

inlines = []

try:
    with open(filepath, mode='r', encoding='utf-8') as infile:
        for line in infile:
            if line.strip() == '<!DOCTYPE html>':
                inlines.append(htmldoctype)
            elif line.strip() == '<html>':
                inlines.append(htmlinfo)
            else:
                inlines.append(line)
except Exception:
    print('something went wrong in get')

try:
    with open(filepath, mode='w', encoding='utf-8') as outfile:
        for line in inlines:
            outfile.write(line)
except Exception:
    print('something went wrong in write')

输入:

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="utf-8"/>
        <title>Test of markdown</title>
        <link type="text/css" rel="stylesheet" href="../main.css"/>
      </head>
    <body>
        test
    </body>
    </html>

输出:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8"/>
        <title>Test of markdown</title>
        <link type="text/css" rel="stylesheet" href="../main.css"/>
    </head>
<body>
  test
</body>
</html>
于 2018-01-06T22:35:49.483 回答