一个python标记扩展,允许您将语义html5分区元素添加到生成的html中。

ocxsect的Python项目详细描述


Build StatusCoverage

标记中的剖切

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-MarkdownPython rexml.etree.ElementTreere - 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节元素的类型。支持的切片元素有sectionchapter(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以获取嵌入标记的完全工作示例。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何在Android Wifi中筛选相同的SSID?   Java中重写接口中异常处理的泛型   java“无效转义序列(有效的是\b\t\n\f\r\”\“\”\)”语法错误   使用JNDI的java NameReadyBoundException   java如何在这个程序上执行算法   java为什么我的应用程序在调试时崩溃而应用程序停止?   Java:while循环未检测到中断条件,但如果块检测到   java如何快速使用jfreechart创建的折线图   java将输入放入JSTL会话变量,以便稍后在屏幕上显示   java在spring boot中加载外部JAR   java Apache NiFi无法使用ojdbc6连接到Oracle 12c。jar或ojdbc8。罐子   java解释StringToWordVector()Weka的输出   java charAt()找不到符号   使用mpjexpress的java阅读控制台输入