Support {:l} and {:cmd} format fields
| 125 | |
| 126 | |
| 127 | class MarkdownFormatter(string.Formatter): |
| 128 | """Support {:l} and {:cmd} format fields""" |
| 129 | |
| 130 | in_jupyter: bool |
| 131 | |
| 132 | def __init__(self, in_jupyter: bool): |
| 133 | self.in_jupyter = in_jupyter |
| 134 | super().__init__() |
| 135 | |
| 136 | def format_field(self, value: t.Any, format_spec: str) -> t.Any: |
| 137 | if format_spec.endswith("l"): |
| 138 | if self.in_jupyter: |
| 139 | value = f"<a href='{value}' target='_blank'>here</a>" |
| 140 | else: |
| 141 | value = f"at {value}" |
| 142 | format_spec = format_spec[:-1] |
| 143 | elif format_spec.endswith("cmd"): |
| 144 | value = f"!{value}" if self.in_jupyter else value |
| 145 | format_spec = format_spec[:-3] |
| 146 | return super().format_field(value, format_spec) |
| 147 | |
| 148 | |
| 149 | def display_msg(text: str, **params: str): |