Giter VIP home page Giter VIP logo

Comments (4)

chrisjsewell avatar chrisjsewell commented on May 20, 2024 1

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.

hukkin avatar hukkin commented on May 20, 2024

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.

chrisjsewell avatar chrisjsewell commented on May 20, 2024

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.

hukkin avatar hukkin commented on May 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.