Skip to content

aleray/mdx_semanticdata

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Semantic data Extension for Python-Markdown

Adds support for semantic data (RDFa).

Converts structures like %% property :: content | label %% into span elements with a property and content attributes. label is optional;

Customizable with make_elt option as to what the actual element is.

Installation

pip install git+git://github.com/aleray/mdx_semanticdata.git 

Usage

>>> import markdown >>> text = "%%dc:author :: Sherry Turkle | Turkle's%% %%dc:title::Second Self%% was an early book on the social aspects of computation." >>> html = markdown.markdown(text, ['semanticdata']) >>> print(html) <p><span content="Sherry Turkle" property="dc:author">Turkle's</span> <span content="Second Self" property="dc:title">Second Self</span> was an early book on the social aspects of computation.</p> 

Custom tree element:

>>> def make_elt (md, rel, target, label): ... # `md` is the Markdown instance ... if rel == "dc:title": ... elt = markdown.util.etree.Element('cite') ... else: ... elt = markdown.util.etree.Element('span') ... elt.set('content', target) ... elt.text = label or target ... if rel: ... elt.set('property', rel) ... return elt >>> md = markdown.Markdown(extensions=['semanticdata'], ... extension_configs={'semanticdata' : [('make_elt', make_elt)]}) >>> html = md.convert(text) >>> print(html) <p><span content="Sherry Turkle" property="dc:author">Turkle's</span> <cite content="Second Self" property="dc:title">Second Self</cite> was an early book on the social aspects of computation.</p> 

Custom default namespace:

>>> text = "%%author :: Sherry Turkle | Turkle's%% %%title::Second Self%% was an early book on the social aspects of computation." >>> md = markdown.Markdown(extensions=['semanticdata'], ... extension_configs={'semanticdata' : [('namespace', 'dc')]}) >>> html = md.convert(text) >>> print(html) <p><span content="Sherry Turkle" property="dc:author">Turkle's</span> <span content="Second Self" property="dc:title">Second Self</span> was an early book on the social aspects of computation.</p> 

Dependencies

Copyright

All rights reserved.

This software is released under the modified BSD License. See LICENSE.md for details.

About

Python-Markdown extension to add support for semantic data (RDFa)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages