10个版本 (5个破坏性版本)
0.6.2 | 2024年5月30日 |
---|---|
0.6.1 | 2024年5月27日 |
0.5.2 | 2024年5月27日 |
0.4.0 | 2024年3月6日 |
0.1.0 | 2024年2月15日 |
#58 在 值格式化
每月629次下载
在 fmtm 中使用
46KB
986 行
ForMaT Text
一种友好的diff文本格式化工具,在合理的标点符号和单词上断行以适应行宽。
与fmt
相比,在Git中使用更为有用,因为格式化更加一致,从而产生更小的diff。
- 尊重行宽限制。
- 优先分割于
- 句子结尾如
.
,然后 - 子句结尾如
,
,然后 - 子句开头如
(
,最后 - 句子连接词如
and
。
- 句子结尾如
- 对使用启发式方法的缩写有有限的支援。
安装
cargo install fmtt
使用
$ fmtt --help
ForMaT Text diff-friendly,
breaking lines on sensible punctuations and words to fit a line width.
Like fmt, FMTT is a text formatter;
it 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 LaTeX,
FMTT does not distinguish different whitespaces or their amount except for
double line breaks; it only preserves leading spaces, not tabs.
This help message is formatted using FMTT itself as an example.
Usage: fmtt [OPTIONS]
Options:
-w, --line-width <LINE_WIDTH>
Maximum line width limit.
[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.
-p, --hanging-config <HANGING_CONFIG>
Treatment for hanging paragraphs. Default: disallow.
Possible values:
- disallow: Disallow hanging. Any indentation change starts a new paragraph
- flatten: Ignore indentation changes; remove extra indentation in hanging lines
- hang: Allow the second line to start hanging (having more indentation); keep the hanging lines as is
-m, --markdown-friendly
Treat `# `/`## `/…/`###### `/`---`/`===`-started lines as single paragraphs;
treat `- `/`* `/regex`\d+\. `-started lines as paragraph starts.
Setting this flag also causes `--hanging-config` to default to `hang`.
-l, --latex-friendly
Ignore `%`-started lines;
treat `\` started lines as paragraph starts.
Useful for LaTeX.
-h, --help
Print help (see a summary with '-h')
-V, --version
Print version
示例
纯文本
$ echo "
The department heads will convene at 3 P.M. to engage in a comprehensive discussion regarding the second-quarter budget, and it is imperative that you bring your identification card for seamless access; subsequently, the Information Technology team is scheduled to conduct a software demonstration at 4 P.M., with the esteemed presence of Mr. Chief Executive Officer's beautiful personal assistant.
In preparation for the impending meeting, a thorough review of the key performance indicators and return on investment is requested before the designated time of the meeting (which is set for 5 P.M.), and your prompt RSVP by 12 P.M. is kindly anticipated to ensure optimal (or at least as optimal as possible) coordination for the arrival of the very important persons at 2 P.M.! Furthermore, it is completely acceptable if you find yourself out of the office during this period.
Simultaneously, the Quality Assurance team is seeking your valuable input in relation to the user interface and user experience; your collaboration is essential before the end of the day. A brief touch-base is suggested before the close of business hours to synchronize efforts and align objectives for maximum efficiency?
Meanwhile, the Research and Development team is deeply immersed in the execution of a project shrouded in secrecy, with the exact estimated time of arrival for the project launch yet to be determined! Additionally, the Human Resources department requires your date of birth for the forthcoming birthday celebration, an event exclusively reserved for individuals of paramount importance, and your immediate response for attendance is highly encouraged. Enjoy the festivities!
" | fmtt
The department heads will convene at 3 P.M. to engage in
a comprehensive discussion regarding the second-quarter budget,
and it is imperative that you bring your identification card for
seamless access; subsequently,
the Information Technology team is scheduled to
conduct a software demonstration at 4 P.M.,
with the esteemed presence of
Mr. Chief Executive Officer's beautiful personal assistant.
In preparation for the impending meeting,
a thorough review of the key performance indicators and return on
investment is requested before the designated time of the meeting
(which is set for 5 P.M.),
and your prompt RSVP by 12 P.M. is kindly anticipated to ensure optimal
(or at least as optimal as possible)
coordination for the arrival of the very important persons at 2 P.M.!
Furthermore,
it is completely acceptable if you find yourself out of
the office during this period.
Simultaneously,
the Quality Assurance team is seeking your valuable input in relation to
the user interface and user experience;
your collaboration is essential before the end of the day.
A brief touch-base is suggested before the close of business hours to
synchronize efforts and align objectives for maximum efficiency?
Meanwhile,
the Research and Development team is deeply immersed in the execution of
a project shrouded in secrecy,
with the exact estimated time of arrival for the project launch yet to
be determined!
Additionally,
the Human Resources department requires your date of birth for
the forthcoming birthday celebration,
an event exclusively reserved for individuals of paramount importance,
and your immediate response for attendance is highly encouraged.
Enjoy the festivities!
Markdown友好模式
$ echo "
# Header 1
body
---
more body
## Header 2
content
- Lists are respected.
- These two are not merged into one line.
1. Ordered lists are also preserved.
2. This line is separate from the previous one.
===
###### Header 6
####### This is just ordinary text,
not a header.
" | fmtt -m
# Header 1
body
---
more body
## Header 2
content
- Lists are respected.
- These two are not merged into one line.
1. Ordered lists are also preserved.
2. This line is separate from the previous one.
===
###### Header 6
####### This is just ordinary text,
not a header.
LaTeX友好模式
$ echo "
\begin{figure}
\centering
\includegraphics[width=0.9\linewidth]{figs/fig-name.pdf}
\caption{Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint cillum sint consectetur cupidatat.\texdtbf{lorem ipsum dolor sit amet}}
\label{fig:lorem}
\end{figure}
" | fmtt
\begin{figure}
\centering
\includegraphics[width=0.9\linewidth]{figs/fig-name.pdf}
\caption{Lorem ipsum dolor sit amet,
qui minim labore adipisicing minim sint cillum sint consectetur
cupidatat.\texdtbf{lorem ipsum dolor sit amet}}
\label{fig:lorem}
\end{figure}
依赖关系
~8–15MB
~182K SLoC