json2arkdown

Struct MarkdownRenderer

Source
pub struct MarkdownRenderer { /* private fields */ }
Expand description

A struct to handle rendering JSON into Markdown format.

The MarkdownRenderer provides customizable options for indentation and depth handling.

Implementations§

Source§

impl MarkdownRenderer

Source

pub fn new(indent_spaces: usize, depth_increment: usize) -> Self

Creates a new MarkdownRenderer.

§Arguments
  • indent_spaces - Number of spaces to use for indentation. Always try to use 1 at first.
  • depth_increment - Increment to apply for nested structures. Always try to use 2 at first

You can experiment with different values, it still not perfect.

§Examples
let renderer = MarkdownRenderer::new(1, 2);
Examples found in repository?
examples/basic.rs (line 7)
4
5
6
7
8
9
10
11
fn main() {
    let json: Value = serde_json::from_str(r#"{"title": "My Project"}"#).unwrap();

    let renderer = MarkdownRenderer::new(1, 2);
    let markdown = renderer.render(&json);

    println!("{}", markdown);
}
Source

pub fn render(&self, json: &Value) -> String

Renders a JSON value into a Markdown string.

§Arguments
  • json - The JSON value to render.
§Returns

A String containing the rendered Markdown.

§Examples
let renderer = MarkdownRenderer::new(1, 2);
let json = serde_json::json!({"title": "My Document"});
let markdown = renderer.render(&json);
assert_eq!(markdown, "");
Examples found in repository?
examples/basic.rs (line 8)
4
5
6
7
8
9
10
11
fn main() {
    let json: Value = serde_json::from_str(r#"{"title": "My Project"}"#).unwrap();

    let renderer = MarkdownRenderer::new(1, 2);
    let markdown = renderer.render(&json);

    println!("{}", markdown);
}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.