Initialize a new instance of the BBCode class.
Optional
library: BBCodeLibraryThe BBCode Library Class, It's possible to create your own via extending BBCodeLibrary
Protected
allowIf true, we use String.replaceAll() instead of htmlEncode().
Protected
allowWhether to allow Escape Characters in parsing to prevent parsing specific tags or not
Protected
currentThe current class (auto-computed).
Enable debugging mode
Protected
defaultsThe standard library (an instance of class BBCodeLibrary).
Protected
detectURLsShould we audo-detect URLs and convert them to links?
Protected
emailThe default template used with the default [email] tag.
Protected
emojiThe current list of emoji.
Protected
emojiThe host filesystem path to emoji (should be an absolute path).
Protected
emojiWhether or not to perform emoji-parsing.
Protected
emojiThis is a regex, precomputed from the list of emoji above.
Protected
emojiThe URL path to emoji (possibly a relative path).
Protected
escapeEncode HTML. POTENTIALLY DANGEROUS IF DISABLED. ONLY DISABLE IF YOU KNOW WHAT YOURE DOING.
Protected
ignoreIf true, newlines will be treated as normal whitespace.
Protected
lexerBBCodeLexer created when calling parse
Protected
limitHow accurate should we be if we're cutting off text?
Protected
limitWhat to add if the output is cut off.
Protected
localThe host filesystem path to local images (should be an absolute path).
Protected
localThe URL path to local images (possibly a relative path).
Protected
lostFor repair when tags are badly mis-nested.
Protected
maxMaximum number of emoji that can be used in parse
Protected
outputThe maximum number of text characters to output.
Protected
plainDon't output tags: Just output text/whitespace/newlines only.
Protected
postHow to trim the whitespace at the end of the input.
Protected
preHow to trim the whitespace at the start of the input.
Protected
quoteThe default template used with the default [quote] tag.
Protected
rootThe root container class.
Protected
ruleThe default HTML to output for a [rule] tag.
Protected
stackThe token stack is used to perform a document-tree walk
Protected
startAn associative array of locations of start tags on the stack.
Protected
tagSet to '[', '<', '{', or '('.
Protected
tagList of tag rules currently in use.
Protected
textThe number of text characters output so far.
Protected
urlWhat to convert auto-detected URLs into.
Protected
urlIf non-false, [url] tags will use this target and no other.
Protected
urlIf true, [url] tags can accept a target="..." parameter.
Protected
urlThe default template used with the default [url] tag.
Protected
wasSet to true if the output was cut off.
Protected
wikiURL prefix used for [[wiki]] links.
Protected
wikiThe default template used when rendering wiki links.
Static
BBCODE_Current release date
Static
BBCODE_Current version number
Protected
autoSearch through the input for URLs, or things that are URL-like and replace with anchor tags.
We search for several possibilities here:
First format (HTTP/HTTPS/FTP):
<"http://" or "https://" or "ftp://">
Second format (implicit HTTP):
Third format (e-mail):
In short, we look for domains and protocols, and if we find them, we consume any paths or parameters after them, stopping at the first whitespace.
We use the same split-and-match technique used by the lexer and the emoji parser, since it's the fastest way to perform tokenization in PHP.
Once we find the URL, we convert it according to the rule given in this.urlPattern.
Note that the input string is plain text, not HTML or BBCode. The return value must be an array of alternating pairs of plain text (even indexes) and HTML (odd indexes).
The string to detect the URLs in.
Returns an array in the form [text, anchor, text, anchor, ...]
.
Protected
cleanupWSByProtected
cleanupWSByRead tokens from the given position in the stack, going forward as we match the rules in the given pattern. Returns the first position after the pattern.
Pattern for cleanup
Position to start the cleanup
Stack to cleanup
Protected
cleanupWSByWalk down from the top of the stack, and remove whitespace/newline tokens from the top according to the rules in the given pattern.
Pattern for cleanup
Array to cleanup
Protected
collectCollect a series of text strings from a token stack and return them as a single string.
The token stack.
The starting index in array to process.
Returns the stack text from all the elements in the stack.
Protected
collectCollect a series of text strings from a token stack in reverse and return them as a single string.
The token stack.
The starting index in array to process.
The ending index in array to process.
Returns the stack text from all the elements in the stack.
Protected
computeProtected
doFormat an enhanced tag, which is like a simple tag but uses a short HTML template for its formatting instead.
The variables you may use are the parameters of the tag, and '_default' for its default value, '_name' for its name, and 'content' for its contents (body). Note that in enhanced mode, the tag parameters' keys must match [a-zA-Z0-9:-]+, that is, alphanumeric, with underscore, colon, or hyphen.
Protected
doProcess a tag:
action
is one of BBCODE_CHECK or BBCODE_OUTPUT. During BBCODE_CHECK, contents
will always be the empty string, and this function should return true if
the tag is legal based on the available information; or it should return
false if the tag is illegal. During BBCODE_OUTPUT, contents
will always
be valid, and this function should return HTML.
tagName
is the name of the tag being processed.
defaultValue
is the default value given; for example, in [url=foo], it's "foo"+
This value has NOT been passed through htmlEncode().
params
is an array of key: value parameters associated with the tag; for example,
in [emoji src=smile alt=:-)], it's ['src': "smile", 'alt': ":-)"]
.
These keys and values have NOT beel passed through htmlEncode().
contents
is the body of the tag during BBCODE_OUTPUT. For example, in
[b]Hello[/b], it's "Hello"+ THIS VALUE IS ALWAYS HTML, not BBCode.
For BBCODE_CHECK, this must return true (if the tag definition is valid) or false (if the tag definition is not valid); for BBCODE_OUTPUT, this function must return HTML output.
Protected
dumpOptional
array: StackType[]Fill an HTML template using variable inserts, which look like this: {$variable} or {$variable/flags} or even {$myarray.george.father/flags}
You may use any variable provided in the parameter array; and you may use the special dot (.) operator to access members of array variables or of object variables.
You may add formatting flags to the variable to control how the text parameters are cleaned up. For example, {$variable/u} causes the variable to be urlencoded(). The available flags are:
v - Verbatim. Do not apply any formatting to the variable; use its exact text, however the user provided it. This overrides all other flags.
b - Apply basename(). n - Apply nl2br(). t - Trim. This causes all initial and trailing whitespace to be trimmed (removed). w - Clean up whitespace. This causes all non-newline whitespace, such as control codes and tabs, to be collapsed into individual space characters.
e - Apply HTMLEncode(). h - Apply htmlEncode(). k - Apply Wikify(). u - Apply urlencode().
Note that only one of the e, h, k, or u "formatting flags" may be specified; these flags are mutually-exclusive.
Protected
finishProperly encode tag content.
Go through a string containing plain text and do three things on it: Replace < and > and & and " with HTML-safe equivalents, and replace emoji like :-) with tags, and replace any embedded URLs with ... links.
The string to process.
Returns the processed version of string.
Protected
generateOutput everything on the stack from pos to the top, inclusive, as plain text, and return it.
This is a little more complicated than necessary, because if we encounter end-tag-optional tags in here, they're not to be outputted as plain text: They're fully legit, and need to be processed with the plain text after them as their body. This returns a list of tokens in the REVERSE of output order.
The position to start on the stack.
Returns an array of output tokens.
Get how precise guessTextLength should be
Get the current preTrim value, see setPostTrim
Get the current preTrim value, see setPreTrim
Escape HTML characters.
This function is used to wrap around calls to htmlEncode() for plain text so that you can add your own text-evaluation code if you want. For example, you might want to make foo turn into foo, or something like that. The default behavior is just to call htmlEncode() and be done with it, but if you inherit and override this function, you can do pretty much anything you want.
Note that htmlEncode() is still used directly for doing things like cleaning up URLs in tags; this function is applied to plain text only.
The string to replace.
Returns an encoded version of string.
Returns true if the given string is a valid e-mail address.
This allows everything that RFC821 allows, including e-mail addresses that make no sense.
The email address to validate.
Returns true if string is an email address or false otherwise.
Returns true if the given string is a valid URL.
If emailToo is false, this checks for:
http :// domain [:port] [/] [any single-line string]
https :// domain [:port] [/] [any single-line string]
ftp :// domain [:port] [/] [any single-line string]
If emailToo is true (the default), this also allows the mailto protocol:
mailto : name @ domain
The URL to validate.
Whether or not a mailto: link is also valid.
Returns true if string is a valid URL or false otherwise.
Protected
limitWe have a string that's too long, so chop it off at a suitable break so that it's
no longer than limit
characters, if at all possible (if there's nowhere to break
before that, we just chop at limit
).
String to limit text length
Maximum text length
Parse a BBCode string and convert it into HTML.
Core parser. This is where all the magic begins and ends. Core parsing routine. Call with a BBCode string, and it returns an HTML string.
The BBCode string to parse.
Returns the HTML version of string.
Protected
parseProtected
parseProtected
processReplace the emoji codes in a string with image tags.
Go through a string containing plain text and do two things on it: Replace < and > and & and " with HTML-safe equivalents, and replace emoji like :-) with tags.
The string to process.
Returns the processed version of string.
Protected
processProtected
processProtected
rebuildProtected
rewindWe're transitioning into a class that's not allowed inside the current one (like they tried to put a [center] tag inside a [b] tag), so we need to unwind the stack, outputting content until we're inside a valid state again. To do this, we need to walk back down the stack, searching for a class that's in the given list; when we find one, we output everything above it. Then we output everything on the stack from the given height to the top, inclusive, and pop everything in that range. This leaves a BBCODE_TEXT element on the stack that is the fully-outputted version of the content, and its class will be the same as that of the stack element before it (or root_class if there is no element before it).
This returns true if the stack could be rewound to a safe state, or false if no such "safe state" existed.
Sets if URL detection should be abled, if enabled it will automatically convert urls into tags in html
If auto URL detection should be enabled
true
Set how precise guessTextLength should be
Precision
Set Log Level, 0 is all 1 is debug 2 is info 3 is warn (default) 4 is error 5 is none
Controls how (non-newline) whitespace and newlines are treated when placed in proximity to this tag or to its end tag. For each setting, you use a simple pattern comprised of the following characters to describe what to remove:
Common Examples:
Controls how (non-newline) whitespace and newlines are treated when placed in proximity to this tag or to its end tag. For each setting, you use a simple pattern comprised of the following characters to describe what to remove:
Common Examples:
Protected
updateIf an end-tag is required/optional but missing, we simulate it here so that the rule handlers still see a valid '_endtag' parameter. This way, all rules always see valid '_endtag' parameters except for rules for isolated tags.
This takes an arbitrary string and makes it a wiki-safe string: It converts all characters to be within [a-zA-Z0-9'",.:_-] by converting everything else to _ characters, compacts multiple _ characters together, and trims initial and trailing _ characters. So, for example, [[Washington, D.C.]] would become "Washington_D.C+", safe to pass through a URL or anywhere else. All characters in the extended-character range (0x7F-0xFF) will be URL-encoded.
Generated using TypeDoc
This is the BBCode Library class, it is responsible for most of the internal parsing of the input into HTML.