md_writer
trestle.core.markdown.md_writer
¤
Create formatted markdown files with optional yaml header.
Attributes¤
logger = logging.getLogger(__name__)
module-attribute
¤
Classes¤
MDWriter
¤
Simple class to create markdown files.
Source code in trestle/core/markdown/md_writer.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
Functions¤
__init__(file_path, header_comments_dict=None)
¤
Initialize the class.
Source code in trestle/core/markdown/md_writer.py
34 35 36 37 38 39 40 41 |
|
add_yaml_header(header)
¤
Add the yaml header.
Source code in trestle/core/markdown/md_writer.py
59 60 61 |
|
cull_headings(md_in, cull_list, strict_match=False)
¤
Cull headers from the lines of input markdown file with optional strict string match.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
md_in
|
Path
|
the path of the markdown file being edited |
required |
cull_list
|
List[str]
|
the list of strings in headers that are to be culled |
required |
strict_match
|
bool
|
whether to require an exact string match on header key or just a substring |
False
|
Returns None and creates new markdown at the path specified during MDWriter construction It is allowed to overwrite the original file
Source code in trestle/core/markdown/md_writer.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
exists()
¤
Check if the file already exists.
Source code in trestle/core/markdown/md_writer.py
55 56 57 |
|
get_lines()
¤
Return the current lines in the file.
Source code in trestle/core/markdown/md_writer.py
167 168 169 |
|
get_text()
¤
Get the text as currently written.
Source code in trestle/core/markdown/md_writer.py
171 172 173 |
|
new_header(level, title, add_new_line_after_header=True)
¤
Add new header.
Source code in trestle/core/markdown/md_writer.py
94 95 96 97 98 99 100 |
|
new_hr()
¤
Add horizontal rule.
Source code in trestle/core/markdown/md_writer.py
102 103 104 105 106 |
|
new_line(line)
¤
Add a line of text to the output.
Source code in trestle/core/markdown/md_writer.py
77 78 79 80 81 82 83 |
|
new_list(list_)
¤
Add a list to the markdown.
Source code in trestle/core/markdown/md_writer.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
new_paragraph()
¤
Start a new paragraph.
Source code in trestle/core/markdown/md_writer.py
90 91 92 |
|
new_paraline(line)
¤
Add a paragraph and a line to output.
Source code in trestle/core/markdown/md_writer.py
85 86 87 88 |
|
new_table(table_list, header)
¤
Add table to the markdown. All rows must be of equal length.
Source code in trestle/core/markdown/md_writer.py
127 128 129 130 131 132 133 134 135 |
|
set_indent_level(level)
¤
Set the current indent level.
Source code in trestle/core/markdown/md_writer.py
63 64 65 |
|
set_indent_step_size(size)
¤
Set the indent step size in spaces.
Source code in trestle/core/markdown/md_writer.py
67 68 69 |
|
write_out()
¤
Write out the markdown file.
Source code in trestle/core/markdown/md_writer.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
|
Functions¤
handler: python