Skip to content

Commit

Permalink
doc: help message align w/ new hanging impl;fix latex config
Browse files Browse the repository at this point in the history
  • Loading branch information
SichangHe committed May 27, 2024
1 parent 36cdfa9 commit 2d34a6b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ This help message is formatted using FMTT itself as an example.
Usage: fmtt [OPTIONS]

Options:
-w, --line-width <LINE_WIDTH>
-w, --line-width <LINE_WIDTH>
Maximum line width limit.

[default: 80]
Expand All @@ -50,14 +50,18 @@ Options:
-c, --change-in-place
If input file is provided, write output to it.

-p, --allow-indented-paragraphs
Allow indented paragraphs.
If not set, any change indentation changes start a new paragraph.
-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.
Useful for Markdown, especially with `-p`.
Setting this flag also causes `--hanging-config` to default to `hang`.

-l, --latex-friendly
Ignore `%`-started lines;
Expand Down Expand Up @@ -144,7 +148,7 @@ content
###### Header 6
####### This is just ordinary text,
not a header.
" | fmtt -pm
" | fmtt -m
# Header 1
body
Expand All @@ -159,7 +163,8 @@ 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.
```
Expand Down
19 changes: 5 additions & 14 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,7 @@ struct App {
short = 'p',
long,
value_enum,
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).
"#
help = r#"Treatment for hanging paragraphs. Default: disallow."#
)]
hanging_config: Option<Hanging>,

Expand All @@ -109,7 +105,7 @@ struct App {
default_value = "false",
help = r#"Treat `# `/`## `/…/`###### `/`---`/`===`-started lines as single paragraphs;
treat `- `/`* `/regex`\d+\. `-started lines as paragraph starts.
Useful for Markdown, especially with `-p`."#
Setting this flag also causes `--hanging-config` to default to `hang`."#
)]
markdown_friendly: bool,

Expand All @@ -131,14 +127,9 @@ impl App {
}

fn hanging_config(&self) -> Hanging {
match (
self.hanging_config,
self.markdown_friendly,
self.latex_friendly,
) {
(Some(config), _, _) => config,
(_, true, _) => Hanging::Hang,
(_, _, true) => Hanging::Flatten,
match (self.hanging_config, self.markdown_friendly) {
(Some(config), _) => config,
(_, true) => Hanging::Hang,
_ => Hanging::Disallow,
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/paragraphs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ pub struct ParagraphsIter<'a> {
#[derive(clap::ValueEnum, Copy, Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
#[serde(rename_all = "kebab-case")]
pub enum Hanging {
/// Hanging paragraphs are treated as separate paragraphs.
/// Disallow hanging. Any indentation change starts a new paragraph.
#[default]
Disallow,
/// Remove extra indentation in hanging lines.
/// Ignore indentation changes; remove extra indentation in hanging lines.
Flatten,
/// Keep the hanging lines as they are.
/// Allow the second line to start hanging (having more indentation);
/// keep the hanging lines as is.
Hang,
}

Expand Down

0 comments on commit 2d34a6b

Please sign in to comment.