在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):kivikakk/comrak开源软件地址(OpenSource Url):https://github.com/kivikakk/comrak开源编程语言(OpenSource Language):Rust 90.2%开源软件介绍(OpenSource Introduction):ComrakRust port of github's InstallationSpecify it as a requirement in [dependencies]
comrak = "0.14" Comrak supports Rust stable. Mac & Linux Binariescurl https://webinstall.dev/comrak | bash Windows 10 Binariescurl.exe -A "MS" https://webinstall.dev/comrak | powershell Usage$ comrak --help
comrak 0.14.0
Ashe Connor <[email protected]>
A 100% CommonMark-compatible GitHub Flavored Markdown parser and formatter
USAGE:
comrak [FLAGS] [OPTIONS] [--] [FILE]...
FLAGS:
--escape Escape raw HTML instead of clobbering it
--gfm Enable GitHub-flavored markdown extensions strikethrough, tagfilter, table, autolink, and
tasklist. It also enables --github-pre-lang.
--github-pre-lang Use GitHub-style <pre lang> for code blocks
--hardbreaks Treat newlines as hard line breaks
-h, --help Prints help information
--smart Use smart punctuation
--unsafe Allow raw HTML and dangerous URLs
-V, --version Prints version information
OPTIONS:
-c, --config-file <PATH> Path to config file containing command-line arguments, or `none'
[default: /Users/kivikakk/.config/comrak/config]
--default-info-string <INFO> Default value for fenced code block's info strings if none is given
-e, --extension <EXTENSION>... Specify an extension name to use [possible values: strikethrough,
tagfilter, table, autolink, tasklist, superscript, footnotes,
description-lists]
-t, --to <FORMAT> Specify output format [default: html] [possible values: html,
commonmark]
--front-matter-delimiter <DELIMITER> Ignore front-matter that starts and ends with the given string
--header-ids <PREFIX> Use the Comrak header IDs extension, with the given ID prefix
--list-style <LIST_STYLE> Specify bullet character for lists (-, +, *) in CommonMark ouput
[default: dash] [possible values: dash, plus, star]
-o, --output <FILE> Write output to FILE instead of stdout
--syntax-highlighting <THEME> Syntax highlighting for codefence blocks. Choose a theme or 'none' for
disabling. [default: base16-ocean.dark]
--width <WIDTH> Specify wrap width (0 = nowrap) [default: 0]
ARGS:
<FILE>... The CommonMark file to parse; or standard input if none passed
By default, Comrak will attempt to read command-line options from a config file specified by --config-file. This
behaviour can be disabled by passing --config-file none. It is not an error if the file does not exist. And there's a Rust interface. You can use use comrak::{markdown_to_html, ComrakOptions};
assert_eq!(markdown_to_html("Hello, **世界**!", &ComrakOptions::default()),
"<p>Hello, <strong>世界</strong>!</p>\n"); Or you can parse the input into an AST yourself, manipulate it, and then use your desired formatter: extern crate comrak;
use comrak::{parse_document, format_html, Arena, ComrakOptions};
use comrak::nodes::{AstNode, NodeValue};
// The returned nodes are created in the supplied Arena, and are bound by its lifetime.
let arena = Arena::new();
let root = parse_document(
&arena,
"This is my input.\n\n1. Also my input.\n2. Certainly my input.\n",
&ComrakOptions::default());
fn iter_nodes<'a, F>(node: &'a AstNode<'a>, f: &F)
where F : Fn(&'a AstNode<'a>) {
f(node);
for c in node.children() {
iter_nodes(c, f);
}
}
iter_nodes(root, &|node| {
match &mut node.data.borrow_mut().value {
&mut NodeValue::Text(ref mut text) => {
let orig = std::mem::replace(text, vec![]);
*text = String::from_utf8(orig).unwrap().replace("my", "your").as_bytes().to_vec();
}
_ => (),
}
});
let mut html = vec![];
format_html(root, &ComrakOptions::default(), &mut html).unwrap();
assert_eq!(
String::from_utf8(html).unwrap(),
"<p>This is your input.</p>\n\
<ol>\n\
<li>Also your input.</li>\n\
<li>Certainly your input.</li>\n\
</ol>\n"); SecurityAs with To allow these, use the ExtensionsComrak supports the five extensions to CommonMark defined in the GitHub Flavored Markdown Spec: Comrak additionally supports its own extensions, which are yet to be specced out (PRs welcome!):
By default none are enabled; they are individually enabled with each parse by setting the appropriate values in the
PluginsCodefence syntax highlighterAt the moment syntax highlighting of codefence blocks is the only feature that can be enhanced with plugins. Create an implementation of the See the Syntect
Related projectsComrak's design goal is to model the upstream The downside, of course, is that the code is not what I'd call idiomatic Rust (so many
As far as I know, Comrak is the only library to implement all of the GitHub Flavored Markdown extensions to the spec, but this tends to only be important if you want to reproduce GitHub's Markdown rendering exactly, e.g. in a GitHub client app. ContributingContributions are highly encouraged; where possible I practice Optimistic Merging as described by Peter Hintjens. Please keep the code of conduct in mind when interacting with this project. Thank you to comrak's many contributors for PRs and issues opened! Code ContributorsFinancial ContributorsBecome a financial contributor and help us sustain our community. [Contribute] IndividualsOrganizationsSupport this project with your organization. Your logo will show up here with a link to your website. [Contribute] ContactAshe Connor <ashe kivikakk ee> LegalCopyright (c) 2017–2021, Ashe Connor. Licensed under the 2-Clause BSD License.
See COPYING for all the details. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论