www
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYestin L. Harrison <yestin@ylh.io>2022-06-18 02:54:34 -0700
committerYestin L. Harrison <yestin@ylh.io>2022-06-18 02:55:05 -0700
commit28a95d05ab70d3a3510c04e9ef673800add128cd (patch)
tree6fbb183c6f2c7930305b0274e5306b4e233c3be8
parent94701358f66f8e05723033cb39a621faa3f13554 (diff)
downloadabout-filter-28a95d05ab70d3a3510c04e9ef673800add128cd.tar.gz
about-filter-28a95d05ab70d3a3510c04e9ef673800add128cd.tar.xz
about-filter-28a95d05ab70d3a3510c04e9ef673800add128cd.zip
dependency cleanup and stylistic bikesheddingHEADmaster
-rw-r--r--Cargo.lock119
-rw-r--r--Cargo.toml9
-rw-r--r--src/main.rs49
3 files changed, 36 insertions, 141 deletions
diff --git a/Cargo.lock b/Cargo.lock
index a24b37c..54f2238 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4,10 +4,9 @@ version = 3
[[package]]
name = "about-filter"
-version = "0.1.0"
+version = "0.1.1"
dependencies = [
"comrak",
- "failure",
"html-escape",
"rst_parser",
"rst_renderer",
@@ -38,26 +37,6 @@ dependencies = [
]
[[package]]
-name = "ansi_term"
-version = "0.11.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
-dependencies = [
- "winapi",
-]
-
-[[package]]
-name = "atty"
-version = "0.2.14"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
-dependencies = [
- "hermit-abi",
- "libc",
- "winapi",
-]
-
-[[package]]
name = "autocfg"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -79,12 +58,6 @@ dependencies = [
]
[[package]]
-name = "bitflags"
-version = "1.2.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
-
-[[package]]
name = "block-buffer"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -130,27 +103,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
-name = "clap"
-version = "2.33.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
-dependencies = [
- "ansi_term",
- "atty",
- "bitflags",
- "strsim",
- "textwrap",
- "unicode-width",
- "vec_map",
-]
-
-[[package]]
name = "comrak"
-version = "0.11.0"
+version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "17bac331cb476d0d005a492e07a5eb64f8b321e3788b1fb265e768fb6918ea13"
+checksum = "3a00ddef7b344800116b794a7cabfb2c60ef4f44db2f44b0f8f3f6dd2ea43866"
dependencies = [
- "clap",
"entities",
"lazy_static",
"pest",
@@ -254,19 +211,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f0a01e0497841a3b2db4f8afa483cce65f7e96a3498bd6c541734792aeac8fe7"
[[package]]
-name = "hermit-abi"
-version = "0.1.19"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
-dependencies = [
- "libc",
-]
-
-[[package]]
name = "html-escape"
-version = "0.2.9"
+version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "816ea801a95538fc5f53c836697b3f8b64a9d664c4f0b91efe1fe7c92e4dbcb7"
+checksum = "b8e7479fa1ef38eb49fb6a42c426be515df2d063f06cb8efd3e50af073dbc26c"
dependencies = [
"utf8-width",
]
@@ -421,9 +369,9 @@ dependencies = [
[[package]]
name = "regex"
-version = "1.5.4"
+version = "1.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461"
+checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1"
dependencies = [
"aho-corasick",
"memchr",
@@ -432,9 +380,9 @@ dependencies = [
[[package]]
name = "regex-syntax"
-version = "0.6.25"
+version = "0.6.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
+checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64"
[[package]]
name = "rst_parser"
@@ -531,12 +479,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6fa3938c99da4914afedd13bf3d79bcb6c277d1b2c398d23257a304d9e1b074"
[[package]]
-name = "strsim"
-version = "0.8.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
-
-[[package]]
name = "syn"
version = "1.0.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -560,15 +502,6 @@ dependencies = [
]
[[package]]
-name = "textwrap"
-version = "0.11.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
-dependencies = [
- "unicode-width",
-]
-
-[[package]]
name = "tinyvec"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -636,12 +569,6 @@ dependencies = [
]
[[package]]
-name = "unicode-width"
-version = "0.1.8"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
-
-[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -672,34 +599,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7cf7d77f457ef8dfa11e4cd5933c5ddb5dc52a94664071951219a97710f0a32b"
[[package]]
-name = "vec_map"
-version = "0.8.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
-
-[[package]]
-name = "winapi"
-version = "0.3.9"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
-dependencies = [
- "winapi-i686-pc-windows-gnu",
- "winapi-x86_64-pc-windows-gnu",
-]
-
-[[package]]
-name = "winapi-i686-pc-windows-gnu"
-version = "0.4.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
-
-[[package]]
-name = "winapi-x86_64-pc-windows-gnu"
-version = "0.4.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
-
-[[package]]
name = "xdg"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index fa37b03..6bdd1f9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "about-filter"
-version = "0.1.0"
-edition = "2018"
+version = "0.1.1"
+edition = "2021"
readme = "README.md"
license-file = "LICENSE"
@@ -10,8 +10,7 @@ homepage = "https://git.ylh.io/about-filter"
repository = "https://github.com/ylh/about-filter"
[dependencies]
-failure = "0.1.8"
rst_parser = "0.4.0"
rst_renderer = "0.4.0"
-comrak = "0.11.0"
-html-escape = "0.2.9"
+comrak = { version = "0.13.0", default-features = false }
+html-escape = "0.2.11"
diff --git a/src/main.rs b/src/main.rs
index 21cf2fd..9ef4792 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -3,48 +3,45 @@ use std::ffi::OsStr;
use std::io::{self, Read, Write};
use std::path::Path;
-use comrak;
-use failure;
+use comrak::{markdown_to_html, ComrakOptions};
use html_escape;
use rst_parser;
use rst_renderer;
-fn to_io(e: failure::Error) -> io::Error {
- io::Error::new(io::ErrorKind::Other, e.to_string())
+fn md(buf: &str, out: &mut impl Write) -> io::Result<()> {
+ out.write_all(markdown_to_html(buf, &ComrakOptions::default()).as_bytes())
}
-fn md<W: Write>(buf: &str, out: &mut W) -> io::Result<()> {
- let s = comrak::markdown_to_html(buf, &comrak::ComrakOptions::default());
- out.write(s.as_bytes()).map(|_| ())
+fn rst(buf: &str, out: &mut impl Write) -> io::Result<()> {
+ rst_parser::parse(buf)
+ .and_then(|d| rst_renderer::render_html(&d, out, false))
+ .map_err(|e| io::Error::new(io::ErrorKind::Other, e.to_string()))
}
-fn rst<W: Write>(buf: &str, out: &mut W) -> io::Result<()> {
- let d = rst_parser::parse(buf).map_err(to_io)?;
- rst_renderer::render_html(&d, out, false).map_err(to_io)
+fn cat(buf: &str, out: &mut impl Write) -> io::Result<()> {
+ out.write_all(buf.as_bytes())
}
-fn cat<W: Write>(buf: &str, out: &mut W) -> io::Result<()> {
- out.write(buf.as_bytes()).map(|_| ())
-}
-
-fn txt<W: Write>(buf: &str, out: &mut W) -> io::Result<()> {
- out.write(b"<pre>")?;
+fn txt(buf: &str, out: &mut impl Write) -> io::Result<()> {
+ out.write_all(b"<pre>")?;
html_escape::encode_safe_to_writer(buf, out)?;
- out.write(b"</pre>").map(|_| ())
+ out.write_all(b"</pre>")
}
fn main() -> io::Result<()> {
- let encoder = env::args().nth(1).as_ref()
- .map(Path::new).and_then(Path::extension).and_then(OsStr::to_str)
+ let mut buf = String::new();
+ io::stdin().read_to_string(&mut buf)?;
+
+ (env::args().nth(1).as_ref()
+ .map(Path::new)
+ .and_then(Path::extension)
+ .and_then(OsStr::to_str)
.map(|s| match s.to_lowercase().as_str() {
- "md" | "mkd" | "markdown" | "mdown" => md,
+ "md" | "mkd" | "markdown" | "mdown" => md,
"rst" => rst,
"html" | "htm" => cat,
_ => txt
- }).unwrap_or(txt);
- let mut buf = String::new();
-
- io::stdin().read_to_string(&mut buf)?;
-
- encoder(&buf.as_str(), &mut io::stdout())
+ })
+ .unwrap_or(txt)
+ )(&buf.as_str(), &mut io::stdout())
}