一个python标记扩展,允许您将语义html5分区元素添加到生成的html中。
ocxsect的Python项目详细描述
标记中的剖切
对python markdown的一个扩展,允许您通过在节的开头放置~~S~~
和结尾放置~~/S~~
等字符串,将语义HTML5节元素添加到生成的HTML中。支持的切片元素有<section>
、<chapter>
、<header>
、<footer>
、<nav>
、<div>
和<article>
。这些可以通过在剖分元素字母后面添加文本来获得标识符,例如~~S section1~~
以给出<section id="section1">
。结构的示意图表示(对调试有用)也将生成并存储为markdown对象的markdown.markdown.tree_diagram属性。
需求和依赖性
Python3(在Python3.6和3.7上测试)
设计用于MkDocs
使用python包Python-Markdown、Python re、xml.etree.ElementTree和re - Regular expression operations
从github源安装setup.py需要setuptools
与其他使用~~~
来描述标记的python标记扩展配合得不太好,特别是它可能导致文本显示为穿透。
安装
警告:xml.etree.elementtree模块对恶意构造的数据不安全。如果需要分析不受信任或未经身份验证的数据,请参见XML vulnerabilities。
警告:请谨慎使用此早期版本的软件,无需任何保证,请首先在虚拟环境中测试此软件!
从pypi安装:
(venv)$ pip install ocxsect
或从github安装:
(venv)$ git clone https://github.com/philbarker/ocxsect.git
(venv)$ cd ocxsect
(venv)$ python setup.py test
(venv)$ python setup.py install
(venv)$ python test.py
用法
若要创建新节,请将~~X~~
单独放在一行上,其中x表示要创建的html5节元素的类型。支持的切片元素有section
、chapter
(c)header
(h)footer
(f)nav
(n)div
(d)和article
(a)。这些可以通过在分区元素字母后面添加文本(例如~~S lesson1~~
)来获得标识符。为了避免非url安全字符在标识符中的任何字符不在集合a-z,a-z,0-9,!已删除$-()+。所以~~A #activity 1~~
变成<article id="activity1">
。
在mkdocs中的用法
安装后,将ocxsect
添加到mkdocs.yml中的扩展块:
markdown_extensions:
- ocxsect
示例
降价输入
~~C lesson1~~
~~H~~
#Markdown structure test
This is in the header section of a chapter. The chapter has id #lesson1. The header has no id.
~~/H~~
~~S section 1~~
#Activity 1
This is in a regular section (id #section1) of a chapter
~~/S~~
~~F~~
This is in the footer of the chapter
~~/F~~
~~/C~~
结构示意图
|--chapter{'id': 'lesson1'}
|--header
|--h1
|--p
|--section{'id': 'section1'}
|--h1
|--p
|--footer
|--p
|--p
HTML输出
<chapter id="lesson1">
<header>
<h1>Markdown structure test</h1>
<p>This is in the header section of a chapter. The chapter has id #lesson1. The header has no id.</p>
</header>
<section id="section1">
<h1>Activity 1</h1>
<p>This is in a regular section (id #section1) of a chapter</p>
</section>
<footer>
<p>This is in the footer of the chapter</p>
</footer>
</chapter>
<p>This is after the chapter</p>
请参阅test.py以获取嵌入标记的完全工作示例。