A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/aleray/mdx_semanticdata below:

aleray/mdx_semanticdata: Python-Markdown extension to add support for semantic data (RDFa)

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.

pip install git+git://github.com/aleray/mdx_semanticdata.git
>>> 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>

All rights reserved.

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


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4