polyglot.markdown.translate module

convert plain-text blocks into various markdown elements

Author:David Young
Date Created:February 26, 2017
class polyglot.markdown.translate.translate(log, settings=False)[source]

The Multimarkdown translator object

Key Arguments:
  • log – logger
  • settings – the settings dictionary

Usage:

To setup your logger, settings and database connections, please use the fundamentals package (see tutorial here).

To initiate a translate object, use the following:

from polyglot.markdown import translate
md = translate(
    log=log,
    settings=settings
)
blockquote(text)[source]

convert plain-text to MMD blockquote

Key Arguments:
  • text – the text to convert to MMD blockquote
Return:
  • blockquote – the MMD blockquote

Usage:

To convert a text to a MMD blockquote:

text = md.quote(" This is my quote  ")
print text

# OUTPUT:
# >  This is my quote
#
bold(text)[source]

convert plain-text to MMD bolded text

Key Arguments:
  • text – the text to convert to MMD bold
Return:
  • text – the bolded text

Usage:

To convert a text block to bolded text:

text = md.bold(" nice day!   ")
print text

# OUTPUT:  **nice day!**
cite(title, author=False, year=False, url=False, publisher=False, mediaKind=False, linkedText=False, nocite=False)[source]

generate a MMD citation

Key Arguments:
  • title – the citation title
  • author – the author. Dafault False
  • year – year published. Dafault False
  • url – url to the media. Dafault False
  • publisher – the publisher of the media. Dafault False
  • mediaKind – what kind of media is it?. Dafault False
  • linkedText – the text to link to the citation. Dafault False/blank
  • nocite – a give citation that has no reference in main doc
Return:
  • citation – the MMD citation

Usage:

To generate a MMD citation:

citation = md.cite(
    title="A very good book",
    author="John Doe",
    year=2015,
    url="http://www.thespacedoctor.co.uk",
    publisher="Beefy Books",
    mediaKind=False,
    linkedText="Doe 2015")
print citation

# OUTPUT:  [Doe 2015][#averygoodbook90]
#
# [#averygoodbook90]: John Doe. *[A Very Good Book](http://www.thespacedoctor.co.uk)*. Beefy Books, 2015. 
code(text)[source]

convert plain-text to MMD inline-code text

Key Arguments:
  • text – the text to convert to MMD inline-code text
Return:
  • text – the inline-code text

Usage:

To convert a text block to inline-code text:

text = md.code(" nice day!   ")
print text

# OUTPUT:  `nice day!`
codeblock(text, lang='')[source]

convert plain-text to MMD fenced codeblock

Key Arguments:
  • text – the text to convert to MMD fenced codeblock
  • lang – the code language for syntax highlighting. Default ‘’
Return:
  • text – the MMD fenced codeblock

Usage:

To convert a text block to comment text:

text = md.codeblock("def main()", "python")
print text

# OUTPUT:
# ```python
# def main()
# ```
comment(text)[source]

convert plain-text to MMD comment

Key Arguments:
  • text – the text to convert to MMD comment
Return:
  • text – the comment text

Usage:

To convert a text block to comment text:

text = md.comment(" nice day!   ")
print text

# OUTPUT:  {>>nice day!<<}
definition(text, definition)[source]

genarate a MMD definition

Key Arguments:
  • text – the text to define
  • definition – the definition
Return:
  • definition – the MMD style definition

Usage:

To genarate a MMD definition:

text = """Pomaceous fruit of plants of the genus Malus in the family Rosaceae.
Also the makers of really great products."""

definition = md.definition("Apple", text)
print definition

# OUTPUT:
# Apple
# :    Pomaceous fruit of plants of the genus Malus in the family Rosaceae.
#      Also the makers of really great products.
#
em(text)[source]

convert plain-text to MMD italicised text

Key Arguments:
  • text – the text to convert to MMD italics
Return:
  • text – the emphasised text

Usage:

To convert a text block to emphasised text:

text = md.em(" nice day!   ")
print text

# OUTPUT:  _nice day!_
footnote(text)[source]

convert plain-text to MMD footnote

Key Arguments:
  • text – the text to convert to MMD footnote
Return:
  • text – the footnote text

Usage:

To convert a text block to footnote text:

text = md.footnote(" nice day!   ")
print text

# OUTPUT:  [^20170228T21:57:40-99]
#
# [^20170228T21:57:40-99]: nice day!
glossary(term, definition)[source]

genarate a MMD glossary

Key Arguments:
  • term – the term to add as a glossary item
  • definition – the definition of the glossary term
Return:
  • glossary – the glossary text

Usage:

To genarate a glossary item:

text = """Pomaceous fruit of plants of the genus Malus in the family Rosaceae.
Also the makers of really great products."""

definition = md.glossary("Apple", text)
print definition

# OUTPUT: 
# [^apple]
#
# [^apple]: Apple
#    Pomaceous fruit of plants of the genus Malus in the family Rosaceae.
#    Also the makers of really great products.
header(text, level)[source]

convert plain-text to MMD header

Key Arguments:
  • text – the text to convert to MMD header
  • level – the header level to convert the text to
Return:
  • header – the MMD header

Usage:

To convert a text MMD header:

header = md.header(" This is my header  ", level=3)
print header

# OUTPUT:
# ### This is my header
#

generate a link to a MMD header

Key Arguments:
  • headerText – the header text (or anchor tag)
  • text – the doc text to link. Default False
Return:
  • link – the link to the header

Usage:

To generate a MMD header link:

link = md.headerLink(" This is my header  ", "inline text")
print link

# OUTPUT:
# [inline text][This is my header]
#
hl(text)[source]

convert plain-text to MMD critical markup highlighted text

Key Arguments:
  • text – the text to convert to MMD highlighted text
Return:
  • text – the highlighted text

Usage:

To convert a text block to highlighted text:

text = md.hl(" nice day!   ")
print text

# OUTPUT:  {==nice day!==}
image(url, title='', width=800)[source]

create MMD image link

Key Arguments:
  • title – the title for the image
  • url – the image URL
  • width – the width in pixels of the image. Default 800
Return:
  • imageLink – the MMD image link

Usage:

To create a MMD image link:

imageLink = md.image(
    "http://www.thespacedoctor.co.uk/images/thespacedoctor_icon_white_circle.png", "thespacedoctor icon", 400)
print imageLink

# OUTPUT:
# ![thespacedoctor icon][thespacedoctor icon 20170228t130146.472262]
#
# [thespacedoctor icon 20170228t130146.472262]: http://www.thespacedoctor.co.uk/images/thespacedoctor_icon_white_circle.png "thespacedoctor icon" width=400px
#

generate a MMD sytle link

Key Arguments:
  • text – the text to link from
  • url – the url to link to
Return:
  • text – the linked text

Usage:

To convert a text and url to MMD link:

text = md.inline_link(
    "  google search engine  ", "  http://www.google.com ")
print text

# OUTPUT:
#   [google search engine](http://www.google.com)
math_block(text)[source]

convert plain-text to MMD math block

Key Arguments:
  • text – the text to convert to MMD math block
Return:
  • math – the math block text

Usage:

To convert a text to MMD math block:

text = md.math_inline("{e}^{i\pi }+1=0")
print text

# OUTPUT:  $${e}^{i\pi }+1=0$$
math_inline(text)[source]

convert plain-text to MMD inline math

Key Arguments:
  • text – the text to convert to MMD inline math
Return:
  • math – the inline math text

Usage:

To convert a text to MMD inline math:

text = md.math_inline("{e}^{i\pi }+1=0")
print text

# OUTPUT:  ${e}^{i\pi }+1=0$
ol(text)[source]

convert plain-text to MMD ordered list

Key Arguments:
  • text – the text to convert to MMD ordered list
Return:
  • ol – the MMD ordered list

Usage:

To convert text to MMD ordered list:

ol = md.ol(" This is a list item   ")
print ol

# OUTPUT:
# 1.  This is a list item
#
strike(text)[source]

convert plain-text to HTML strike-through text

Key Arguments:
  • text – the text to convert to HTML strike-through
Return:
  • text – the strike-through text

Usage:

To convert a text block to strike-through text:

text = md.strike(" nice day!   ")
print text

# OUTPUT:  <s>nice day!</s>
ul(text)[source]

convert plain-text to MMD unordered list

Key Arguments:
  • text – the text to convert to MMD unordered list
Return:
  • ul – the MMD unordered list

Usage:

To convert text to a MMD unordered list:

ul = md.ul(" This is a list item   ")
print ul

# OUTPUT:
# *  This is a list item
#
underline(text)[source]

convert plain-text to HTML underline text

Key Arguments:
  • text – the text to convert to HTML underlined
Return:
  • text – the underlined text

Usage:

To convert a text block to underlined text:

text = md.underline(" nice day!   ")
print text

# OUTPUT:  <u>nice day!</u>
url(text)[source]

convert plain-text to MMD clickable URL

Key Arguments:
  • text – the text to convert to MMD clickable URL
Return:
  • text – the URL text

Usage:

To convert a text block to MMD clickable URL:

text = md.url(" http://www.google.com    ")
print text

# OUTPUT:  <http://www.google.com>