Markdown

Unicode UTF-8 code points of characters that play a special role: LF, #, , … , and so on. Note for Windows users: the CRLF EOL is not taken into account. Please switch to LF.

markdowntolatex.markdown.encoding.ASTERISK = 42

*, code point: U+002A.

markdowntolatex.markdown.encoding.BACKSLASH = 92

\, code point: U+005C.

markdowntolatex.markdown.encoding.DOLLAR = 36

$, code point: U+0024.

markdowntolatex.markdown.encoding.HASH = 35

#, code point: U+0023.

markdowntolatex.markdown.encoding.LATEX_BACKSLASH = [92, 98, 97, 99, 107, 115, 108, 97, 115, 104]

backslah = (\, b, a, c, k, s, l, a, s, h)

markdowntolatex.markdown.encoding.LATEX_NEWLINE = [92, 92]

newline = (\, \)

markdowntolatex.markdown.encoding.LF = 10

LF, code point: U+000A.

markdowntolatex.markdown.encoding.SPACE = 32

‘ ‘ , code point: U+0020.

markdowntolatex.markdown.encoding.SPECIAL_CHARACTERS = {10, 32, 35}

LF, hash, space are the special characters.

markdowntolatex.markdown.encoding.UNDERSCORE = 95

_,code point: U+005F.

The Markdown parser.

class markdowntolatex.markdown.parser.Parser(dialect='Github')
interpret(read)

The automaton that rules the markdown parsing.

Parameters:

read – the currently read character, as an int.

Type:

int

Raise:

ValueError iff read is not a legal code point.

TODO: Define the legal range for code points. TODO: Implement ValueError.

is_count_even(key)
Param:

key, a key for the dictionary count.

Type:

str

Returns:

True iff self.count[key] is an even interger.

Return type:

Boolean

Raise:

TypeError iff self.count[key] is not an integer.

TODO: Implement exceptions management.

is_count_odd(key)
Param:

key, a key for the dictionary count.

Type:

str

Returns:

True iff self.count[key] is an odd interger.

Return type:

Boolean

Raise:

TypeError iff self.count[key] is not an integer.

TODO: Implement exceptions management.

is_count_positive(key)
Param:

key, a key for the dictionary count.

Type:

str

Returns:

True iff self.count[key] is positive.

Return type:

Boolean

Raise:

TypeError iff self.count[key] is not an integer.

TODO: Implement exceptions management.

is_count_positive_even(key)
Param:

key, a key for the dictionary count.

Type:

str

Returns:

True iff self.count[key] is positive even.

Return type:

Boolean

Raise:

TypeError iff self.count[key] is not an integer.

TODO: Implement exceptions management.

is_count_positive_odd(key)
Param:

key, a key for the dictionary count.

Type:

str

Returns:

True iff self.count[key] is positive even.

Return type:

Boolean

Raise:

TypeError iff self.count[key] is not an integer.

TODO: Implement exceptions management.

static is_regular_character(read)

A character is a regular character iff it is not a special character.

static latex(command, card=1, line_break=False)

Given a LaTex command command and a cardinality card, returns the sequence command + … + command (card time(s)).

Optionally, appends n (n = 0, 1, 2, …) line break(s) at the end of the sequence iff ‘line_break’ is set to n.

Note that (1) line_break=True means line_break=1, (2) line_break=False means line_break=0.

TODO: Exceptions (card) :param command: plain text that denotes a LaTeX command (“backslash”, “newline”, …). :param card: the number of times command is repeated. :type card: int :param line_break: Appended line break(s). :type line_break: int :return: A LaTeX command, as a list of code points. :rtype: list

reset_count(key)

Resets self.count[key] to 0.

Param:

key a key for the dictionary count.

Type:

str

Raise:

KeyError iff key is not a key for count.

set_count(key, n)
set_level(level)

the inner level is updated with respect to the given value of level.

set_state(state)

state is assigned the value of state.

update_count(key, n=1)

Given a counting number n=1, 2, 3, …, @increases self.count[key] by n.

Param:

key, a key for the dictionary count.

Type:

str

Param:

n the value that adds to self.count[key].

Type:

int

Raise:

KeyError iff key is not a key for count.

Raise:

TypeError iff n is not an integer

Raise:

ValueError iff n is not a positive integer.

update_heading(read, head=None, prefix=None, tail=None, suffix=None)

Given read*, updates the heading.

Parameters:
  • read (int) – The read character.

  • prefix (list) – An optional prefix

  • tail (list) – An optional tail

  • suffix (list) – An optional suffix (if no tail)

update_mode(mode=None)

Sets self.mode to mode.

Param:

mode, a mode identifier.

Type:

str

Raise:

ValueError iff mode is not a legal mode.

TODO: Implement exceptions management.

update_text(read, head=None, prefix=None, tail=None, suffix=None)

Given read*, updates the text.

Parameters:
  • read (int) – The read character.

  • prefix (list) – An optional prefix

  • tail (list) – An optional tail

  • suffix (list) – An optional suffix (if no tail)

Updates the (core) text that will be injected into the LaTeX code source.

update_tree()

Updates the current tree by appending a node at the upper right extremity. If the tree does not exist yet, the node becomes the tree.

class markdowntolatex.markdown.tree.Tree(height, level)

Tree is the tree

Parameters:
  • height (int) – The tree’s height at instantiation. Positive integer.

  • level – The tree’s level at instantiation. Positive integer.

  • type – int

TODO: Exceptions

add_branch(level, subtree)

Adds branch (a “subtree”) to self.tree.

The height of the tree is updated accordingly.

find_diagonal_up()

Find the upper diagonal element and returns it.

Returns:

The subtree (should be a Node)

Return type:

Tree

TODO: Warning if diagonal element is not a Node

get_level_max()

return: level_max (see mathsheet)

to_string(arg, whitespaces=True)

TODO: !

update_diagonal(subtree)

TODO: Compare with add_branch.

update_heading(read)

updates the curent heading with read.

update_text(read)

updates the curent text heading with read.