Git Product home page Git Product logo

Comments (9)

frnmst avatar frnmst commented on May 28, 2024

I'm not sure what you are trying to achieve, but correct me if I'm wrong:

  • you are using md-toc's pre-commit hook
  • the platform you are running pre-commit on does not support file changing in place
  • md-toc returns an exit code != 0 only in the case if something goes wrong. If you don't pass the -p options then md-toc will print the TOC to the stdout, and it will return 0. Since you can't use -p, you need some other way to replace the old TOC in the markdown file
  • since the markdown file needs to be changed, you need that the pre-commit pipeline fails. This won't happen by simply removing the -p option...

You didn't mention the platform(s), but I think the easiest thing to do is reading some environment variable specific to that/those platform: if the environment variable(s) is detected then md-toc must exit with something != 0

from md-toc.

jsh9 avatar jsh9 commented on May 28, 2024

Is there a way to check whether the ToC would have been changed without actually changing the ToC?

If so, I can put md-toc in tox (no changing the ToC) as well as in pre-commit (apply changes to ToC if necessary).

Thanks!

from md-toc.

frnmst avatar frnmst commented on May 28, 2024

OK, so you want something like this?

old_toc = get_toc(file)
new_toc = build_toc(file)
if '--diff' and old_toc != new_toc:
    print(new_toc)
    sys.exit(128)
else:
    print(new_toc)
    sys.exit(0)

from md-toc.

frnmst avatar frnmst commented on May 28, 2024

You can try the new --diff option from the dev branch. Let me know if it works

from md-toc.

jsh9 avatar jsh9 commented on May 28, 2024

Hi @frnmst , it works perfectly! Thank you!

I'm using md-toc in pre-commit for auto-formatting locally. And then I'm adding a md-toc step in tox.ini (with --diff) just for the CI pipeline.

from md-toc.

jsh9 avatar jsh9 commented on May 28, 2024

Hi @frnmst , here's a follow-up question: do you plan to add this functionality to the latest release any time soon? Thanks!

from md-toc.

frnmst avatar frnmst commented on May 28, 2024

Hi @jsh9 this new feature needs a cleanup and the usual unit tests. It is scheduled to be released for version 8.2.0. See the changelog.

from md-toc.

jsh9 avatar jsh9 commented on May 28, 2024

Thank you!

from md-toc.

frnmst avatar frnmst commented on May 28, 2024

Done, check version 8.2.0

from md-toc.

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.