Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions | Variables
admonitions Namespace Reference

Functions

str convert_admonitions (str content)
 

Variables

dict _RECOGNIZED_ADMONITIONS
 

Detailed Description

Preprocesses Markdown source and converts admonitions written in blockquotes.

Usage: convert_admonitions(str)

Function Documentation

◆ convert_admonitions()

str admonitions.convert_admonitions ( str  content)
Convert blockquotes into admonitions if they start with a marker.

   Blockquotes starting with  `> **marker**` are converted either into
   sidenotes (`<span class="aside"/>`) or into admonitions to be
   processed by an admonition extension later.

Definition at line 19 of file admonitions.py.

19def convert_admonitions(content: str) -> str:
20 """Convert blockquotes into admonitions if they start with a marker.
21
22 Blockquotes starting with `> **marker**` are converted either into
23 sidenotes (`<span class="aside"/>`) or into admonitions to be
24 processed by an admonition extension later.
25 """
26 processed = []
27 current_admonition = None
28 indent = ''
29 for line in content.split('\n'):
30 if current_admonition is not None:
31 if line.startswith('>'):
32 processed.append(indent + line[1:])
33 continue
34 if current_admonition == 'Note':
35 note = processed.pop()
36 processed.pop()
37 processed[-1] = processed[
38 -1] + f' <span class="aside" markdown=1>{note}</span>'
39 current_admonition = None
40 elif line.startswith('> **') and line.endswith('**'):
41 current_admonition = re.match(r'^> \*\*(.*)\*\*$', line)[1]
42 if current_admonition == 'Note':
43 indent = ''
44
45 # Drop all empy lines preceeding the side note.
46 while processed[-1] == '':
47 processed.pop()
48
49 # Do not try to attach sidenote to the section title.
50 if processed[-1].startswith('#'):
51 processed.append('')
52 else:
53 # Start an admonition using Python markdown syntax.
54 processed.append(
55 f'!!! {_RECOGNIZED_ADMONITIONS[current_admonition]} "{current_admonition}"'
56 )
57 current_admonition = True
58 indent = ' '
59 continue
60 processed.append(line)
61 return "\n".join(processed)

Variable Documentation

◆ _RECOGNIZED_ADMONITIONS

dict admonitions._RECOGNIZED_ADMONITIONS
protected
Initial value:
1= {
2 "Source to read": "sourcecode",
3 "Trying it": "tryit",
4 "Warning": "warning"
5}

Definition at line 12 of file admonitions.py.