pub struct BBCode {
pub matchers: Arc<Vec<MatchInfo>>,
}Expand description
The main bbcode system. You create this to parse bbcode! Inexpensive clones, since fields are all reference counted.
Fields§
§matchers: Arc<Vec<MatchInfo>>Supply this!
Implementations§
Source§impl BBCode
impl BBCode
Sourcepub fn default() -> Result<Self, Error>
pub fn default() -> Result<Self, Error>
Get a default bbcode parser. Should hopefully have reasonable defaults!
Sourcepub fn from_matchers(matchers: Vec<MatchInfo>) -> Self
pub fn from_matchers(matchers: Vec<MatchInfo>) -> Self
Create a BBCode parser from the given list of matchers. If you’re building a fully custom set of tags, use this endpoint
Sourcepub fn from_config(
config: BBCodeTagConfig,
additional_matchers: Option<Vec<MatchInfo>>,
) -> Result<Self, Error>
pub fn from_config( config: BBCodeTagConfig, additional_matchers: Option<Vec<MatchInfo>>, ) -> Result<Self, Error>
Create a BBCode parser from a config, using standard tags (plus any extras specified in the config). If you
want a tweaked BBCode parser but based off reasonable defaults, use this. BBCode::default() is the same
as calling this with BBCodeTagConfig::default(). You can also optionally pass in more tags you wish to support
(this is done because the order of tag matchers is important, and the “standard” configuration requires some internal
matchers to come after yours)
Sourcepub fn to_consumer(&mut self)
pub fn to_consumer(&mut self)
Convert the current bbcode instance to one which consumes all tags it used to parse. The raw text SHOULD be left untouched (I think?)
Sourcepub fn get_tagregex(
tag: &'static str,
open_consume: Option<(i32, i32)>,
close_consume: Option<(i32, i32)>,
) -> (String, String)
pub fn get_tagregex( tag: &'static str, open_consume: Option<(i32, i32)>, close_consume: Option<(i32, i32)>, ) -> (String, String)
Produce the two basic regexes (open and close) for bbcode tags
Sourcepub fn add_tagmatcher(
matchers: &mut Vec<MatchInfo>,
tag: &'static str,
info: ScopeInfo,
open_consume: Option<(i32, i32)>,
close_consume: Option<(i32, i32)>,
) -> Result<(), Error>
pub fn add_tagmatcher( matchers: &mut Vec<MatchInfo>, tag: &'static str, info: ScopeInfo, open_consume: Option<(i32, i32)>, close_consume: Option<(i32, i32)>, ) -> Result<(), Error>
Add the open and close matches to the given vector for the given tag (you must construct ScopeInfo yourself). open_consume and close_consume are the amount of newlines to take before and after the open and close tag
pub fn plaintext_ids() -> Vec<&'static str>
Sourcepub fn parse(&self, input: &str) -> String
pub fn parse(&self, input: &str) -> String
Main function! You call this to parse your raw bbcode! It also escapes html stuff so it can be used raw! Current version keeps newlines as-is and it’s expected you use pre-wrap, later there may be modes for more standard implementations
Sourcepub fn parse_profiled_opt(&mut self, input: &str, _name: String) -> String
pub fn parse_profiled_opt(&mut self, input: &str, _name: String) -> String
This MAY OR MAY NOT profile, depending on your featureset!