Crates.io | fmtm |
lib.rs | fmtm |
version | 0.0.3 |
source | src |
created_at | 2024-05-27 09:28:30.930946 |
updated_at | 2024-09-03 01:07:54.964743 |
description | A diff-friendly Markdown formatter that breaks lines on sensible punctuations and words to fit a line width. |
homepage | |
repository | https://github.com/SichangHe/fmtm |
max_upload_size | |
id | 1253217 |
size | 94,369 |
A diff-friendly Markdown formatter that breaks lines on sensible punctuations and words to fit a line width.
This is more useful to use with Git than formatters like Prettier because the formatting is more consistent, resulting in smaller diffs.
FMTM uses FMTT to format Markdown paragraphs:
.
, then,
, then(
, and finallyand
.FMTM preserves code blocks, and trims leading spaces to a multiple of 4 for display math and HTML blocks.
cargo install fmtm
$ fmtm --help
ForMaT Markdown diff-friendly,
breaking lines on sensible punctuations and words to fit a line width.
Like FMTT,
FMTM formats its input to have lines shorter than the line width limit
(if possible).
It reads an input file or StdIn and prints the formatted text to StdOut.
Like FMTT, FMTM only preserves leading spaces, not tabs.
Usage: fmtm [OPTIONS]
Options:
-w, --line-width <LINE_WIDTH>
Maximum line width limit. Preserve line lengths if set to 0.
[default: 80]
-f, --filename <FILENAME>
Name of input file; if omitted, read from StdIn.
-c, --change-in-place
If input file is provided, write output to it.
-e, --emphasis-marker <EMPHASIS_MARKER>
Marker for emphasis spans, or preserve the input if set to "".
[default: *]
-s, --strong-marker <STRONG_MARKER>
Marker for strong spans, or preserve the input if set to "".
[default: **]
-i, --indentation <INDENTATION>
Fixed indentation string,
or calculate to align the beginning of content text in each list if set to "".
[default: " "]
-h, --help
Print help (see a summary with '-h')
-V, --version
Print version
See src/tests/**.md
for test inputs and their formatted output in
src/tests/snapshots/
.
This documentation itself is also formatted with FMTM.
A fork of @ytmimi's markdown-fmt
powers this formatter's Markdown handling;
it is a proof of concept for rustfmt
.
Thank you @ytmimi for all the hard work!
This formatter is for myself. If you want extra features, feel free to fork. Pull Requests are welcome, but I will try to keep high code quality.
Items with 🌹 are the ones I want.
I have implemented these options in the markdown-fmt
fork,
but have not exposed them in the CLI.
-
, but can be *
or preserved.1.
, but can have leading 0
s or be preserved.These extensions can be implemented simply by adding struct
s that
implement traits in my markdown-fmt
fork.
I lean towards calling external CLI applications (shell out)
for formatting these blocks of other languages.
These functionalities require further tweaking markdown-fmt
itself.
<
>
around bare URLs 🌹.Functionalities that alter the content would, in principle, not be implemented. Examples include fixing reversed links and incrementing header levels.
Currently, it is perfectly fine to format a Markdown document with both FMTM and Markdownlint, similar to running isort and black, except the order does not matter.