diff --git a/src/main.rs b/src/main.rs index af01dad..0b40dfb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,7 +22,7 @@ fn main() -> Result<()> { let formatted = format( &input, app.line_width, - app.hanging_config, + app.hanging_config(), ¶graph_starts, ); @@ -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, #[arg( short, @@ -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, + } + } } diff --git a/src/tests/format.rs b/src/tests/format.rs index ddeab3b..01c3759 100644 --- a/src/tests/format.rs +++ b/src/tests/format.rs @@ -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 { diff --git a/src/tests/snapshots/fmtt__tests__format__bracket-2.snap b/src/tests/snapshots/fmtt__tests__format__bracket-2.snap index ac26439..cecefd9 100644 --- a/src/tests/snapshots/fmtt__tests__format__bracket-2.snap +++ b/src/tests/snapshots/fmtt__tests__format__bracket-2.snap @@ -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} diff --git a/src/tests/snapshots/fmtt__tests__format__gpt1-2.snap b/src/tests/snapshots/fmtt__tests__format__gpt1-2.snap index a50a309..58df8e2 100644 --- a/src/tests/snapshots/fmtt__tests__format__gpt1-2.snap +++ b/src/tests/snapshots/fmtt__tests__format__gpt1-2.snap @@ -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 diff --git a/src/tests/snapshots/fmtt__tests__format__indented-2.snap b/src/tests/snapshots/fmtt__tests__format__indented-2.snap index f37332a..e493a3b 100644 --- a/src/tests/snapshots/fmtt__tests__format__indented-2.snap +++ b/src/tests/snapshots/fmtt__tests__format__indented-2.snap @@ -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. diff --git a/src/tests/snapshots/fmtt__tests__format__indented_and_allow_indented_paragraphs-2.snap b/src/tests/snapshots/fmtt__tests__format__indented_and_allow_indented_paragraphs-2.snap index f37332a..e493a3b 100644 --- a/src/tests/snapshots/fmtt__tests__format__indented_and_allow_indented_paragraphs-2.snap +++ b/src/tests/snapshots/fmtt__tests__format__indented_and_allow_indented_paragraphs-2.snap @@ -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. diff --git a/src/tests/snapshots/fmtt__tests__format__latex_figure-2.snap b/src/tests/snapshots/fmtt__tests__format__latex_figure-2.snap index ac26439..cecefd9 100644 --- a/src/tests/snapshots/fmtt__tests__format__latex_figure-2.snap +++ b/src/tests/snapshots/fmtt__tests__format__latex_figure-2.snap @@ -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} diff --git a/src/tests/snapshots/fmtt__tests__format__markdown_headers_separators-2.snap b/src/tests/snapshots/fmtt__tests__format__markdown_headers_separators-2.snap index d811086..386d929 100644 --- a/src/tests/snapshots/fmtt__tests__format__markdown_headers_separators-2.snap +++ b/src/tests/snapshots/fmtt__tests__format__markdown_headers_separators-2.snap @@ -9,4 +9,5 @@ body content === ###### Header 6 -####### This is just ordinary text, not a header. +####### This is just ordinary text, + not a header. diff --git a/src/tests/snapshots/fmtt__tests__format__markdown_mix-2.snap b/src/tests/snapshots/fmtt__tests__format__markdown_mix-2.snap index 6583abf..06ce8c7 100644 --- a/src/tests/snapshots/fmtt__tests__format__markdown_mix-2.snap +++ b/src/tests/snapshots/fmtt__tests__format__markdown_mix-2.snap @@ -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. diff --git a/src/tests/snapshots/fmtt__tests__format__markdown_ordered_list-2.snap b/src/tests/snapshots/fmtt__tests__format__markdown_ordered_list-2.snap index 8b75f3f..8253376 100644 --- a/src/tests/snapshots/fmtt__tests__format__markdown_ordered_list-2.snap +++ b/src/tests/snapshots/fmtt__tests__format__markdown_ordered_list-2.snap @@ -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 diff --git a/src/tests/snapshots/fmtt__tests__format__markdown_unordered_list-2.snap b/src/tests/snapshots/fmtt__tests__format__markdown_unordered_list-2.snap index fda7f9f..aaf3e41 100644 --- a/src/tests/snapshots/fmtt__tests__format__markdown_unordered_list-2.snap +++ b/src/tests/snapshots/fmtt__tests__format__markdown_unordered_list-2.snap @@ -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