Skip to content

Commit 42eb442

Browse files
authored
Merge pull request #675 from kivikakk/push-xsrxvrqonwlk
Factor out inlines::Scanner, and Other Such Cleanups.
2 parents a935ef6 + 27642a2 commit 42eb442

File tree

12 files changed

+754
-594
lines changed

12 files changed

+754
-594
lines changed

fuzz/fuzz_targets/quadratic.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ struct FuzzExtensionOptions {
200200
spoiler: bool,
201201
greentext: bool,
202202
alerts: bool,
203+
inline_footnotes: bool,
203204
}
204205

205206
impl FuzzExtensionOptions {
@@ -212,6 +213,7 @@ impl FuzzExtensionOptions {
212213
tasklist: self.tasklist,
213214
superscript: self.superscript,
214215
footnotes: self.footnotes,
216+
inline_footnotes: self.inline_footnotes,
215217
description_lists: self.description_lists,
216218
multiline_block_quotes: self.multiline_block_quotes,
217219
math_dollars: self.math_dollars,

src/cm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::cmp::max;
22
use std::collections::HashSet;
33
use std::fmt::{self, Write};
44
use std::str;
5-
use typed_arena::Arena;
65

76
use crate::ctype::{isalpha, isdigit, ispunct, ispunct_char, isspace, isspace_char};
87
use crate::node_matches;
@@ -15,6 +14,7 @@ use crate::parser::options::{Options, Plugins, WikiLinksMode};
1514
use crate::parser::shortcodes::NodeShortCode;
1615
use crate::scanners;
1716
use crate::strings::trim_start_match;
17+
use crate::Arena;
1818

1919
/// Formats an AST as CommonMark, modified by the given options.
2020
pub fn format_document<'a>(

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,12 @@ pub use html::Anchorizer;
9494
pub use nodes::Node;
9595
pub use parser::options;
9696
pub use parser::{parse_document, Options, ResolvedReference};
97-
pub use typed_arena::Arena;
9897
pub use xml::format_document as format_xml;
9998
pub use xml::format_document_with_plugins as format_xml_with_plugins;
10099

100+
/// Convenience type alias for arena used to hold nodes.
101+
pub type Arena<'a> = typed_arena::Arena<nodes::AstNode<'a>>;
102+
101103
#[deprecated(
102104
since = "0.45.0",
103105
note = "use `comrak::options::Extension` instead of `comrak::ExtensionOptions`"

src/nodes.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,12 @@ impl std::fmt::Display for Sourcepos {
724724
}
725725
}
726726

727+
impl From<(LineColumn, LineColumn)> for Sourcepos {
728+
fn from((start, end): (LineColumn, LineColumn)) -> Sourcepos {
729+
Sourcepos { start, end }
730+
}
731+
}
732+
727733
impl From<(usize, usize, usize, usize)> for Sourcepos {
728734
fn from(sp: (usize, usize, usize, usize)) -> Sourcepos {
729735
Sourcepos {
@@ -827,7 +833,7 @@ impl Ast {
827833
///
828834
/// ```rust
829835
/// # use comrak::{nodes::{AstNode, NodeValue}, Arena};
830-
/// # let arena = Arena::<AstNode>::new();
836+
/// # let arena = Arena::new();
831837
/// let node_in_arena = arena.alloc(NodeValue::Document.into());
832838
/// ```
833839
pub type AstNode<'a> = arena_tree::Node<'a, RefCell<Ast>>;

src/parser/autolink.rs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1+
use std::borrow::Cow;
12
use std::str;
2-
use typed_arena::Arena;
33
use unicode_categories::UnicodeCategories;
44

55
use crate::character_set::character_set;
66
use crate::ctype::{isalnum, isalpha, isspace};
7-
use crate::nodes::{AstNode, Node, NodeLink, NodeValue, Sourcepos};
8-
use crate::parser::inlines::Subject;
9-
use crate::parser::{inlines::make_inline, Spx};
7+
use crate::nodes::{Node, NodeLink, NodeValue, Sourcepos};
8+
use crate::parser::inlines::{make_inline, Subject};
9+
use crate::parser::Spx;
10+
use crate::Arena;
1011

1112
pub(crate) fn process_email_autolinks<'a>(
12-
arena: &'a Arena<AstNode<'a>>,
13+
arena: &'a Arena<'a>,
1314
node: Node<'a>,
14-
contents: &mut String,
15+
contents: &mut Cow<'static, str>,
1516
relaxed_autolinks: bool,
1617
sourcepos: &mut Sourcepos,
1718
spx: &mut Spx,
@@ -69,7 +70,7 @@ pub(crate) fn process_email_autolinks<'a>(
6970

7071
let nsp_end_col = spx.consume(skip);
7172

72-
contents.truncate(i);
73+
contents.to_mut().truncate(i);
7374

7475
let nsp: Sourcepos = (
7576
sourcepos.end.line,
@@ -95,26 +96,20 @@ pub(crate) fn process_email_autolinks<'a>(
9596
post.insert_after(after);
9697

9798
let after_ast = &mut after.data_mut();
98-
process_email_autolinks(
99-
arena,
100-
after,
101-
match after_ast.value {
102-
NodeValue::Text(ref mut t) => t.to_mut(),
103-
_ => unreachable!(),
104-
},
105-
relaxed_autolinks,
106-
&mut asp,
107-
spx,
108-
);
99+
let NodeValue::Text(ref mut text) = after_ast.value else {
100+
unreachable!();
101+
};
102+
process_email_autolinks(arena, after, text, relaxed_autolinks, &mut asp, spx);
109103
after_ast.sourcepos = asp;
110104
}
111105

112106
return;
113107
}
114108
}
115109
}
110+
116111
fn email_match<'a>(
117-
arena: &'a Arena<AstNode<'a>>,
112+
arena: &'a Arena<'a>,
118113
contents: &str,
119114
i: usize,
120115
relaxed_autolinks: bool,
@@ -231,7 +226,7 @@ pub fn www_match<'a>(
231226
subject: &mut Subject<'a, '_, '_, '_, '_, '_>,
232227
) -> Option<(Node<'a>, usize, usize)> {
233228
const WWW_DELIMS: [bool; 256] = character_set!(b"*_~([");
234-
let i = subject.pos;
229+
let i = subject.scanner.pos;
235230
let relaxed_autolinks = subject.options.parse.relaxed_autolinks;
236231
let bytes = subject.input.as_bytes();
237232

@@ -397,7 +392,7 @@ pub fn url_match<'a>(
397392
) -> Option<(Node<'a>, usize, usize)> {
398393
const SCHEMES: [&str; 3] = ["http", "https", "ftp"];
399394

400-
let i = subject.pos;
395+
let i = subject.scanner.pos;
401396
let relaxed_autolinks = subject.options.parse.relaxed_autolinks;
402397
let bytes = subject.input.as_bytes();
403398
let size = subject.input.len();

0 commit comments

Comments
 (0)