|
10 | 10 | 'detect_mime', 'bunzip', 'loads', 'loads_multi', 'dumps', 'untar_dir', 'repo_details', 'shell', 'ssh', |
11 | 11 | 'rsync_multi', 'run', 'open_file', 'save_pickle', 'load_pickle', 'parse_env', 'expand_wildcards', |
12 | 12 | 'atomic_save', 'dict2obj', 'obj2dict', 'repr_dict', 'is_listy', 'mapped', 'IterLen', 'ReindexCollection', |
13 | | - 'SaveReturn', 'trim_wraps', 'save_iter', 'asave_iter', 'clean_cli_output', 'unqid', 'rtoken_hex', |
14 | | - 'friendly_name', 'n_friendly_names', 'exec_eval', 'get_source_link', 'sparkline', 'modify_exception', |
15 | | - 'round_multiple', 'set_num_threads', 'join_path_file', 'autostart', 'EventTimer', 'stringfmt_names', |
16 | | - 'PartialFormatter', 'partial_format', 'truncstr', 'utc2local', 'local2utc', 'trace', 'modified_env', |
17 | | - 'ContextManagers', 'shufflish', 'console_help', 'hl_md', 'type2str', 'dataclass_src', 'Unset', 'nullable_dc', |
18 | | - 'make_nullable', 'flexiclass', 'asdict', 'vars_pub', 'is_typeddict', 'is_namedtuple', 'CachedIter', |
19 | | - 'CachedAwaitable', 'reawaitable', 'is_async_callable', 'maybe_await', 'noopa', 'flexicache', 'time_policy', |
20 | | - 'mtime_policy', 'timed_cache'] |
| 13 | + 'SaveReturn', 'trim_wraps', 'save_iter', 'asave_iter', 'frontmatter', 'clean_cli_output', 'unqid', |
| 14 | + 'rtoken_hex', 'friendly_name', 'n_friendly_names', 'exec_eval', 'get_source_link', 'sparkline', |
| 15 | + 'modify_exception', 'round_multiple', 'set_num_threads', 'join_path_file', 'autostart', 'EventTimer', |
| 16 | + 'stringfmt_names', 'PartialFormatter', 'partial_format', 'truncstr', 'utc2local', 'local2utc', 'trace', |
| 17 | + 'modified_env', 'ContextManagers', 'shufflish', 'console_help', 'hl_md', 'type2str', 'dataclass_src', |
| 18 | + 'Unset', 'nullable_dc', 'make_nullable', 'flexiclass', 'asdict', 'vars_pub', 'is_typeddict', 'is_namedtuple', |
| 19 | + 'CachedIter', 'CachedAwaitable', 'reawaitable', 'is_async_callable', 'maybe_await', 'noopa', 'flexicache', |
| 20 | + 'time_policy', 'mtime_policy', 'timed_cache'] |
21 | 21 |
|
22 | 22 | # %% ../nbs/03_xtras.ipynb #3401d507 |
23 | 23 | from .imports import * |
@@ -596,6 +596,17 @@ def asave_iter(g): |
596 | 596 | def _(*args, **kwargs): return _save_iter(g, *args, **kwargs) |
597 | 597 | return _ |
598 | 598 |
|
| 599 | +# %% ../nbs/03_xtras.ipynb #20e906c7 |
| 600 | +def frontmatter(txt:str)->dict: |
| 601 | + "Dict contained in frontmatter in `txt`, if present" |
| 602 | + import yaml |
| 603 | + if not txt.startswith('---\n'): return {} |
| 604 | + fm,part,_ = txt[4:].partition('\n---\n') |
| 605 | + if not part: return {} |
| 606 | + try: res = yaml.safe_load(fm) |
| 607 | + except yaml.parser.ParserError: return {} |
| 608 | + return res if isinstance(res,dict) else {} |
| 609 | + |
599 | 610 | # %% ../nbs/03_xtras.ipynb #45eb5141 |
600 | 611 | def clean_cli_output(txt:str, strip:bool=True): |
601 | 612 | "Clean CLI output by handling alternate screen, carriage returns, and ANSI escapes" |
|
0 commit comments