Transform

Trait Transform 

Source
pub trait Transform {
    // Required methods
    fn transform_text<F>(self, f: F) -> Self
       where F: Fn(String) -> String;
    fn transform_image_urls<F>(self, f: F) -> Self
       where F: Fn(String) -> String;
    fn transform_link_urls<F>(self, f: F) -> Self
       where F: Fn(String) -> String;
    fn transform_autolink_urls<F>(self, f: F) -> Self
       where F: Fn(String) -> String;
    fn transform_code<F>(self, f: F) -> Self
       where F: Fn(String) -> String;
    fn transform_html<F>(self, f: F) -> Self
       where F: Fn(String) -> String;
    fn transform_with<T: Transformer>(self, transformer: T) -> Self;
    fn transform_if_doc<P, F>(self, predicate: P, transform: F) -> Self
       where P: Fn(&Self) -> bool,
             F: FnOnce(Self) -> Self,
             Self: Sized;
}
Expand description

High-level transformation methods for common use cases

Required Methods§

Source

fn transform_text<F>(self, f: F) -> Self
where F: Fn(String) -> String,

Transform all text elements with a function

§Example
use markdown_ppp::ast::*;
use markdown_ppp::ast_transform::Transform;

let doc = Document {
    blocks: vec![Block::Paragraph(vec![Inline::Text("hello".to_string())])],
};
let result = doc.transform_text(|text| text.to_uppercase());
Source

fn transform_image_urls<F>(self, f: F) -> Self
where F: Fn(String) -> String,

Transform all image URLs with a function

§Example
use markdown_ppp::ast::*;
use markdown_ppp::ast_transform::Transform;

let doc = Document {
    blocks: vec![Block::Paragraph(vec![Inline::Image(Image {
        destination: "/image.jpg".to_string(),
        title: None,
        alt: "test".to_string(),
    })])],
};
let result = doc.transform_image_urls(|url| {
    format!("https://cdn.example.com{}", url)
});

Transform all link URLs with a function

§Example
use markdown_ppp::ast::*;
use markdown_ppp::ast_transform::Transform;

let doc = Document {
    blocks: vec![Block::Paragraph(vec![Inline::Link(Link {
        destination: "http://example.com".to_string(),
        title: None,
        children: vec![Inline::Text("link".to_string())],
    })])],
};
let result = doc.transform_link_urls(|url| {
    url.replace("http://", "https://")
});

Transform all autolink URLs with a function

Source

fn transform_code<F>(self, f: F) -> Self
where F: Fn(String) -> String,

Transform all code spans with a function

Source

fn transform_html<F>(self, f: F) -> Self
where F: Fn(String) -> String,

Transform all HTML content with a function

Source

fn transform_with<T: Transformer>(self, transformer: T) -> Self

Apply a custom transformer

Source

fn transform_if_doc<P, F>(self, predicate: P, transform: F) -> Self
where P: Fn(&Self) -> bool, F: FnOnce(Self) -> Self, Self: Sized,

Transform conditionally based on a document predicate

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§