|
9 | 9 | 'repr_dict', 'is_listy', 'mapped', 'IterLen', 'ReindexCollection', 'get_source_link', 'truncstr', |
10 | 10 | 'sparkline', 'modify_exception', 'round_multiple', 'set_num_threads', 'join_path_file', 'autostart', |
11 | 11 | 'EventTimer', 'stringfmt_names', 'PartialFormatter', 'partial_format', 'utc2local', 'local2utc', 'trace', |
12 | | - 'modified_env', 'ContextManagers', 'shufflish', 'console_help'] |
| 12 | + 'modified_env', 'ContextManagers', 'shufflish', 'console_help', 'hl_md'] |
13 | 13 |
|
14 | 14 | # %% ../nbs/03_xtras.ipynb 2 |
15 | 15 | from .imports import * |
@@ -566,3 +566,13 @@ def console_help( |
566 | 566 | nm = S.bold.light_blue(e.name) |
567 | 567 | print(f'{nm:45}{e.load().__doc__}') |
568 | 568 |
|
| 569 | + |
| 570 | +# %% ../nbs/03_xtras.ipynb 159 |
| 571 | +def hl_md(s, lang='xml', show=True): |
| 572 | + "Syntax highlight `s` using `lang`." |
| 573 | + md = f'```{lang}\n{s}\n```' |
| 574 | + if not show: return md |
| 575 | + try: |
| 576 | + from IPython import display |
| 577 | + return display.Markdown(md) |
| 578 | + except ImportError: print(s) |
0 commit comments