Skip to content

Commit

Permalink
markdown-friendly style preserves hanging
Browse files Browse the repository at this point in the history
  • Loading branch information
SichangHe committed May 27, 2024
1 parent 36b8666 commit 36cdfa9
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 28 deletions.
25 changes: 20 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn main() -> Result<()> {
let formatted = format(
&input,
app.line_width,
app.hanging_config,
app.hanging_config(),
&paragraph_starts,
);

Expand Down Expand Up @@ -94,12 +94,14 @@ struct App {
#[arg(
short = 'p',
long,
default_value_t,
value_enum,
help = r#"Treatment for hanging paragraphs.
If not set, any change indentation changes start a new paragraph."#
help = r#"Treatment for hanging paragraphs:
`disallow` causes any indentation changes to start a new paragraph (default);
`flatten` ignores any indentation changes;
`hang` allows the second line to start hanging (having more indentation).
"#
)]
hanging_config: Hanging,
hanging_config: Option<Hanging>,

#[arg(
short,
Expand Down Expand Up @@ -127,4 +129,17 @@ impl App {
ParagraphStarts::preset(self.markdown_friendly, self.latex_friendly)
.context("Failed to build special paragraph starts handler.")
}

fn hanging_config(&self) -> Hanging {
match (
self.hanging_config,
self.markdown_friendly,
self.latex_friendly,
) {
(Some(config), _, _) => config,
(_, true, _) => Hanging::Hang,
(_, _, true) => Hanging::Flatten,
_ => Hanging::Disallow,
}
}
}
2 changes: 1 addition & 1 deletion src/tests/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fn default_format(text: &str) -> String {
}

fn markdown_format(text: &str) -> String {
format(text, 80, Hanging::Flatten, &markdown_paragraph_starts()).join("")
format(text, 80, Hanging::Hang, &markdown_paragraph_starts()).join("")
}

fn latex_format(text: &str) -> String {
Expand Down
9 changes: 5 additions & 4 deletions src/tests/snapshots/fmtt__tests__format__bracket-2.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ source: src/tests/format.rs
expression: "&markdown_formatted"
---
\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}
\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}
12 changes: 6 additions & 6 deletions src/tests/snapshots/fmtt__tests__format__gpt1-2.snap
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ 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?
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
Expand Down
4 changes: 2 additions & 2 deletions src/tests/snapshots/fmtt__tests__format__indented-2.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat.
Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Excepteur sint occaecat cupidatat non proident,
sunt in culpa qui officia deserunt mollit anim id est laborum.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat.
Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Duis aute irure dolor in reprehenderit in
voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Excepteur sint occaecat cupidatat non proident,
sunt in culpa qui officia deserunt mollit anim id est laborum.
9 changes: 5 additions & 4 deletions src/tests/snapshots/fmtt__tests__format__latex_figure-2.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ source: src/tests/format.rs
expression: "&markdown_formatted"
---
\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}
\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}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ body
content
===
###### Header 6
####### This is just ordinary text, not a header.
####### This is just ordinary text,
not a header.
3 changes: 2 additions & 1 deletion src/tests/snapshots/fmtt__tests__format__markdown_mix-2.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ content
2. This line is separate from the previous one.
===
###### Header 6
####### This is just ordinary text, not a header.
####### This is just ordinary text,
not a header.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ expression: "&markdown_formatted"
---
1. Lorem ipsum dolor sit amet
2. consectetur adipiscing elit
3. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua
3. Sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ expression: "&markdown_formatted"
---
- Lorem ipsum dolor sit amet
- consectetur adipiscing elit
* Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua
* Sed do eiusmod tempor incididunt ut labore et
dolore magna aliqua

0 comments on commit 36cdfa9

Please sign in to comment.