Comments (4)
Yeh I agree these things should probably default to success, but it would be nice to (optionally) get some kind of warning.
maybe make this a bit less "hardcoded" than directly printing to stderr, by doing something like:
try:
code_block = fmt_func(code_block, info_str)
except Exception:
# Swallow exceptions so that formatter errors (e.g. due to
# invalid code) do not crash mdformat.
options["mdformat_logger"].warn("some message")
this is probably not the ideal solution, but you get the idea
from mdformat.
I was also unsure (and still am) what the best default here is. I made mdformat swallow code formatter exceptions for now, since I feel like it might be quite common to write broken code in Markdown code blocks, e.g.
here's broken json in a markdown code block
```json
{
"item1": 1,
"item2": 2,
...
}
```
I'm not sure if this assumption is valid though, and for my own use, I'd be happy with mdformat returning a non-zero error code if a code formatter raises. If there's two schools of thought here I'd happily merge a CLI arg to change this behavior.
At a minimum, I think the errors should be logged
Agreed.
Another place where reporting/failing should be considered, is when duplicate_refs are found in the env (after parsing)
What do you mean by duplicate_refs? Is this something that happens (and should error) in markdown-it-py
perhaps?
from mdformat.
yeh good point about writing broken code, I think then failure should be optional via a CLI arg 👍
What do you mean by duplicate_refs?
See https://github.com/executablebooks/markdown-it-py/blob/c3247296415c69cb3083376a78c56e4da8249815/markdown_it/rules_block/reference.py#L197, if you write:
[a]: href1
[a]: href2
The 2nd one will be stored in duplicate_refs
.
It is the renderers job to decide if it/how they want to act on these duplicates (for example in myst-parser a warning is sent to the Sphinx error reporter)
from mdformat.
Ah gotcha.
I'm now thinking since mdformat is a formatter, not a validator, if there is a problem that can't be fixed by formatting, then the exit code should probably by default always be success (this goes for "invalid" code block contents). We could consider printing a warning to stderr though.
When it comes to duplicate_refs
, if i understand correctly, that is something that mdformat can fix, by simply only rendering the first ref (with the assumption that rendering ref links is supported, currently isn't). So I feel like no warnings or anything should be needed.
from mdformat.
Related Issues (20)
- Incorrect behaviour with `<br>` or `<br/>` HOT 7
- Consider respecting gfm checklists HOT 1
- Support for Front Matter with Markdown page metadata HOT 1
- `--wrap n` should respect tables HOT 2
- Escape "\|" not working in table cell HOT 3
- Support XGG base directory specification for user configuration resolution
- Checkboxes are escaped HOT 3
- mdformat breaks Hugo shortcodes by escaping `<` HOT 5
- markdown-it-py 3 support
- Not Working In Python 3.11? HOT 5
- Error: Could not format HOT 2
- Alt text wrapped in grave marks is deleted HOT 2
- Formatted md renders different html than original md HOT 2
- image path is falsely patched with `<>` if URL includes `()`, breaks render HOT 5
- Double slash in math formular HOT 3
- Incorrecly reformats python code HOT 1
- convert inline links to references? HOT 2
- Support json schema
- Word-wrap on sentence (punctuation) and width. HOT 1
- Inline elements in image descriptions are flattened and stripped HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mdformat.