Skip to content

Commit

Permalink
Merge pull request #89 from kivikakk/latest-upstream
Browse files Browse the repository at this point in the history
latest upstream
  • Loading branch information
Ashe Connor authored Nov 27, 2018
2 parents 3262824 + b9b8a27 commit 343cb69
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 111 deletions.
8 changes: 4 additions & 4 deletions src/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ impl<'o> HtmlFormatter<'o> {
},
NodeValue::HtmlBlock(ref nhb) => if entering {
self.cr()?;
if self.options.safe {
if !self.options.unsafe_ {
self.output.write_all(b"<!-- raw HTML omitted -->")?;
} else if self.options.ext_tagfilter {
tagfilter_block(&nhb.literal, &mut self.output)?;
Expand Down Expand Up @@ -509,7 +509,7 @@ impl<'o> HtmlFormatter<'o> {
self.output.write_all(b"</code>")?;
},
NodeValue::HtmlInline(ref literal) => if entering {
if self.options.safe {
if !self.options.unsafe_ {
self.output.write_all(b"<!-- raw HTML omitted -->")?;
} else if self.options.ext_tagfilter && tagfilter(literal) {
self.output.write_all(b"&lt;")?;
Expand Down Expand Up @@ -540,7 +540,7 @@ impl<'o> HtmlFormatter<'o> {
},
NodeValue::Link(ref nl) => if entering {
self.output.write_all(b"<a href=\"")?;
if !self.options.safe || !dangerous_url(&nl.url) {
if self.options.unsafe_ || !dangerous_url(&nl.url) {
self.escape_href(&nl.url)?;
}
if !nl.title.is_empty() {
Expand All @@ -553,7 +553,7 @@ impl<'o> HtmlFormatter<'o> {
},
NodeValue::Image(ref nl) => if entering {
self.output.write_all(b"<img src=\"")?;
if !self.options.safe || !dangerous_url(&nl.url) {
if self.options.unsafe_ || !dangerous_url(&nl.url) {
self.escape_href(&nl.url)?;
}
self.output.write_all(b"\" alt=\"")?;
Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ fn main() -> Result<(), Box<Error>> {
.takes_value(true),
)
.arg(
clap::Arg::with_name("safe")
.long("safe")
.help("Suppress raw HTML and dangerous URLs"),
clap::Arg::with_name("unsafe")
.long("unsafe")
.help("Allow raw HTML and dangerous URLs"),
)
.arg(
clap::Arg::with_name("extension")
Expand Down Expand Up @@ -114,7 +114,7 @@ fn main() -> Result<(), Box<Error>> {
default_info_string: matches
.value_of("default-info-string")
.map(|e| e.to_owned()),
safe: matches.is_present("safe"),
unsafe_: matches.is_present("unsafe"),
ext_strikethrough: exts.remove("strikethrough"),
ext_tagfilter: exts.remove("tagfilter"),
ext_table: exts.remove("table"),
Expand Down
6 changes: 4 additions & 2 deletions src/parser/inlines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,8 +718,10 @@ impl<'a, 'r, 'o, 'd, 'i> Subject<'a, 'r, 'o, 'd, 'i> {
closer_num_chars -= use_delims;

if self.options.ext_strikethrough && opener_char == b'~' {
opener_num_chars = 0;
closer_num_chars = 0;
if opener_num_chars != closer_num_chars ||
opener_num_chars > 0 {
return None
}
}

opener
Expand Down
20 changes: 11 additions & 9 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pub struct ComrakOptions {
/// ```
pub default_info_string: Option<String>,

/// Disable rendering of raw HTML and potentially dangerous links.
/// Allow rendering of raw HTML and potentially dangerous links.
///
/// ```
/// # use comrak::{markdown_to_html, ComrakOptions};
Expand All @@ -164,19 +164,19 @@ pub struct ComrakOptions {
/// [Safe](http://commonmark.org).\n";
///
/// assert_eq!(markdown_to_html(input, &options),
/// "<script>\nalert(\'xyz\');\n</script>\n\
/// <p>Possibly <marquee>annoying</marquee>.</p>\n\
/// <p><a href=\"javascript:alert(document.cookie)\">Dangerous</a>.</p>\n\
/// <p><a href=\"http://commonmark.org\">Safe</a>.</p>\n");
///
/// options.safe = true;
/// assert_eq!(markdown_to_html(input, &options),
/// "<!-- raw HTML omitted -->\n\
/// <p>Possibly <!-- raw HTML omitted -->annoying<!-- raw HTML omitted -->.</p>\n\
/// <p><a href=\"\">Dangerous</a>.</p>\n\
/// <p><a href=\"http://commonmark.org\">Safe</a>.</p>\n");
///
/// options.unsafe_ = true;
/// assert_eq!(markdown_to_html(input, &options),
/// "<script>\nalert(\'xyz\');\n</script>\n\
/// <p>Possibly <marquee>annoying</marquee>.</p>\n\
/// <p><a href=\"javascript:alert(document.cookie)\">Dangerous</a>.</p>\n\
/// <p><a href=\"http://commonmark.org\">Safe</a>.</p>\n");
/// ```
pub safe: bool,
pub unsafe_: bool,

/// Enables the
/// [strikethrough extension](https://github.github.com/gfm/#strikethrough-extension-)
Expand All @@ -200,6 +200,7 @@ pub struct ComrakOptions {
/// ```
/// # use comrak::{markdown_to_html, ComrakOptions};
/// let options = ComrakOptions {
/// unsafe_: true,
/// ext_tagfilter: true,
/// ..ComrakOptions::default()
/// };
Expand Down Expand Up @@ -247,6 +248,7 @@ pub struct ComrakOptions {
/// ```
/// # use comrak::{markdown_to_html, ComrakOptions};
/// let options = ComrakOptions {
/// unsafe_: true,
/// ext_tasklist: true,
/// ..ComrakOptions::default()
/// };
Expand Down
Loading

0 comments on commit 343cb69

Please sign in to comment.