1027
+ − 1
<?php
+ − 2
+ − 3
/*
+ − 4
* Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
1081
745200a9cc2a
Fixed some upgrade bugs; added support for choosing one's own date/time formats; rebrand as 1.1.7
Dan
diff
changeset
+ − 5
* Copyright (C) 2006-2009 Dan Fuhry
1027
+ − 6
*
+ − 7
* This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
+ − 8
* as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
+ − 9
*
+ − 10
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
+ − 11
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
+ − 12
*/
+ − 13
+ − 14
class Carpenter_Parse_MediaWiki
+ − 15
{
+ − 16
public $rules = array(
+ − 17
'bold' => "/'''(.+?)'''/",
+ − 18
'italic' => "/''(.+?)''/",
+ − 19
'underline' => '/__(.+?)__/',
+ − 20
'externalwithtext' => '#\[((?:https?|irc|ftp)://.+?) (.+?)\]#',
1106
+ − 21
'externalnotext' => '#\[((?:https?|irc|ftp)://.+?)\]#',
1156
+ − 22
'mailtonotext' => '#\[mailto:([^ \]]+?)\]#',
+ − 23
'mailtowithtext' => '#\[mailto:([^ \]]+?) (.+?)\]#',
1174
+ − 24
'hr' => '/^[-]{4,} *$/m',
+ − 25
'code' => '/^<code>(?:\r?\n)?(.+?)(?:\r?\n)?<\/code>$/mis'
1027
+ − 26
);
+ − 27
1078
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 28
private $blockquote_rand_id;
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 29
1027
+ − 30
public function lang(&$text)
+ − 31
{
+ − 32
global $lang;
+ − 33
+ − 34
preg_match_all('/<lang (?:code|id)="([a-z0-9_-]+)">([\w\W]+?)<\/lang>/', $text, $langmatch);
+ − 35
foreach ( $langmatch[0] as $i => $match )
+ − 36
{
+ − 37
if ( $langmatch[1][$i] == $lang->lang_code )
+ − 38
{
+ − 39
$text = str_replace_once($match, $langmatch[2][$i], $text);
+ − 40
}
+ − 41
else
+ − 42
{
+ − 43
$text = str_replace_once($match, '', $text);
+ − 44
}
+ − 45
}
+ − 46
+ − 47
return array();
+ − 48
}
+ − 49
+ − 50
public function templates(&$text)
+ − 51
{
+ − 52
$template_regex = "/\{\{(.+)((\n|\|[ ]*([A-z0-9]+)[ ]*=[ ]*(.+))*)\}\}/isU";
+ − 53
$i = 0;
1054
e6b14d33ac55
Renderer: added "smart paragraphs" for templates. <p><b>Foo</b> {bar}</p> where bar is multiline is basically turned into proper XHTML paragraphs.
Dan
diff
changeset
+ − 54
while ( preg_match($template_regex, $text, $match) )
1027
+ − 55
{
+ − 56
$i++;
+ − 57
if ( $i == 5 )
+ − 58
break;
+ − 59
$text = RenderMan::include_templates($text);
+ − 60
}
+ − 61
+ − 62
return array();
+ − 63
}
+ − 64
+ − 65
public function heading(&$text)
+ − 66
{
1031
8a4b75e73137
Wiki formatting: Headings: tolerate spaces after line; added disable_rule method (required for rev. 1029)
Dan
diff
changeset
+ − 67
if ( !preg_match_all('/^(={1,6}) *(.+?) *\\1 *$/m', $text, $results) )
1027
+ − 68
return array();
+ − 69
+ − 70
$headings = array();
+ − 71
foreach ( $results[0] as $i => $match )
+ − 72
{
+ − 73
$headings[] = array(
+ − 74
'level' => strlen($results[1][$i]),
+ − 75
'text' => $results[2][$i]
+ − 76
);
+ − 77
}
+ − 78
+ − 79
$text = Carpenter::tokenize($text, $results[0]);
+ − 80
+ − 81
return $headings;
+ − 82
}
+ − 83
+ − 84
public function multilist(&$text)
+ − 85
{
+ − 86
// Match entire lists
+ − 87
$regex = '/^
+ − 88
([:#\*])+ # Initial list delimiter
+ − 89
[ ]*
+ − 90
.+?
+ − 91
(?:
+ − 92
\r?\n
+ − 93
(?:\\1|[ ]{2,})
+ − 94
[ ]*
+ − 95
.+?)*
+ − 96
$/mx';
+ − 97
+ − 98
if ( !preg_match_all($regex, $text, $lists) )
+ − 99
return array();
+ − 100
+ − 101
$types = array(
+ − 102
'*' => 'unordered',
+ − 103
'#' => 'ordered',
+ − 104
':' => 'indent'
+ − 105
);
+ − 106
+ − 107
$pieces = array();
+ − 108
foreach ( $lists[0] as $i => $list )
+ − 109
{
+ − 110
$token = $lists[1][$i];
+ − 111
$piece = array(
+ − 112
'type' => $types[$token],
+ − 113
'items' => array()
+ − 114
);
+ − 115
+ − 116
// convert windows newlines to unix
+ − 117
$list = str_replace("\r\n", "\n", $list);
+ − 118
$items_pre = explode("\n", $list);
+ − 119
$items = array();
+ − 120
// first pass, go through and combine items that are newlined
+ − 121
foreach ( $items_pre as $item )
+ − 122
{
+ − 123
if ( substr($item, 0, 1) == $token )
+ − 124
{
+ − 125
$items[] = $item;
+ − 126
}
+ − 127
else
+ − 128
{
+ − 129
// it's a continuation of the previous LI. Don't need to worry about
+ − 130
// undefined indices here since the regex should filter out all invalid
+ − 131
// markup. Just append this line to the previous.
+ − 132
$items[ count($items) - 1 ] .= "\n" . trim($item);
+ − 133
}
+ − 134
}
+ − 135
+ − 136
// second pass, separate items and tokens
+ − 137
unset($items_pre);
+ − 138
foreach ( $items as $item )
+ − 139
{
+ − 140
// get the depth
1073
b19a9bcb6a45
More work on rendering engine. Fixed some bugs with paragraph skipping and added (incomplete) support for blockquotes.
Dan
diff
changeset
+ − 141
$itemtoken = preg_replace('/^([#:\*]+).*$/s', '$1', $item);
1027
+ − 142
// get the text
+ − 143
$itemtext = trim(substr($item, strlen($itemtoken)));
+ − 144
$piece['items'][] = array(
+ − 145
// depth starts at 1
+ − 146
'depth' => strlen($itemtoken),
+ − 147
'text' => $itemtext
+ − 148
);
+ − 149
}
+ − 150
$pieces[] = $piece;
+ − 151
}
+ − 152
+ − 153
$text = Carpenter::tokenize($text, $lists[0]);
+ − 154
+ − 155
return $pieces;
+ − 156
}
+ − 157
1073
b19a9bcb6a45
More work on rendering engine. Fixed some bugs with paragraph skipping and added (incomplete) support for blockquotes.
Dan
diff
changeset
+ − 158
public function blockquote(&$text)
b19a9bcb6a45
More work on rendering engine. Fixed some bugs with paragraph skipping and added (incomplete) support for blockquotes.
Dan
diff
changeset
+ − 159
{
1078
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 160
$rand_id = hexencode(AESCrypt::randkey(16), '', '');
1073
b19a9bcb6a45
More work on rendering engine. Fixed some bugs with paragraph skipping and added (incomplete) support for blockquotes.
Dan
diff
changeset
+ − 161
1078
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 162
while ( preg_match_all('/^(?:(>+) *.+(?:\r?\n|$))+/m', $text, $quotes) )
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 163
{
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 164
foreach ( $quotes[0] as $quote )
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 165
{
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 166
$piece = trim(preg_replace('/^> */m', '', $quote));
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 167
$text = str_replace_once($quote, "{blockquote:$rand_id}\n$piece\n{/blockquote:$rand_id}\n", $text);
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 168
}
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 169
}
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 170
//die('<pre>' . htmlspecialchars($text) . '</pre>');
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 171
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 172
$this->blockquote_rand_id = $rand_id;
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 173
}
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 174
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 175
public function blockquotepost(&$text)
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 176
{
67a4c839c7e1
Blockquote functionality in wikitext parser now allows rendering of other block level elements properly
Dan
diff
changeset
+ − 177
return $this->blockquote_rand_id;
1073
b19a9bcb6a45
More work on rendering engine. Fixed some bugs with paragraph skipping and added (incomplete) support for blockquotes.
Dan
diff
changeset
+ − 178
}
b19a9bcb6a45
More work on rendering engine. Fixed some bugs with paragraph skipping and added (incomplete) support for blockquotes.
Dan
diff
changeset
+ − 179
1027
+ − 180
public function paragraph(&$text)
+ − 181
{
1044
+ − 182
// The trick with paragraphs is to not turn things into them when a block level element already wraps the block of text.
+ − 183
// First we need a list of block level elements (http://htmlhelp.com/reference/html40/block.html + some Enano extensions)
+ − 184
$blocklevel = 'address|blockquote|center|code|div|dl|fieldset|form|h1|h2|h3|h4|h5|h6|hr|li|ol|p|pre|table|ul|tr|td|th|tbody|thead|tfoot';
+ − 185
+ − 186
// Wrap all block level tags
1073
b19a9bcb6a45
More work on rendering engine. Fixed some bugs with paragraph skipping and added (incomplete) support for blockquotes.
Dan
diff
changeset
+ − 187
RenderMan::tag_strip('_paragraph_bypass', $text, $_nw);
1138
a7b490f0c418
parse_mediawiki: Marked the paragraph bug as non-blocker, delayed until RC1. I have higher priorities than a minor win32 only parsing issue.
Dan
diff
changeset
+ − 188
1127
4b858862c35c
More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
diff
changeset
+ − 189
// I'm not sure why I had to go through all these alternatives. Trying to bring it
4b858862c35c
More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
diff
changeset
+ − 190
// all down to one by ?'ing subpatterns was causing things to return empty and throwing
4b858862c35c
More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
diff
changeset
+ − 191
// errors in the parser. Eventually, around ~3:57AM I just settled on this motherf---er
4b858862c35c
More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
diff
changeset
+ − 192
// of a regular expression.
1138
a7b490f0c418
parse_mediawiki: Marked the paragraph bug as non-blocker, delayed until RC1. I have higher priorities than a minor win32 only parsing issue.
Dan
diff
changeset
+ − 193
a7b490f0c418
parse_mediawiki: Marked the paragraph bug as non-blocker, delayed until RC1. I have higher priorities than a minor win32 only parsing issue.
Dan
diff
changeset
+ − 194
// FIXME: This regexp triggers a known PHP stack size issue under win32 and possibly
a7b490f0c418
parse_mediawiki: Marked the paragraph bug as non-blocker, delayed until RC1. I have higher priorities than a minor win32 only parsing issue.
Dan
diff
changeset
+ − 195
// other platforms (<http://bugs.php.net/bug.php?id=47689>). The workaround is going to
a7b490f0c418
parse_mediawiki: Marked the paragraph bug as non-blocker, delayed until RC1. I have higher priorities than a minor win32 only parsing issue.
Dan
diff
changeset
+ − 196
// involve writing our own parser that takes care of recursion without using the stack,
a7b490f0c418
parse_mediawiki: Marked the paragraph bug as non-blocker, delayed until RC1. I have higher priorities than a minor win32 only parsing issue.
Dan
diff
changeset
+ − 197
// which is going to be a bitch, and may not make it in until Caoineag RCs.
a7b490f0c418
parse_mediawiki: Marked the paragraph bug as non-blocker, delayed until RC1. I have higher priorities than a minor win32 only parsing issue.
Dan
diff
changeset
+ − 198
1127
4b858862c35c
More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
diff
changeset
+ − 199
$regex = ";
4b858862c35c
More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
diff
changeset
+ − 200
<($blocklevel)
4b858862c35c
More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
diff
changeset
+ − 201
(?:
4b858862c35c
More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
diff
changeset
+ − 202
# self closing, no attributes
4b858862c35c
More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
diff
changeset
+ − 203
[ ]*/>
4b858862c35c
More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
diff
changeset
+ − 204
|
4b858862c35c
More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
diff
changeset
+ − 205
# self closing, attributes
4b858862c35c
More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
diff
changeset
+ − 206
[ ][^>]+? />
4b858862c35c
More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
diff
changeset
+ − 207
|
4b858862c35c
More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
diff
changeset
+ − 208
# with inner text, no attributes
4b858862c35c
More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
diff
changeset
+ − 209
>
4b858862c35c
More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
diff
changeset
+ − 210
(?: (?R) | .*? )*</\\1>
4b858862c35c
More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
diff
changeset
+ − 211
|
4b858862c35c
More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
diff
changeset
+ − 212
# with inner text and attributes
4b858862c35c
More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
diff
changeset
+ − 213
[ ][^>]+? # attributes
4b858862c35c
More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
diff
changeset
+ − 214
>
4b858862c35c
More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
diff
changeset
+ − 215
(?: (?R) | .*? )*</\\1>
4b858862c35c
More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
diff
changeset
+ − 216
)
4b858862c35c
More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
diff
changeset
+ − 217
;sx";
4b858862c35c
More parser work: fixed a few bugs with [[intlinks]] in headers, a bug that caused the paragraph parser to return an empty string, and added a warning/backup-and-restore for when a render stage returns an empty string.
Dan
diff
changeset
+ − 218
1131
adfbe522c95f
Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
diff
changeset
+ − 219
// oh. and we're using this tokens thing because for identical matches, the first match will
adfbe522c95f
Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
diff
changeset
+ − 220
// get wrapped X number of times instead of all matches getting wrapped once; replacing each
adfbe522c95f
Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
diff
changeset
+ − 221
// with a unique token id remedies this
adfbe522c95f
Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
diff
changeset
+ − 222
adfbe522c95f
Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
diff
changeset
+ − 223
$tokens = array();
adfbe522c95f
Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
diff
changeset
+ − 224
$rand_id = sha1(microtime() . mt_rand());
1134
4fdd92da4fe8
Hack: temporarily disabled PCRE recursion for Win32 in the paragraph block tag parser until a better parser can be written/adapted
dan
diff
changeset
+ − 225
4fdd92da4fe8
Hack: temporarily disabled PCRE recursion for Win32 in the paragraph block tag parser until a better parser can be written/adapted
dan
diff
changeset
+ − 226
// Temporary hack to fix crashes under win32. Sometime I'll write a loop based
4fdd92da4fe8
Hack: temporarily disabled PCRE recursion for Win32 in the paragraph block tag parser until a better parser can be written/adapted
dan
diff
changeset
+ − 227
// parser for this whole section. Maybe. Perhaps the Apache folks will fix their
4fdd92da4fe8
Hack: temporarily disabled PCRE recursion for Win32 in the paragraph block tag parser until a better parser can be written/adapted
dan
diff
changeset
+ − 228
// Windows binaries first.
4fdd92da4fe8
Hack: temporarily disabled PCRE recursion for Win32 in the paragraph block tag parser until a better parser can be written/adapted
dan
diff
changeset
+ − 229
if ( PHP_OS == 'WIN32' || PHP_OS == 'WINNT' )
4fdd92da4fe8
Hack: temporarily disabled PCRE recursion for Win32 in the paragraph block tag parser until a better parser can be written/adapted
dan
diff
changeset
+ − 230
{
4fdd92da4fe8
Hack: temporarily disabled PCRE recursion for Win32 in the paragraph block tag parser until a better parser can be written/adapted
dan
diff
changeset
+ − 231
$regex = str_replace("(?: (?R) | .*? )*", "(?: .*? )", $regex);
4fdd92da4fe8
Hack: temporarily disabled PCRE recursion for Win32 in the paragraph block tag parser until a better parser can be written/adapted
dan
diff
changeset
+ − 232
}
1130
c308b471ed82
OK, I'm done with the preg_replace() in the paragraph parser. It's too buggy. Replaced with preg_match_all()/str_replace_once().
Dan
diff
changeset
+ − 233
if ( preg_match_all($regex, $text, $matches) )
c308b471ed82
OK, I'm done with the preg_replace() in the paragraph parser. It's too buggy. Replaced with preg_match_all()/str_replace_once().
Dan
diff
changeset
+ − 234
{
1131
adfbe522c95f
Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
diff
changeset
+ − 235
foreach ( $matches[0] as $i => $match )
1130
c308b471ed82
OK, I'm done with the preg_replace() in the paragraph parser. It's too buggy. Replaced with preg_match_all()/str_replace_once().
Dan
diff
changeset
+ − 236
{
1131
adfbe522c95f
Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
diff
changeset
+ − 237
$text = str_replace_once($match, "{_pb_:$rand_id:$i}", $text);
adfbe522c95f
Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
diff
changeset
+ − 238
$tokens[$i] = '<_paragraph_bypass>' . $match . '</_paragraph_bypass>';
1130
c308b471ed82
OK, I'm done with the preg_replace() in the paragraph parser. It's too buggy. Replaced with preg_match_all()/str_replace_once().
Dan
diff
changeset
+ − 239
}
c308b471ed82
OK, I'm done with the preg_replace() in the paragraph parser. It's too buggy. Replaced with preg_match_all()/str_replace_once().
Dan
diff
changeset
+ − 240
}
c308b471ed82
OK, I'm done with the preg_replace() in the paragraph parser. It's too buggy. Replaced with preg_match_all()/str_replace_once().
Dan
diff
changeset
+ − 241
1131
adfbe522c95f
Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
diff
changeset
+ − 242
foreach ( $tokens as $i => $match )
adfbe522c95f
Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
diff
changeset
+ − 243
{
adfbe522c95f
Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
diff
changeset
+ − 244
$text = str_replace_once("{_pb_:$rand_id:$i}", $match, $text);
adfbe522c95f
Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
diff
changeset
+ − 245
}
adfbe522c95f
Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
diff
changeset
+ − 246
adfbe522c95f
Another fix to paragraph bypass behavior, for when the same substring appears more than once in the text
Dan
diff
changeset
+ − 247
// die('<pre>' . htmlspecialchars($text) . '</pre>');
1134
4fdd92da4fe8
Hack: temporarily disabled PCRE recursion for Win32 in the paragraph block tag parser until a better parser can be written/adapted
dan
diff
changeset
+ − 248
1073
b19a9bcb6a45
More work on rendering engine. Fixed some bugs with paragraph skipping and added (incomplete) support for blockquotes.
Dan
diff
changeset
+ − 249
RenderMan::tag_unstrip('_paragraph_bypass', $text, $_nw, true);
1044
+ − 250
1027
+ − 251
// This is potentially a hack. It allows the parser to stick in <_paragraph_bypass> tags
+ − 252
// to prevent the paragraph parser from interfering with pretty HTML generated elsewhere.
+ − 253
RenderMan::tag_strip('_paragraph_bypass', $text, $_nw);
+ − 254
1044
+ − 255
$startcond = "(?!(?:[\\r\\n]|\{_paragraph_bypass:[a-f0-9]{32}:[0-9]+\}|[ ]*<\/?(?:$blocklevel)(?: .+>|>)))";
+ − 256
$regex = "/^
+ − 257
$startcond # line start condition - do not match if the line starts with the condition above
+ − 258
.+? # body text
1027
+ − 259
(?:
1044
+ − 260
\\n # additional lines
+ − 261
$startcond # make sure of only one newline in a row, and end the paragraph if a new line fails the start condition
1027
+ − 262
.*?
1044
+ − 263
)* # keep going until it fails
+ − 264
$
1027
+ − 265
/mx";
+ − 266
+ − 267
if ( !preg_match_all($regex, $text, $matches) )
1044
+ − 268
{
+ − 269
RenderMan::tag_unstrip('_paragraph_bypass', $text, $_nw);
1027
+ − 270
return array();
1044
+ − 271
}
1027
+ − 272
+ − 273
// Debugging :)
1044
+ − 274
// die('<pre>' . htmlspecialchars($text) . "\n-----------------------------------------------------------\n" . htmlspecialchars(print_r($matches, true)) . '</pre>');
1027
+ − 275
+ − 276
// restore stripped
+ − 277
RenderMan::tag_unstrip('_paragraph_bypass', $text, $_nw);
+ − 278
+ − 279
// tokenize
+ − 280
$text = Carpenter::tokenize($text, $matches[0]);
+ − 281
+ − 282
return $matches[0];
+ − 283
}
+ − 284
}
+ − 285
+ − 286
function parser_mediawiki_xhtml_image($text)
+ − 287
{
+ − 288
$text = RenderMan::process_image_tags($text, $taglist);
+ − 289
$text = RenderMan::process_imgtags_stage2($text, $taglist);
+ − 290
return $text;
+ − 291
}
+ − 292
+ − 293
function parser_mediawiki_xhtml_tables($text)
+ − 294
{
+ − 295
return process_tables($text);
+ − 296
}
+ − 297