GithubHelp home page GithubHelp logo

extract_headings's Introduction

extract_headings plugin for pelican

Any problems, please contact [email protected]

This is a very simple pelican plugin which extracts the h1~h6 headings from a markdown document.

This plugin introduces two new member to the pelican content object:

  • html_headings: a list of heading objects like {tag: "h1", value: "Hello this is h1 heading"}
  • html_toc: table of contents build with the markdown headings, html unordered list style

License

BSD (3-Clause) License. Please see LICENSE.txt for more details.

Requirements

  • python-markdown: pip install Markdown

Usage

First, clone the plugin repo to your plugin directory:

git clone https://github.com/wilbur-ma/extract_headings ${PELICAN_PLUGIN_DIRECTORY}/extract_headings

Then add or update the MD_EXTENSION and PLUGINS variables in your pelican configuration:

MD_EXTENSIONS = (['extra', 'codehilite', 'headerid'])
PLUGINS = ['extract_headings']

Use your own slugify function

You can define your own slugify function in your pelican configuration, e.g.:

import md5 
def my_slugify(value, sep):
    m = md5.new()
    m.update(value.encode("UTF-8"))
    return "toc_{}".format(m.digest().encode("hex"))
from markdown.extensions.headerid import HeaderIdExtension
MD_EXTENSIONS = ([HeaderIdExtension(configs=[('slugify', my_slugify)])])

You should tell the extrac_headings to use your slugify function by setting the MY_SLUGIFY_FUNC variable in your pelican configuration.

MY_SLUGIFY_FUNC = my_slugify

ul or ol

You can set the output list type via MY_TOC_LIST_TYPE configuration. By default extract_headings outputs the tocs in a unordered list, you can use ordered list by setting MY_TOC_LIST_TYPE to 'ol'.

Headings' id attribute

If you do not want to add id attribute to content's headings, just set MY_TOC_UPDATE_CONTENT = False in your pelican configuration.

Thanks

  • extract_toc plugin

extract_headings's People

Contributors

mawenbao avatar

Watchers

James Cloos avatar  avatar Yan Huang avatar

Forkers

vickyi sinoyster

extract_headings's Issues

当标题中含有中文的时候报错

我clone了master并添加了如下内容

MD_EXTENSIONS = (['extra', 'codehilite', 'headerid'])
PLUGINS = ['extract_headings']

当标题包含中文的时候会报错

ERROR: Could not process ./04_test.md
  | 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)

但是我看了你的源仓库,文章也是包含中文的,貌似并没有什么问题。
请问这个你是怎么解决的。好像跟u'字符串'之类的有关,因为对这方面不太懂,请指教一下^_^

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.