Enable list or rules. (chainable) :param names: rule name or list of rule names to enable. :param ignoreInvalid: set `true` to ignore errors when rule not found. It will automatically find appropriate components, containing rules with given names. If rule not found,
(
self, names: str | Iterable[str], ignoreInvalid: bool = False
)
| 158 | return rules |
| 159 | |
| 160 | def enable( |
| 161 | self, names: str | Iterable[str], ignoreInvalid: bool = False |
| 162 | ) -> MarkdownIt: |
| 163 | """Enable list or rules. (chainable) |
| 164 | |
| 165 | :param names: rule name or list of rule names to enable. |
| 166 | :param ignoreInvalid: set `true` to ignore errors when rule not found. |
| 167 | |
| 168 | It will automatically find appropriate components, |
| 169 | containing rules with given names. If rule not found, and `ignoreInvalid` |
| 170 | not set - throws exception. |
| 171 | |
| 172 | Example:: |
| 173 | |
| 174 | md = MarkdownIt().enable(['sub', 'sup']).disable('smartquotes') |
| 175 | |
| 176 | """ |
| 177 | result = [] |
| 178 | |
| 179 | if isinstance(names, str): |
| 180 | names = [names] |
| 181 | |
| 182 | for chain in ["core", "block", "inline"]: |
| 183 | result.extend(self[chain].ruler.enable(names, True)) |
| 184 | result.extend(self.inline.ruler2.enable(names, True)) |
| 185 | |
| 186 | missed = [name for name in names if name not in result] |
| 187 | if missed and not ignoreInvalid: |
| 188 | raise ValueError(f"MarkdownIt. Failed to enable unknown rule(s): {missed}") |
| 189 | |
| 190 | return self |
| 191 | |
| 192 | def disable( |
| 193 | self, names: str | Iterable[str], ignoreInvalid: bool = False |