https://github.com/mehedimi/shortcode-parser
WordPress flavored shortcode parser written in rust
https://github.com/mehedimi/shortcode-parser
rust shortcode wp wp-shorcode
Last synced: 11 months ago
JSON representation
WordPress flavored shortcode parser written in rust
- Host: GitHub
- URL: https://github.com/mehedimi/shortcode-parser
- Owner: mehedimi
- Created: 2023-04-09T15:04:48.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-21T23:38:55.000Z (over 2 years ago)
- Last Synced: 2025-01-18T06:28:53.712Z (about 1 year ago)
- Topics: rust, shortcode, wp, wp-shorcode
- Language: Rust
- Homepage: https://github.com/mehedimi/shortcode-parser
- Size: 11.7 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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
```toml
[dependencies]
shortcode_parser = { path = "PATH_OF_THE_CRATE" }
```
or
```toml
[dependencies]
shortcode_parser = { git = "https://github.com/mehedimi/shortcode-parser", branch = "main" }
```
### Example
Here is a simple `[audio]` shortcode parsed into html.
```rust
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::>()
.join(" ");
return format!("", tag_attrs);
});
let content = "This is a [audio class=\"audio\"] tag";
shortcode.render(content.to_string());
// Output: This is a tag
}
```