Skip to content

Commit 97906f4

Browse files
committed
correct doc tests.
1 parent 8446dd5 commit 97906f4

File tree

4 files changed

+26
-57
lines changed

4 files changed

+26
-57
lines changed

src/html.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub enum ChildRendering {
123123
/// context.write_str(if entering { "<b>" } else { "</b>" })?;
124124
/// },
125125
/// NodeValue::Image(ref nl) => |context, node, entering| {
126-
/// assert!(node.get(arena).sourcepos == (3, 1, 3, 18).into());
126+
/// assert!(node.get(context.arena).sourcepos == (3, 1, 3, 18).into());
127127
/// if entering {
128128
/// context.write_str(&nl.url.to_uppercase())?;
129129
/// return Ok(ChildRendering::Skip);
@@ -132,15 +132,15 @@ pub enum ChildRendering {
132132
/// });
133133
///
134134
/// let options = Options::default();
135-
/// let arena = Arena::new();
135+
/// let mut arena = Arena::new();
136136
/// let doc = parse_document(
137-
/// &arena,
137+
/// &mut arena,
138138
/// "_Hello_, **world**.\n\n![title](/img.png)",
139139
/// &options,
140140
/// );
141141
///
142142
/// let mut result: String = String::new();
143-
/// let converted_count = CustomFormatter::format_document(doc, &options, &mut result, 0).unwrap();
143+
/// let converted_count = CustomFormatter::format_document(&arena, doc, &options, &mut result, 0).unwrap();
144144
///
145145
/// assert_eq!(
146146
/// result,

src/lib.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,28 @@
1919
//! use comrak::nodes::{AstNode, NodeValue};
2020
//!
2121
//! # fn main() {
22-
//! let arena = Arena::new();
22+
//! let mut arena = Arena::new();
2323
//!
2424
//! let root = parse_document(
25-
//! &arena,
26-
//! "This is my input.\n\n1. Also [my](#) input.\n2. Certainly *my* input.\n",
25+
//! &mut arena,
26+
//! "Hello, pretty world!\n\n1. Do you like [pretty](#) paintings?\n2. Or *pretty* music?\n",
2727
//! &Options::default());
2828
//!
29-
//! for node in root.descendants() {
30-
//! if let NodeValue::Text(ref mut text) = node.data.borrow_mut().value {
31-
//! *text = text.replace("my", "your");
29+
//! for node in root.descendants(&arena).collect::<Vec<_>>() {
30+
//! if let NodeValue::Text(ref mut text) = node.get_mut(&mut arena).value {
31+
//! *text = text.replace("pretty", "beautiful");
3232
//! }
3333
//! }
3434
//!
3535
//! let mut html = String::new();
36-
//! format_html(root, &Options::default(), &mut html).unwrap();
36+
//! format_html(&arena, root, &Options::default(), &mut html).unwrap();
3737
//!
3838
//! assert_eq!(
3939
//! &html,
40-
//! "<p>This is your input.</p>\n\
40+
//! "<p>Hello, beautiful world!</p>\n\
4141
//! <ol>\n\
42-
//! <li>Also <a href=\"#\">your</a> input.</li>\n\
43-
//! <li>Certainly <em>your</em> input.</li>\n\
42+
//! <li>Do you like <a href=\"#\">beautiful</a> paintings?</li>\n\
43+
//! <li>Or <em>beautiful</em> music?</li>\n\
4444
//! </ol>\n");
4545
//! # }
4646
//! ```

src/nodes.rs

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -663,38 +663,7 @@ impl Ast {
663663

664664
/// The type of a node within the document.
665665
///
666-
/// It is bound by the lifetime `'a`, which corresponds to the `Arena` nodes are
667-
/// allocated in. Child `Ast`s are wrapped in `RefCell` for interior mutability.
668-
///
669-
/// You can construct a new `AstNode` from a `NodeValue` using the `From` trait:
670-
///
671-
/// ```no_run
672-
/// # use comrak::nodes::{AstNode, NodeValue};
673-
/// let root = AstNode::from(NodeValue::Document);
674-
/// ```
675-
///
676-
/// Note that no sourcepos information is given to the created node. If you wish
677-
/// to assign sourcepos information, use the `From` trait to create an `AstNode`
678-
/// from an `Ast`:
679-
///
680-
/// ```no_run
681-
/// # use comrak::nodes::{Ast, AstNode, NodeValue};
682-
/// let root = AstNode::from(Ast::new(
683-
/// NodeValue::Paragraph,
684-
/// (4, 1).into(), // start_line, start_col
685-
/// ));
686-
/// ```
687-
///
688-
/// Adjust the `end` position manually.
689-
///
690-
/// For practical use, you'll probably need it allocated in an `Arena`, in which
691-
/// case you can use `.into()` to simplify creation:
692-
///
693-
/// ```no_run
694-
/// # use comrak::{nodes::{AstNode, NodeValue}, Arena};
695-
/// # let arena = Arena::<AstNode>::new();
696-
/// let node_in_arena = arena.alloc(NodeValue::Document.into());
697-
/// ```
666+
/// TODO
698667
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
699668
pub struct AstNode(NodeId);
700669

src/parser/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,11 @@ pub struct ExtensionOptions<'c> {
392392
/// use comrak::parse_document;
393393
/// let mut options = Options::default();
394394
/// options.extension.front_matter_delimiter = Some("---".to_owned());
395-
/// let arena = Arena::new();
395+
/// let mut arena = Arena::new();
396396
/// let input ="---\nlayout: post\n---\nText\n";
397-
/// let root = parse_document(&arena, input, &options);
397+
/// let root = parse_document(&mut arena, input, &options);
398398
/// let mut buf = String::new();
399-
/// format_commonmark(&root, &options, &mut buf);
399+
/// format_commonmark(&arena, root, &options, &mut buf);
400400
/// assert_eq!(buf, input);
401401
/// ```
402402
pub front_matter_delimiter: Option<String>,
@@ -876,17 +876,17 @@ pub struct RenderOptions {
876876
/// ```
877877
/// # use comrak::{parse_document, Options, format_commonmark};
878878
/// # fn main() {
879-
/// # let arena = indextree::Arena::new();
879+
/// # let mut arena = indextree::Arena::new();
880880
/// let mut options = Options::default();
881-
/// let node = parse_document(&arena, "hello hello hello hello hello hello", &options);
881+
/// let node = parse_document(&mut arena, "hello hello hello hello hello hello", &options);
882882
/// let mut output = String::new();
883-
/// format_commonmark(node, &options, &mut output).unwrap();
883+
/// format_commonmark(&arena, node, &options, &mut output).unwrap();
884884
/// assert_eq!(output,
885885
/// "hello hello hello hello hello hello\n");
886886
///
887887
/// options.render.width = 20;
888888
/// let mut output = String::new();
889-
/// format_commonmark(node, &options, &mut output).unwrap();
889+
/// format_commonmark(&arena, node, &options, &mut output).unwrap();
890890
/// assert_eq!(output,
891891
/// "hello hello hello\nhello hello hello\n");
892892
/// # }
@@ -1035,18 +1035,18 @@ pub struct RenderOptions {
10351035
/// ```rust
10361036
/// # use std::str;
10371037
/// # use comrak::{Arena, Options, format_commonmark, parse_document};
1038-
/// let arena = Arena::new();
1038+
/// let mut arena = Arena::new();
10391039
/// let mut options = Options::default();
10401040
/// let input = "```\nhello\n```\n";
1041-
/// let root = parse_document(&arena, input, &options);
1041+
/// let root = parse_document(&mut arena, input, &options);
10421042
///
10431043
/// let mut buf = String::new();
1044-
/// format_commonmark(&root, &options, &mut buf);
1044+
/// format_commonmark(&arena, root, &options, &mut buf);
10451045
/// assert_eq!(buf, " hello\n");
10461046
///
10471047
/// buf.clear();
10481048
/// options.render.prefer_fenced = true;
1049-
/// format_commonmark(&root, &options, &mut buf);
1049+
/// format_commonmark(&arena, root, &options, &mut buf);
10501050
/// assert_eq!(buf, "```\nhello\n```\n");
10511051
/// ```
10521052
#[cfg_attr(feature = "bon", builder(default))]

0 commit comments

Comments
 (0)