-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
56 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,15 +19,60 @@ Automatically add whitespace between CJK (Chinese, Japanese, Korean) and half-wi | |
|
||
## Install | ||
|
||
```bash | ||
$ curl -sSL https://git.io/JckA6 | bash | ||
``` | ||
|
||
after that, you will get `/usr/local/bin/autocorrect` command. | ||
|
||
```bash | ||
$ autocorrect -h | ||
AutoCorrect 0.4.4 | ||
Jason Lee <[email protected] | ||
Automatically add whitespace between CJK (Chinese, Japanese, Korean) and half-width characters (alphabetical letters, | ||
numerical digits and symbols). | ||
|
||
USAGE: | ||
autocorrect [FLAGS] [text] | ||
|
||
FLAGS: | ||
-h, --help Prints help information | ||
--html Use for HTML format | ||
-V, --version Prints version information | ||
|
||
ARGS: | ||
<text> Target filepath or string (Plain text) for format | ||
``` | ||
|
||
## Usage | ||
|
||
```bash | ||
$ autocorrect 你好Hello世界 | ||
你好 Hello 世界 | ||
$ autocorrect text.md | ||
你好 Hello 世界 | ||
|
||
$ autocorrect text.md > text-new.md | ||
``` | ||
|
||
Format HTML | ||
|
||
```bash | ||
$ autocorrect --html '<p>你好hello世界</p><p>你好world世界</p>' | ||
<p>你好 hello 世界</p><p>你好 world 世界</p> | ||
|
||
$ autocorrect --html text.html | ||
``` | ||
|
||
## Usage in Rust | ||
|
||
In your Cargo.toml | ||
|
||
```toml | ||
[dependencies] | ||
autocorrect = "0.4.0" | ||
``` | ||
|
||
## Usage | ||
|
||
Use `autocorrect::format` to format plain text. | ||
|
||
```rust | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
use autocorrect::{format, format_html}; | ||
use clap::{crate_version, App, Arg, SubCommand}; | ||
use clap::{crate_version, App, Arg}; | ||
use glob::glob; | ||
use std::fs; | ||
use std::path::Path; | ||
|
@@ -9,24 +9,15 @@ pub fn main() { | |
.author("Jason Lee <[email protected]") | ||
.version(crate_version!()) | ||
.about("Automatically add whitespace between CJK (Chinese, Japanese, Korean) and half-width characters (alphabetical letters, numerical digits and symbols).") | ||
.subcommand( | ||
SubCommand::with_name("format") | ||
.about("Format content") | ||
.arg( | ||
Arg::with_name("file").help("Target file (Plain text) for format").takes_value(true).required(true) | ||
) | ||
.arg( | ||
Arg::with_name("html").long("html").help("Use for HTML format") | ||
) | ||
.arg( | ||
Arg::with_name("auto-correct").short("a").long("auto-correct").help("Auto-correct offenses.") | ||
) | ||
.arg( | ||
Arg::with_name("text").help("Target filepath or string (Plain text) for format").takes_value(true).required(false) | ||
) | ||
.arg( | ||
Arg::with_name("html").long("html").help("Use for HTML format") | ||
) | ||
.get_matches(); | ||
|
||
if let Some(matches) = matches.subcommand_matches("format") { | ||
let file_name = matches.value_of("file").unwrap(); | ||
|
||
if let Some(file_name) = matches.value_of("text") { | ||
let path_exist = Path::new(file_name).exists(); | ||
if path_exist { | ||
for f in glob(file_name).unwrap() { | ||
|