Is there a CommonMark Tidy? [answer: kinda]

I am a project maintainer. I want to enforce common syntax rules for writers (e.g. consistent choice of header syntax, always wrap at 72 characters) so that our text files are not just valid CommonMark, but also have a consistent visual style for human readers and plaintext renderers.

I don’t mind using someone else’s style guide. (Although word-wrap / right-margin might need to be something I define.)

My understanding is that the CommonMark project is currently defining a specification and reference CommonMark-to-HTML renderers. Do any of the current tools include a linter (reports invalid markup) or ideally a tidier (fixes invalid markup, where possible)?

So far the only tool I’ve found in any language is https://www.npmjs.com/package/tidy-markdown which doesn’t guarantee CommonMark validity. It follows this styleguide: https://github.com/slang800/markdown-styleguide (includes table markup).

1 Like

There isn’t a linting tool or tidier that I’m aware of. There has been some discussion around creating a style guide in this topic though. Perhaps a configurable linting tool would be best, then people could define their own style guides that use it.

2 Likes

You can do a commonmark -> commonmark translation with cmark, and the result should be semantically equivalent, but the changes may be more than you’d expect in a linter.

See the discussion of “lossless ASTs” here:
https://talk.commonmark.org/t/should-there-be-additional-information-in-the-ast/?source_topic_id=2464

1 Like

How does cmark decide which styles to use? Perhaps we could create a style guide based on it’s behaviour.

1 Like