ddocs.markdown¶
Core Markdown-to-LaTeX conversion logic plus the Deltares-specific
post-processing (UTF-8 tree-character replacement, table column-width fixes, and
long-word wrapping in tables). The clean command logic now lives in
ddocs.latex.clean.
ddocs.markdown ¶
Convert Markdown documentation to LaTeX (Pandoc + Deltares post-processing).
convert_all_markdown_files ¶
convert_all_markdown_files(input_dir: Path, output_dir: Path, template: Path | None = None, standalone: bool = False, pattern: str = '*.md') -> tuple[int, int]
Convert all Markdown files in a directory to LaTeX.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dir
|
Path
|
Directory containing Markdown files |
required |
output_dir
|
Path
|
Directory for output LaTeX files |
required |
template
|
Path | None
|
Optional custom Pandoc template |
None
|
standalone
|
bool
|
If True, generate complete LaTeX documents |
False
|
pattern
|
str
|
Glob pattern for matching files (default: "*.md") |
'*.md'
|
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
Tuple of (successful_conversions, total_files) |
Source code in src\ddocs\markdown\markdown.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
convert_markdown_to_latex ¶
convert_markdown_to_latex(input_file: Path, output_file: Path, template: Path | None = None, standalone: bool = False) -> bool
Convert a Markdown file to LaTeX using Pandoc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_file
|
Path
|
Path to input Markdown file |
required |
output_file
|
Path
|
Path to output LaTeX file |
required |
template
|
Path | None
|
Optional custom Pandoc template |
None
|
standalone
|
bool
|
If True, generate a complete LaTeX document. If False, generate a fragment that can be included. |
False
|
Returns:
| Type | Description |
|---|---|
bool
|
True if conversion succeeded, False otherwise |
Source code in src\ddocs\markdown\markdown.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | |
fix_table_column_widths ¶
fix_table_column_widths(content: str) -> str
Fix LaTeX table column widths for better formatting.
Looks for tables and analyzes content to adjust column widths to prevent overlap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str
|
LaTeX content string |
required |
Returns:
| Type | Description |
|---|---|
str
|
Content with adjusted table column widths |
Source code in src\ddocs\markdown\markdown.py
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 | |
replace_utf8_tree_chars ¶
replace_utf8_tree_chars(content: str) -> str
Replace UTF-8 box-drawing characters and symbols with LaTeX equivalents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str
|
LaTeX content string |
required |
Returns:
| Type | Description |
|---|---|
str
|
Content with UTF-8 characters replaced |
Source code in src\ddocs\markdown\markdown.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 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 | |
wrap_long_words_in_tables ¶
wrap_long_words_in_tables(content: str) -> str
Wrap very long words in table cells with seqsplit for automatic breaking.
This prevents long words from overflowing table columns by allowing them to break at any character position.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str
|
LaTeX content string |
required |
Returns:
| Type | Description |
|---|---|
str
|
Content with long words wrapped in seqsplit |
Source code in src\ddocs\markdown\markdown.py
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 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
check_pandoc_cli ¶
check_pandoc_cli(args: Namespace | None = None) -> int
CLI handler for the check-pandoc command.
Ensures pandoc is available (downloading it if necessary) and maps the
result to a process exit code suitable for sys.exit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
args
|
Namespace | None
|
Parsed CLI arguments from argparse. Unused -- accepted only so the
handler matches the calling convention of the other |
None
|
Returns:
| Type | Description |
|---|---|
int
|
0 if pandoc is accessible, 1 otherwise. |
Examples:
- Run the check and use the result as a process exit code:
>>> import sys >>> from ddocs.markdown.pandoc_utils import check_pandoc_cli >>> exit_code = check_pandoc_cli() # doctest: +SKIP >>> exit_code # doctest: +SKIP 0 - The argparse namespace is accepted but ignored:
>>> import argparse >>> from ddocs.markdown.pandoc_utils import check_pandoc_cli >>> ns = argparse.Namespace(command="check-pandoc") >>> check_pandoc_cli(ns) # doctest: +SKIP 0
See Also
check_pandoc_installed: The underlying check-and-install routine.
Source code in src\ddocs\markdown\pandoc_utils.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
check_pandoc_installed ¶
check_pandoc_installed() -> bool
Ensure pandoc is callable from the command line.
If pandoc is already on PATH this returns immediately. Otherwise the pandoc
binary bundled with pypandoc-binary is located and its directory is prepended
to this process's PATH so the binary (and any subprocess spawned from this
process) can invoke pandoc directly. No network download happens; the PATH
change affects only the current process, not the parent shell.
Returns:
| Type | Description |
|---|---|
bool
|
True if pandoc is accessible after the call, False if the bundled binary |
bool
|
could not be located on |
Examples:
- Guard a conversion step on pandoc being available:
>>> from ddocs.markdown.pandoc_utils import check_pandoc_installed >>> if check_pandoc_installed(): # doctest: +SKIP ... print("converting") converting - Abort early when pandoc cannot be made available:
>>> from ddocs.markdown.pandoc_utils import check_pandoc_installed >>> ready = check_pandoc_installed() # doctest: +SKIP >>> ready or "could not install pandoc" # doctest: +SKIP True
See Also
sanity_check: The PATH-only check this function builds on. check_pandoc_cli: Thin wrapper that maps the result to an exit code.
Source code in src\ddocs\markdown\pandoc_utils.py
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 | |
sanity_check ¶
sanity_check() -> bool
Check whether a pandoc executable is callable from the command line.
Runs pandoc --version as a subprocess. On success the detected version is
printed and True is returned; if pandoc is missing from PATH or the
call fails, False is returned. This only inspects what is already
reachable -- it never downloads or installs anything.
Returns:
| Type | Description |
|---|---|
bool
|
True if |
Examples:
- Branch on whether pandoc is available:
>>> from ddocs.markdown.pandoc_utils import sanity_check >>> if sanity_check(): # doctest: +SKIP ... print("ready to convert") ... else: ... print("pandoc missing") ready to convert - Use the boolean result to pick a fallback message:
>>> from ddocs.markdown.pandoc_utils import sanity_check >>> available = sanity_check() # doctest: +SKIP >>> "ok" if available else "install pandoc first" # doctest: +SKIP 'ok'
See Also
check_pandoc_installed: Verify pandoc and download it when it is missing.
Source code in src\ddocs\markdown\pandoc_utils.py
20 21 22 23 24 25 26 27 28 29 30 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 | |