Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ComrakExtensionOptions non-exhaustive #305

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions examples/s-expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,18 @@ fn iter_nodes<'a, W: Write>(
fn dump(source: &str) -> io::Result<()> {
let arena = Arena::new();

let mut extension = ExtensionOptions::default();
extension.strikethrough = true;
extension.tagfilter = true;
extension.table = true;
extension.autolink = true;
extension.tasklist = true;
extension.superscript = true;
extension.footnotes = true;
extension.description_lists = true;

let opts = Options {
extension: ExtensionOptions {
strikethrough: true,
tagfilter: true,
table: true,
autolink: true,
tasklist: true,
superscript: true,
footnotes: true,
description_lists: true,
..ExtensionOptions::default()
},
extension,
..Options::default()
};

Expand Down
59 changes: 29 additions & 30 deletions fuzz/fuzz_targets/all_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,36 @@ use comrak::{
};

fuzz_target!(|s: &str| {
let mut extension = ExtensionOptions::default();
extension.strikethrough = true;
extension.tagfilter = true;
extension.table = true;
extension.autolink = true;
extension.tasklist = true;
extension.superscript = true;
extension.header_ids = Some("user-content-".to_string());
extension.footnotes = true;
extension.description_lists = true;
extension.front_matter_delimiter = Some("---".to_string());
extension.shortcodes = true;

let mut parse = ParseOptions::default();
parse.smart = true;
parse.default_info_string = Some("rust".to_string());
parse.relaxed_tasklist_matching = true;

let mut render = RenderOptions::default();
render.hardbreaks = true;
render.github_pre_lang = true;
render.full_info_string = true;
render.width = 80;
render.unsafe_ = true;
render.escape = true;
render.list_style = ListStyleType::Star;
render.sourcepos = true;

markdown_to_html(
s,
&Options {
extension: ExtensionOptions {
strikethrough: true,
tagfilter: true,
table: true,
autolink: true,
tasklist: true,
superscript: true,
header_ids: Some("user-content-".to_string()),
footnotes: true,
description_lists: true,
front_matter_delimiter: Some("---".to_string()),
shortcodes: true,
},
parse: ParseOptions {
smart: true,
default_info_string: Some("rust".to_string()),
relaxed_tasklist_matching: true,
},
render: RenderOptions {
hardbreaks: true,
github_pre_lang: true,
full_info_string: true,
width: 80,
unsafe_: true,
escape: true,
list_style: ListStyleType::Star,
sourcepos: true,
},
},
&Options { extension, parse, render },
);
});
10 changes: 3 additions & 7 deletions fuzz/fuzz_targets/cli_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@ use libfuzzer_sys::fuzz_target;

use comrak::{
markdown_to_html_with_plugins, plugins::syntect::SyntectAdapter, Plugins,
RenderPlugins,
};

// Note that we end up fuzzing Syntect here.

fuzz_target!(|s: &str| {
let adapter = SyntectAdapter::new("base16-ocean.dark");
let plugins = Plugins {
render: RenderPlugins {
codefence_syntax_highlighter: Some(&adapter),
..Default::default()
},
};

let mut plugins = Plugins::default();
plugins.render.codefence_syntax_highlighter = Some(&adapter);

markdown_to_html_with_plugins(s, &Default::default(), &plugins);
});
26 changes: 13 additions & 13 deletions fuzz/fuzz_targets/gfm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ use comrak::{markdown_to_html, ExtensionOptions, Options, RenderOptions};
// options are routinely used by Commonmarker users.

fuzz_target!(|s: &str| {
let mut extension = ExtensionOptions::default();
extension.strikethrough = true;
extension.tagfilter = true;
extension.table = true;
extension.autolink = true;

let mut render = RenderOptions::default();
render.hardbreaks = true;
render.github_pre_lang = true;
render.unsafe_ = true;

markdown_to_html(
s,
&Options {
extension: ExtensionOptions {
strikethrough: true,
tagfilter: true,
table: true,
autolink: true,
..Default::default()
},
extension,
parse: Default::default(),
render: RenderOptions {
hardbreaks: true,
github_pre_lang: true,
unsafe_: true,
..Default::default()
},
render,
},
);
});
28 changes: 14 additions & 14 deletions fuzz/fuzz_targets/gfm_footnotes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ use comrak::{markdown_to_html, ExtensionOptions, Options, RenderOptions};
// options are routinely used by Commonmarker users.

fuzz_target!(|s: &str| {
let mut extension = ExtensionOptions::default();
extension.strikethrough = true;
extension.tagfilter = true;
extension.table = true;
extension.autolink = true;
extension.footnotes = true;

let mut render = RenderOptions::default();
render.hardbreaks = true;
render.github_pre_lang = true;
render.unsafe_ = true;

markdown_to_html(
s,
&Options {
extension: ExtensionOptions {
strikethrough: true,
tagfilter: true,
table: true,
autolink: true,
footnotes: true,
..Default::default()
},
extension,
parse: Default::default(),
render: RenderOptions {
hardbreaks: true,
github_pre_lang: true,
unsafe_: true,
..Default::default()
},
render,
},
);
});
28 changes: 14 additions & 14 deletions fuzz/fuzz_targets/gfm_sourcepos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ use comrak::{markdown_to_html, ExtensionOptions, Options, RenderOptions};
// options are routinely used by Commonmarker users.

fuzz_target!(|s: &str| {
let mut extension = ExtensionOptions::default();
extension.strikethrough = true;
extension.tagfilter = true;
extension.table = true;
extension.autolink = true;

let mut render = RenderOptions::default();
render.hardbreaks = true;
render.github_pre_lang = true;
render.unsafe_ = true;
render.sourcepos = true;

markdown_to_html(
s,
&Options {
extension: ExtensionOptions {
strikethrough: true,
tagfilter: true,
table: true,
autolink: true,
..Default::default()
},
extension,
parse: Default::default(),
render: RenderOptions {
hardbreaks: true,
github_pre_lang: true,
unsafe_: true,
sourcepos: true,
..Default::default()
},
render,
},
);
});
56 changes: 28 additions & 28 deletions fuzz/fuzz_targets/quadratic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,19 @@ struct FuzzExtensionOptions {

impl FuzzExtensionOptions {
fn to_options(&self) -> ExtensionOptions {
ExtensionOptions {
strikethrough: self.strikethrough,
tagfilter: self.tagfilter,
table: self.table,
autolink: self.autolink,
tasklist: self.tasklist,
superscript: self.superscript,
footnotes: self.footnotes,
description_lists: self.description_lists,
shortcodes: self.shortcodes,
front_matter_delimiter: None,
header_ids: None,
}
let mut extension = ExtensionOptions::default();
extension.strikethrough = self.strikethrough;
extension.tagfilter = self.tagfilter;
extension.table = self.table;
extension.autolink = self.autolink;
extension.tasklist = self.tasklist;
extension.superscript = self.superscript;
extension.footnotes = self.footnotes;
extension.description_lists = self.description_lists;
extension.shortcodes = self.shortcodes;
extension.front_matter_delimiter = None;
extension.header_ids = None;
extension
}
}

Expand All @@ -220,11 +220,11 @@ struct FuzzParseOptions {

impl FuzzParseOptions {
fn to_options(&self) -> ParseOptions {
ParseOptions {
smart: self.smart,
default_info_string: None,
relaxed_tasklist_matching: self.relaxed_tasklist_matching,
}
let mut parse = ParseOptions::default();
parse.smart = self.smart;
parse.default_info_string = None;
parse.relaxed_tasklist_matching = self.relaxed_tasklist_matching;
parse
}
}

Expand All @@ -242,16 +242,16 @@ struct FuzzRenderOptions {

impl FuzzRenderOptions {
fn to_options(&self) -> RenderOptions {
RenderOptions {
hardbreaks: self.hardbreaks,
github_pre_lang: self.github_pre_lang,
full_info_string: self.full_info_string,
width: self.width,
unsafe_: self.unsafe_,
escape: self.escape,
list_style: self.list_style,
sourcepos: self.sourcepos,
}
let mut render = RenderOptions::default();
render.hardbreaks = self.hardbreaks;
render.github_pre_lang = self.github_pre_lang;
render.full_info_string = self.full_info_string;
render.width = self.width;
render.unsafe_ = self.unsafe_;
render.escape = self.escape;
render.list_style = self.list_style;
render.sourcepos = self.sourcepos;
render
}
}

Expand Down
63 changes: 34 additions & 29 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,36 +194,41 @@ fn main() -> Result<(), Box<dyn Error>> {

let exts = &cli.extensions;

let mut extension = ExtensionOptions::default();
extension.strikethrough = exts.contains(&Extension::Strikethrough) || cli.gfm;
extension.tagfilter = exts.contains(&Extension::Tagfilter) || cli.gfm;
extension.table = exts.contains(&Extension::Table) || cli.gfm;
extension.autolink = exts.contains(&Extension::Autolink) || cli.gfm;
extension.tasklist = exts.contains(&Extension::Tasklist) || cli.gfm;
extension.superscript = exts.contains(&Extension::Superscript);
extension.header_ids = cli.header_ids;
extension.footnotes = exts.contains(&Extension::Footnotes);
extension.description_lists = exts.contains(&Extension::DescriptionLists);
extension.front_matter_delimiter = cli.front_matter_delimiter;
#[cfg(feature = "shortcodes")]
{
extension.shortcodes = cli.gemojis;
}

let mut parse = ParseOptions::default();
parse.smart = cli.smart;
parse.default_info_string = cli.default_info_string;
parse.relaxed_tasklist_matching = cli.relaxed_tasklist_character;

let mut render = RenderOptions::default();
render.hardbreaks = cli.hardbreaks;
render.github_pre_lang = cli.github_pre_lang || cli.gfm;
render.full_info_string = cli.full_info_string;
render.width = cli.width;
render.unsafe_ = cli.unsafe_;
render.escape = cli.escape;
render.list_style = cli.list_style.into();
render.sourcepos = cli.sourcepos;

let options = Options {
extension: ExtensionOptions {
strikethrough: exts.contains(&Extension::Strikethrough) || cli.gfm,
tagfilter: exts.contains(&Extension::Tagfilter) || cli.gfm,
table: exts.contains(&Extension::Table) || cli.gfm,
autolink: exts.contains(&Extension::Autolink) || cli.gfm,
tasklist: exts.contains(&Extension::Tasklist) || cli.gfm,
superscript: exts.contains(&Extension::Superscript),
header_ids: cli.header_ids,
footnotes: exts.contains(&Extension::Footnotes),
description_lists: exts.contains(&Extension::DescriptionLists),
front_matter_delimiter: cli.front_matter_delimiter,
#[cfg(feature = "shortcodes")]
shortcodes: cli.gemojis,
},
parse: ParseOptions {
smart: cli.smart,
default_info_string: cli.default_info_string,
relaxed_tasklist_matching: cli.relaxed_tasklist_character,
},
render: RenderOptions {
hardbreaks: cli.hardbreaks,
github_pre_lang: cli.github_pre_lang || cli.gfm,
full_info_string: cli.full_info_string,
width: cli.width,
unsafe_: cli.unsafe_,
escape: cli.escape,
list_style: cli.list_style.into(),
sourcepos: cli.sourcepos,
},
extension,
parse,
render,
};

let syntax_highlighter: Option<&dyn SyntaxHighlighterAdapter>;
Expand Down
Loading