aboutsummaryrefslogtreecommitdiff
path: root/web/mastosan/src
diff options
context:
space:
mode:
Diffstat (limited to 'web/mastosan/src')
-rw-r--r--web/mastosan/src/main.rs30
1 files changed, 26 insertions, 4 deletions
diff --git a/web/mastosan/src/main.rs b/web/mastosan/src/main.rs
index a69e24a..80658b0 100644
--- a/web/mastosan/src/main.rs
+++ b/web/mastosan/src/main.rs
@@ -1,7 +1,18 @@
use lol_html::{element, html_content::ContentType, HtmlRewriter, Settings};
+use std::env::args;
use std::io::{self, prelude::*, stdin, stdout};
fn main() -> io::Result<()> {
+ let mode = match args().nth(1) {
+ None => {
+ return Err(io::Error::new(
+ io::ErrorKind::InvalidInput,
+ "usage: mastosan [markdown|slackdown|text]",
+ ))
+ }
+ Some(mode) => mode,
+ };
+
let mut output = Vec::new();
let mut rewriter = HtmlRewriter::new(
Settings {
@@ -22,10 +33,21 @@ fn main() -> io::Result<()> {
}),
element!("a[href]", |el| {
let href = el.get_attribute("href").unwrap();
- el.prepend("|", ContentType::Html);
- el.prepend(&href, ContentType::Html);
- el.prepend("<", ContentType::Html);
- el.append(">", ContentType::Html);
+ match mode.as_str() {
+ "slackdown" => {
+ el.prepend("|", ContentType::Html);
+ el.prepend(&href, ContentType::Html);
+ el.prepend("<", ContentType::Html);
+ el.append(">", ContentType::Html);
+ }
+ "markdown" => {
+ el.prepend("](", ContentType::Html);
+ el.prepend(&href, ContentType::Html);
+ el.prepend("[", ContentType::Html);
+ el.append(")", ContentType::Html);
+ }
+ _ => {}
+ }
el.remove_and_keep_content();
Ok(())