Skip to content

Commit

Permalink
Merge pull request #466 from Veetaha/main
Browse files Browse the repository at this point in the history
Use `bon` for an infallible and compile-time-checked builder
  • Loading branch information
kivikakk authored Oct 22, 2024
2 parents 5a8e449 + f819456 commit b27a3dd
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 128 deletions.
84 changes: 44 additions & 40 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ shell-words = { version = "1.0", optional = true }
slug = "0.1.4"
emojis = { version = "0.6.2", optional = true }
arbitrary = { version = "1", optional = true, features = ["derive"] }
derive_builder = "0.20.0"
bon = "2.2.1"
caseless = "0.2.1"

[dev-dependencies]
Expand Down
7 changes: 3 additions & 4 deletions examples/s-expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const INDENT: usize = 4;
const CLOSE_NEWLINE: bool = false;

use comrak::nodes::{AstNode, NodeValue};
use comrak::{parse_document, Arena, ExtensionOptionsBuilder, Options};
use comrak::{parse_document, Arena, ExtensionOptions, Options};
use std::env;
use std::error::Error;
use std::fs::File;
Expand Down Expand Up @@ -74,7 +74,7 @@ fn iter_nodes<'a, W: Write>(
fn dump(source: &str) -> io::Result<()> {
let arena = Arena::new();

let extension = ExtensionOptionsBuilder::default()
let extension = ExtensionOptions::builder()
.strikethrough(true)
.tagfilter(true)
.table(true)
Expand All @@ -88,8 +88,7 @@ fn dump(source: &str) -> io::Result<()> {
.math_code(true)
.wikilinks_title_after_pipe(true)
.wikilinks_title_before_pipe(true)
.build()
.unwrap();
.build();

let opts = Options {
extension,
Expand Down
1 change: 1 addition & 0 deletions rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nightly
29 changes: 13 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
//! The `comrak` binary.
use comrak::{
adapters::SyntaxHighlighterAdapter, plugins::syntect::SyntectAdapter, Arena,
ExtensionOptionsBuilder, ListStyleType, Options, ParseOptionsBuilder, Plugins,
RenderOptionsBuilder,
adapters::SyntaxHighlighterAdapter, plugins::syntect::SyntectAdapter, Arena, ListStyleType,
Options, Plugins,
};
use std::boxed::Box;
use std::env;
Expand All @@ -14,6 +13,7 @@ use std::path::PathBuf;
use std::process;

use clap::{Parser, ValueEnum};
use comrak::{ExtensionOptions, ParseOptions, RenderOptions};

const EXIT_SUCCESS: i32 = 0;
const EXIT_PARSE_CONFIG: i32 = 2;
Expand Down Expand Up @@ -251,15 +251,14 @@ fn main() -> Result<(), Box<dyn Error>> {

let exts = &cli.extensions;

let mut extension = ExtensionOptionsBuilder::default();
extension
let extension = ExtensionOptions::builder()
.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)
.maybe_header_ids(cli.header_ids)
.footnotes(exts.contains(&Extension::Footnotes))
.description_lists(exts.contains(&Extension::DescriptionLists))
.multiline_block_quotes(exts.contains(&Extension::MultilineBlockQuotes))
Expand All @@ -270,23 +269,21 @@ fn main() -> Result<(), Box<dyn Error>> {
.underline(exts.contains(&Extension::Underline))
.spoiler(exts.contains(&Extension::Spoiler))
.greentext(exts.contains(&Extension::Greentext))
.front_matter_delimiter(cli.front_matter_delimiter);
.maybe_front_matter_delimiter(cli.front_matter_delimiter);

#[cfg(feature = "shortcodes")]
{
extension.shortcodes(cli.gemojis);
}
let extension = extension.shortcodes(cli.gemojis);

let extension = extension.build()?;
let extension = extension.build();

let parse = ParseOptionsBuilder::default()
let parse = ParseOptions::builder()
.smart(cli.smart)
.default_info_string(cli.default_info_string)
.maybe_default_info_string(cli.default_info_string)
.relaxed_tasklist_matching(cli.relaxed_tasklist_character)
.relaxed_autolinks(cli.relaxed_autolinks)
.build()?;
.build();

let render = RenderOptionsBuilder::default()
let render = RenderOptions::builder()
.hardbreaks(cli.hardbreaks)
.github_pre_lang(cli.github_pre_lang || cli.gfm)
.full_info_string(cli.full_info_string)
Expand All @@ -301,7 +298,7 @@ fn main() -> Result<(), Box<dyn Error>> {
.ignore_empty_links(cli.ignore_empty_links)
.gfm_quirks(cli.gfm_quirks || cli.gfm)
.tasklist_classes(cli.tasklist_classes)
.build()?;
.build();

let options = Options {
extension,
Expand Down
Loading

0 comments on commit b27a3dd

Please sign in to comment.