API overview¶
For the basic usage of Python-Markups, one should import some markup
class from markups
, create an instance of that class, and use
the convert()
method:
>>> import markups
>>> markup = markups.ReStructuredTextMarkup()
>>> markup.convert('*reStructuredText* test').get_document_body()
'<div class="document">\n<p><em>reStructuredText</em> test</p>\n</div>\n'
For advanced usage (like dynamically choosing the markup class), one may use one of the functions documented below.
Getting lists of available markups¶
-
markups.
get_all_markups
()¶ - Returns
list of all markups (both standard and custom ones)
- Return type
list of markup classes
-
markups.
get_available_markups
()¶ - Returns
list of all available markups (markups whose
available()
method returns True)- Return type
list of markup classes
Getting a specific markup¶
-
markups.
get_markup_for_file_name
(filename, return_class=False)¶ - Parameters
filename (str) – name of the file
return_class (bool) – if true, this function will return a class rather than an instance
- Returns
a markup with
file_extensions
attribute containing extension of filename, if found, otherwiseNone
>>> import markups >>> markup = markups.get_markup_for_file_name('foo.mkd') >>> markup.convert('**Test**').get_document_body() '<p><strong>Test</strong></p>\n' >>> markups.get_markup_for_file_name('bar.rst', return_class=True) <class 'markups.restructuredtext.ReStructuredTextMarkup'>
Configuration directory¶
Some markups can provide configuration files that the user may use to change the behavior.
These files are stored in a single configuration directory.
If XDG_CONFIG_HOME
is defined, then the configuration
directory is it. Otherwise, it is .config
subdirectory in
the user’s home directory.