TransformPipeline

Struct TransformPipeline 

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

Builder for creating transformation pipelines

Allows chaining multiple transformations together with conditional logic.

§Example

use markdown_ppp::ast::*;
use markdown_ppp::ast_transform::TransformPipeline;

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

let result = TransformPipeline::new()
    .transform_text(|s| s.trim().to_string())
    .transform_image_urls(|url| format!("https://cdn.example.com{}", url))
    .apply(doc);

Implementations§

Source§

impl TransformPipeline

Source

pub fn new() -> Self

Create a new empty pipeline

Source

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

Transform all text elements

Source

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

Transform all image URLs

Transform all link URLs

Transform all autolink URLs

Source

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

Transform all code spans

Source

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

Transform all HTML content

Source

pub fn transform_with<T: Transformer + 'static>(self, transformer: T) -> Self

Apply a custom transformer

Source

pub fn custom<F>(self, f: F) -> Self
where F: FnOnce(Document) -> Document + 'static,

Add a custom transformation function

Source

pub fn when<F>(self, condition: bool, builder: F) -> Self

Conditionally apply a sub-pipeline

Source

pub fn when_doc<P, F>(self, predicate: P, builder: F) -> Self
where P: Fn(&Document) -> bool + 'static, F: FnOnce(TransformPipeline) -> TransformPipeline + 'static,

Apply transformations only if the document matches a predicate

Source

pub fn remove_empty_paragraphs(self) -> Self

Remove empty paragraphs

Source

pub fn remove_empty_text(self) -> Self

Remove empty text elements

Source

pub fn normalize_whitespace(self) -> Self

Normalize whitespace

Source

pub fn filter_blocks<F>(self, predicate: F) -> Self
where F: Fn(&Block) -> bool + 'static,

Filter blocks by predicate

Source

pub fn apply(self, doc: Document) -> Document

Apply all transformations in the pipeline

Trait Implementations§

Source§

impl Default for TransformPipeline

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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.