API Reference
klartext.token
Module defining a token.
Token
A Token used while parsing the klartext language.
__init__(indent, type, content)
Creates a token.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
indent
|
int
|
The level of indentation of the token |
required |
type
|
str
|
The type of token |
required |
content
|
Any
|
Additional content depending on the type of token |
required |
content()
Get the content of the token.
Returns:
Type | Description |
---|---|
Any
|
Additional content depending on the type of token |
indent()
Get the level of indent.
Returns:
Type | Description |
---|---|
int
|
The level of indentation of the token |
type()
Get the type of token.
Returns:
Type | Description |
---|---|
str
|
The type of the token |
klartext.exceptions
Module providing exceptions.
ParseError
Bases: Exception
Indicates a parse error.
This exception is thrown whenever the parser encounters a problem with the syntax of the parsed text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message
|
str
|
A message describing the cause of the exception. |
required |
token
|
Token | None
|
The token that triggered the exception. |
None
|
klartext.parser
Module providing a parser for the klartext markup language.
Parser
Parser for the klartext markup language.
__init__()
Creates a parser.
convertMarkdown(text)
staticmethod
Markdown conversion for text content.
Converts the text content from Markdown to xhtml.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
The text content |
required |
Returns:
Type | Description |
---|---|
str
|
The text content converted from Markdown to xhtml |
lookupIncludeFile(filename, basedir)
staticmethod
Default lookup for include files.
Tries to locate the include file relative to the basedir.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
Name of the include file to lookup |
required |
basedir
|
str
|
Base directory for the lookup |
required |
parse(infile, convert_text=removeSurroundingBlankLines, basedir='', lookup=lookupIncludeFile)
Parse a klartext file.
Parses a klartext file and returns an XML representation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
infile
|
TextIOBase
|
The text file to parse |
required |
convert_text
|
Callable[[str], str]
|
Callback function to convert the content of text nodes |
removeSurroundingBlankLines
|
basedir
|
str
|
Directory used as base when looking up included files |
''
|
lookup
|
Callable[[str, str], str]
|
Callback function used to lookup include files |
lookupIncludeFile
|
Returns:
Type | Description |
---|---|
bytes
|
UTF-8 enoded byte string containing the XML representation of the klartext file |
removeSurroundingBlankLines(text)
staticmethod
Default conversion for text content.
Removes leading and trailing blank lines from text content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
The text content |
required |
Returns:
Type | Description |
---|---|
str
|
The text content without leading and trailing blank lines |
klartext.inline
Module providing the inline tags extension for Markdown.
InlineTagsExtension
Bases: Extension
Extension for inline tags.
Extends Markdown with the concept of inline tags.
Example
The input:
This is /em/some/ markup.
will be converted to:
This is <em>some</em> markup.
klartext.glossary
Module providing the glossary extension for Markdown.
GlossaryExtension
Bases: Extension
Extension for marking glossary entries.
Extends Markdown with a simple method to mark glossary entries.
Example
The input:
This is {Markdown} markup.
will be converted to:
This is <a data-type="xref" data-xrefstyle="glossary" href="#markdown">Markdown</a>.