Comments (9)
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.
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.
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.
You can try the new --diff
option from the dev
branch. Let me know if it works
from md-toc.
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.
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.
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.
Thank you!
from md-toc.
Done, check version 8.2.0
from md-toc.
Related Issues (20)
- CommonMark Spec 0.29 is out HOT 1
- Ordered TOC doesn't work HOT 6
- Title with trailing spaces HOT 1
- I get thi serror after `pip install md-toc` HOT 4
- Allow "1." only ordered TOC lists output HOT 10
- Feature Request: Automatically skip lines to first or (N) TOC HOT 1
- Links not working when some styling is used in the header on GitHub HOT 5
- multiple hyphens in anchor links for GitLab Flavored Markdown
- Probably wrong license declaration HOT 3
- Redcarpet v3.5.1 is out
- Feature request: Support MD in argument instead of file HOT 4
- Commonmark 0.30 is out HOT 1
- Incorrect Type Annotation for `build_anchor_link` Function
- Line Endings Are Always CRLF on Windows HOT 4
- Consider Mentioning Existence of GitHub's Built-In Markdown Table of Contents HOT 4
- Is it possible to ignore certain headers? HOT 2
- Invalid Cross-device Link HOT 8
- Irregular jumps in heading size not being recognized HOT 4
- IndexError: list index out of range HOT 5
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 md-toc.