python markdown扩展,为markdown文档添加少量结构。

mdx_sections的Python项目详细描述


MDX U部分

概述

此模块是Python-Markdown的扩展,它提供了向标记文档添加少量结构的能力。

此扩展的操作有两个前提:

  • 每个标题元素都指示新文档节的开始。
  • 文档节可以嵌套,并且文档节的父级是由前一个标题元素创建的节,该元素具有更高的顺序,例如,前一个h2节包含在与h1相对应的前一个标题块中。如果没有这样的元素,则它是根元素的子元素。

新节(包含div元素)可以配置为具有特定的idclass属性。语法为:

# {id,class} Title

idclass都是可选的,只要启用此扩展,就将始终创建containingdiv元素。

一个例子应该说明这一点。假设提供了以下输入文档:

# {resume} Resumé

## {education} Education
Educational experience

## {experience} Working Experience
Work experience

### {xyz_corp,employer} XYZ Corp.
I worked at XYZ

### {acme_inc,employer} Acme Inc.
I also worked at Acme

## Hobbies
- Cards
- Books
- Dogs

### About _my_ hobbies
My hobbies are great.

这将转换为:

<div class="section" id="section_resume">
  <h1 class="title">Resum&eacute;</h1>
  <div class="section" id="section_education">
    <h2 class="title">Education</h2>
    <p>Educational experience</p>
  </div>
  <div class="section" id="section_experience">
    <h2 class="title">Working Experience</h2>
    <p>Work experience</p>
    <div class="employer" id="section_xyz_corp">
      <h3 class="title">XYZ Corp.</h3>
      <p>I worked at XYZ</p>
    </div>
    <div class="employer" id="section_acme_inc">
      <h3 class="title">Acme Inc.</h3>
      <p>I also worked at Acme</p>
    </div>
  </div>
  <div class="section">
    <h2 class="title">Hobbies</h2>
    <ul>
      <li>Cards</li>
      <li>Books</li>
      <li>Dogs</li>
    </ul>
    <div class="section">
      <h3 class="title">About <em>my</em> hobbies</h3>
      <p>My hobbies are great.</p>
    </div>
  </div>
</div>

结果文档在语义上是正确的。使用css的样式也更容易。

安装

使用setuptools安装,例如(在virtualenv中):

$ pip install mdx_sections

或者如果您希望从github获取最新信息:

$ git clone git://github.com/jessedhillon/mdx_sections.git

使用量

有关python标记扩展的扩展介绍,请参见文档http://freewidom.org/projects/python markdown/extensions。

这个扩展名的缩写是sections,它有两个配置参数:

  • section_cls,默认为section。这是应用于生成的div的默认css类,当标记文档未指定时。
  • heading_cls,默认为title。这是应用于正在转换的h[1-6]元素的默认css类。

更改

0.1

^{em1}2012年2月22日

  • 首次公开发行。

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

推荐PyPI第三方库


热门话题
图形Java仿射变换以旋转通用路径   IntelliJ IDEA中的java代码标记为编译器错误,在Eclipse中可以正常工作   java ArrayList的containsAll返回了错误的值   如何在安卓中的片段活动中添加java代码   java通过使用netbeans调用jbutton,将带有行的jbutton添加到jtable中   java在更新arrayAdapter/listView之前更新最终列表   java如何在另一个项目中导入包含AspectJ方面和注释的项目   为什么我的java布尔测试总是失败?   Eclipse中的java自动激活   在Bluetooth for Java(更具体地说是Android)之上是否有TCP/IP协议栈实现?   java Android Studio通过intent传递ArrayList并填充ListView