feat(cheddar): Add toggle flag for about-filter behaviour
Cheddar now needs to be passed the --about-filter flag to toggle the behaviour for rendering Markdown into HTML. By default Markdown will be highlighted like normal source code (i.e. cgit source-filtering is the default behaviour).
This commit is contained in:
parent
47541340c0
commit
d752cbecc0
1 changed files with 38 additions and 13 deletions
|
@ -46,17 +46,41 @@ lazy_static! {
|
||||||
// Emulates the GitHub style (subtle background hue and padding).
|
// Emulates the GitHub style (subtle background hue and padding).
|
||||||
const BLOCK_PRE: &str = "<pre style=\"background-color:#f6f8fa;padding:16px;\">\n";
|
const BLOCK_PRE: &str = "<pre style=\"background-color:#f6f8fa;padding:16px;\">\n";
|
||||||
|
|
||||||
fn args_extension() -> Option<String> {
|
struct Args {
|
||||||
// The name of the file to be formatted is usually passed in as
|
/// Should Cheddar run as an about filter? (i.e. give special
|
||||||
// the first argument and can be used to determine a syntax set.
|
/// rendering treatment to Markdown documents)
|
||||||
let args = env::args().collect::<Vec<String>>();
|
about_filter: bool,
|
||||||
if args.len() != 2 {
|
|
||||||
return None
|
/// What file extension has been supplied (if any)?
|
||||||
|
extension: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parse the command-line flags passed to cheddar to determine
|
||||||
|
/// whether it is running in about-filter mode (`--about-filter`) and
|
||||||
|
/// what file extension has been supplied.
|
||||||
|
fn parse_args() -> Args {
|
||||||
|
let mut args = Args {
|
||||||
|
about_filter: false,
|
||||||
|
extension: None,
|
||||||
|
};
|
||||||
|
|
||||||
|
for (i, arg) in env::args().enumerate() {
|
||||||
|
if i == 0 {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if arg == "--about-filter" {
|
||||||
|
args.about_filter = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
args.extension = Path::new(&arg)
|
||||||
|
.extension()
|
||||||
|
.and_then(OsStr::to_str)
|
||||||
|
.map(|s| s.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
Path::new(&args[1]).extension()
|
return args
|
||||||
.and_then(OsStr::to_str)
|
|
||||||
.map(|s| s.to_string())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_continue(res: &io::Result<usize>) -> bool {
|
fn should_continue(res: &io::Result<usize>) -> bool {
|
||||||
|
@ -190,9 +214,10 @@ fn format_code(extension: Option<&str>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let extension = args_extension();
|
let args = parse_args();
|
||||||
match extension.as_ref().map(String::as_str) {
|
|
||||||
Some("md") => format_markdown(),
|
match args.extension.as_ref().map(String::as_str) {
|
||||||
extension => format_code(extension),
|
Some("md") if args.about_filter => format_markdown(),
|
||||||
|
extension => format_code(extension),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue