- Notifications
You must be signed in to change notification settings - Fork 84
👌 IMPROVE: MarkdownIt config and documentation #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add additional configuration presets, allow for options tp be overriden in the `MarkdownIt` initialisation, Add convenience methods to `SyntaxTreeNode`
Codecov Report
@@ Coverage Diff @@ ## master #136 +/- ## ========================================== + Coverage 96.16% 96.27% +0.10% ========================================== Files 72 72 Lines 3107 3141 +34 ========================================== + Hits 2988 3024 +36 + Misses 119 117 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
| @hukkinj1 I'm keeping commonmark as the default, but have added the option override and some other presets |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👍 , here's my notes!
| def __repr__(self) -> str: | ||
| return f"{self.__class__.__name__}({self.type})" | ||
| | ||
| def __getitem__(self, item: int) -> "SyntaxTreeNode": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally favor having just one way to do things, and would prefer the more explicit .children[i] syntax. Don't feel too strongly about that though.
If we keep this though, we might want to improve type annotations. item can be a slice in addition to int and return type will change accordingly too. An @overload is probably needed.
The return type will also break if subclassed. Merging #131 and changing the type to _T (and annotating self as _T) should fix this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeh exactly, I was going to leave this type annotation stuff to the other PR
| return tokens | ||
| | ||
| @property | ||
| def is_root(self) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use self.is_root inside def type() definition to remove duplication.
| ) | ||
| child._set_children_from_tokens(nested_tokens[1:-1]) | ||
| | ||
| def pretty( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we print closing tags or add the slash character to make the tags self-closing if there's no content? That would make the output more or less valid XML and wouldn't confuse highlighters, parsers etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not adding closing tags as the indentation denotes the nesting and this would make it overly verbose and less readable (which is the main point of this function). I could add self-closing, but TBH the highlighting below in tests/test_tree/test_pretty.xml seems to be fine
| > a *quote* | ||
| """) | ||
| node = SyntaxTreeNode.from_tokens(tokens) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a heads-up, I made a PR (#132) which would change this syntax to node = SyntaxTreeNode(tokens) so if we merge that then one of the PRs needs to adapt depending on merge order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have a look
markdown_it/main.py Outdated
| _PRESETS["js-default"] = _PRESETS["default"] | ||
| _PRESETS["gfm-like"] = presets.default.make() | ||
| _PRESETS["gfm-like"]["options"]["linkify"] = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make these new presets public in markdown_it.presets package like the original ones are? That enables a workflow where you fetch a preset from there, mutate it, and pass it on to .configure()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in bc3a2ef
| self, config: Union[str, Mapping] = "commonmark", renderer_cls=RendererHTML | ||
| self, | ||
| config: Union[str, Mapping] = "commonmark", | ||
| options_update: Optional[Mapping] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One neat trick I've recently started to use in my APIs is
from types import MappingProxyType # This is basically just an immutable empty mapping EMPTY_MAP = MappingProxyType({}) def func(options: Mapping = EMPTY_MAP): ...This convention saves me a bunch of Optional annotations and None handling, and avoids the dangerous default problem.
Could be applied here if you like it 😄 You basically just need to create one global EMPTY_MAP instance per project and can reuse it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the tip, I will have a look but probably not add it in this PR
Co-authored-by: Taneli Hukkinen <hukkinj1@users.noreply.github.com>
Add additional configuration presets,
allow for options tp be overriden in the
MarkdownItinitialisation,Add convenience methods to
SyntaxTreeNode