forked from uutils/coreutils
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request uutils#4158 from tertsdiepraam/markdown-in-docs-v1
Markdown in docs v1
- Loading branch information
Showing
5 changed files
with
131 additions
and
56 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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// Copyright (C) ~ Roy Ivy III <[email protected]>; MIT license | ||
// spell-checker:ignore backticks | ||
|
||
extern crate proc_macro; | ||
use std::{fs::File, io::Read, path::PathBuf}; | ||
|
@@ -37,6 +38,19 @@ pub fn main(_args: TokenStream, stream: TokenStream) -> TokenStream { | |
TokenStream::from(new) | ||
} | ||
|
||
// FIXME: This is currently a stub. We could do much more here and could | ||
// even pull in a full markdown parser to get better results. | ||
/// Render markdown into a format that's easier to read in the terminal. | ||
/// | ||
/// For now, all this function does is remove backticks. | ||
/// Some ideas for future improvement: | ||
/// - Render headings as bold | ||
/// - Convert triple backticks to indented | ||
/// - Printing tables in a nice format | ||
fn render_markdown(s: &str) -> String { | ||
s.replace('`', "") | ||
} | ||
|
||
/// Get the usage from the "Usage" section in the help file. | ||
/// | ||
/// The usage is assumed to be surrounded by markdown code fences. It may span | ||
|
@@ -81,7 +95,8 @@ pub fn help_section(input: TokenStream) -> TokenStream { | |
let section = get_argument(&input, 0, "section"); | ||
let filename = get_argument(&input, 1, "filename"); | ||
let text = parse_help(§ion, &filename); | ||
TokenTree::Literal(Literal::string(&text)).into() | ||
let rendered = render_markdown(&text); | ||
TokenTree::Literal(Literal::string(&rendered)).into() | ||
} | ||
|
||
/// Get an argument from the input vector of `TokenTree`. | ||
|