Skip to content

mehedimi/shortcode-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Shortcode Parser

WordPress flavored shortcode parser written in rust.

NB: Currently this crate is not for production use. If you need to experiment with this, feel free use as local crate.

Installation

[dependencies]
shortcode_parser = { path = "PATH_OF_THE_CRATE" }

or

[dependencies]
shortcode_parser = { git = "https://github.com/mehedimi/shortcode-parser", branch = "main" }

Example

Here is a simple [audio] shortcode parsed into html.

use shortcode_parser::Shortcode;

fn main() {
    let mut shortcode = Shortcode::new();

    shortcode.add("audio", |_content, attrs| {
        let tag_attrs = attrs
            .unwrap()
            .iter()
            .map(|attr| {
                return format!("{}=\"{}\"", attr.0, attr.1);
            })
            .collect::<Vec<_>>()
            .join(" ");

        return format!("<audio {}></audio>", tag_attrs);
    });

    let content = "This is a [audio class=\"audio\"] tag";

    shortcode.render(content.to_string());
    // Output: This is a <audio class="audio"></audio> tag
}

About

WordPress flavored shortcode parser written in rust

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages