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§
Sourcefn transform_text<F>(self, f: F) -> Self
fn transform_text<F>(self, f: F) -> Self
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());Sourcefn transform_image_urls<F>(self, f: F) -> Self
fn transform_image_urls<F>(self, f: F) -> Self
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)
});Sourcefn transform_link_urls<F>(self, f: F) -> Self
fn transform_link_urls<F>(self, f: F) -> Self
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://")
});Sourcefn transform_autolink_urls<F>(self, f: F) -> Self
fn transform_autolink_urls<F>(self, f: F) -> Self
Transform all autolink URLs with a function
Sourcefn transform_code<F>(self, f: F) -> Self
fn transform_code<F>(self, f: F) -> Self
Transform all code spans with a function
Sourcefn transform_html<F>(self, f: F) -> Self
fn transform_html<F>(self, f: F) -> Self
Transform all HTML content with a function
Sourcefn transform_with<T: Transformer>(self, transformer: T) -> Self
fn transform_with<T: Transformer>(self, transformer: T) -> Self
Apply a custom transformer
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.