Generate documents according to the template.
Project description
安装方法
使用 pip 安装:
pip install document-template
使用方法
- test.html:
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>#{title}</title>
</head>
<body>
<h1>#{head}</h1>
<a href="#{url}">#{url}</a>
<br>
Test.......
<hr>
<span style="font-size: larger;font-weight: bold">#{large_font}</span>
<br>
为真时显示:#{bool:show_span}<span>显示的内容</span>#{bool:show_span};;分割;;#{bool:show_span}show_span is True#{bool:show_span}
<br>
#{copy:start}多行文字,替换局部内容:#{contents} 和 #{another_contents}#{copy:end}
</body>
</html>
- test.py:
from document_template import DocumentTemplate
if __name__ == '__main__':
id_dict = {"title": "标题", "head": "正文标题", "url": "https://github.com/liying2008", "large_font": "大号字体"}
id_dict['show_span'] = True
# Multi-line copy supports string, list and tuple
# id_dict['contents'] = 'ABCDEFG'
# id_dict['another_contents'] = '1234567'
id_dict['contents'] = ('A', 'B', 'C', 'D', 'E', 'F', 'G')
id_dict['another_contents'] = ['1', '2', '3', '4', '5', '6', '7']
temp = DocumentTemplate()
temp.load("test.html", encoding='utf-8')
temp.set_identifier_dict(id_dict)
temp.linefeed = '<br>\n'
temp.save_document("new_test.html")
注意事项
成对出现的 #{bool:} 须在同一行;
成对出现的 #{copy:} 须在同一行;
不支持 #{bool:}、 #{copy:} 嵌套使用。
更新内容
支持 Python 3;
支持多行拷贝中有多个 #{标识符};
支持自定义多行拷贝的换行符。
LICENSE
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file document-template-0.0.6.tar.gz.
File metadata
- Download URL: document-template-0.0.6.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.20.0 CPython/2.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b541a4680be9a075eb5edab085b7ed05f21623c21e81a61e2e6fd524f6143f3
|
|
| MD5 |
e1d6695ee5f278425ca164d639ff7050
|
|
| BLAKE2b-256 |
fecc9847cfbc82f010242032abe70ad1e87d153090b010e0d9d4629037377e3d
|
File details
Details for the file document_template-0.0.6-py2.py3-none-any.whl.
File metadata
- Download URL: document_template-0.0.6-py2.py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.20.0 CPython/2.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8356db0db439813951239dc7ded987463378a1e426f4609f5e9ac45f99e1bc3
|
|
| MD5 |
0712c9383742b4714e78f4a81e657811
|
|
| BLAKE2b-256 |
b5010038c481e0f66b86841b56ec3dde1af30b8695c0fb50066806de3594a33e
|