43 private static $instance;
56 if ( self::$instance === null ) {
57 if ( $config === null ) {
60 self::$instance =
new Splitter( $config );
62 return self::$instance;
71 self::$instance = null;
74 protected function __construct(
Config $config) {
75 $this->config = $config;
76 $this->buildSplitter();
86 public function split( &$text ) {
87 return preg_split( $this->splitter, $text, -1, PREG_SPLIT_DELIM_CAPTURE );
95 private function buildSplitter() {
96 if ( $this->config->skipTemplates )
100 $templatesDelimiter =
'{{(?>[^{}]|(?R))*}}|';
110 $templatesDelimiter =
'{{[^|]*?(?:(?:\[\[[^]]+]])?)[^|]*?(?:\|(?:\w+=)?|(?:}}))|\|\w+=|';
126 $headingsDelimiter = $this->config->parseHeadings ?
'' :
'^=+[^=]+=+$|';
128 $urlPattern =
'[a-z]+?\:\/\/(?:\S+\.)+\S+(?:\/.*)?';
129 $this->splitter =
'/(' .
132 $templatesDelimiter .
133 '^ .+?\n|\n .+?\n|\n .+?$|^ .+?$|' .
134 '<nowiki>.*?<.nowiki>|<code>.*?<\/code>|' .
135 '<pre>.*?<\/pre>|<html>.*?<\/html>|' .
136 '<script>.*?<\/script>|' .
137 '<syntaxhighlight.*?>.*?<\/syntaxhighlight>|' .
138 '<gallery>.*?<\/gallery>|' .
139 '<div.*?>|<\/div>|' .
140 '<span.*?>|<\/span>|' .
141 '<file>[^<]*<\/file>|' .
142 'style=".+?"|class=".+?"|' .
143 '<noautolinks>.*?<\/noautolinks>|' .
144 '\[' . $urlPattern .
'\s.+?\]|'. $urlPattern .
'(?=\s|$)|' .
145 '(?<=\b)\S+\@(?:\S+\.)+\S+(?=\b)' .
$splitter
The splitting expression that separates text to be parsed from text that must not be parsed...
$config
The LinkTitles configuration for this Splitter instance.
static singleton(Config &$config=null)
Gets the Splitter singleton; may build one with the given config or the default config if none is giv...
Holds LinkTitles configuration.
Caches a regular expression that delimits text to be parsed.
The LinkTitles class holds configuration for the LinkTitles extension.
split(&$text)
Splits a text into sections that may be linked and sections that may not be linked (e...
static invalidate()
Invalidates the singleton instance.