SourceForge logo
SourceForge logo
Menu

phpwiki-checkins

From: Geoffrey T. D. <da...@us...> - 2002年09月17日 19:23:35
Update of /cvsroot/phpwiki/phpwiki/lib
In directory usw-pr-cvs1:/tmp/cvs-serv24360/lib
Modified Files:
	BlockParser.php stdlib.php 
Log Message:
Convert to using the new markup engine, even for old markup pages.
So far, the only bugs I know of (I'm sure there are more) are:
 o Footnotes don't work quite the same (especially if there is
 more than one reference to a footnote.) This could probably
 be fixed, but I'm not sure it's worth it.
 o There are issues having to do with "tight" vs "loose" lists.
Please let me know of any other problems you discover.
Index: BlockParser.php
===================================================================
RCS file: /cvsroot/phpwiki/phpwiki/lib/BlockParser.php,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -2 -b -p -d -r1.26 -r1.27
--- BlockParser.php	16 Sep 2002 22:12:47 -0000	1.26
+++ BlockParser.php	17 Sep 2002 19:23:32 -0000	1.27
@@ -904,6 +904,4 @@ class Block_p extends BlockMarkup
 //
 
-
-
 function TransformText ($text, $markup = 2.0) {
 if (isa($text, 'WikiDB_PageRevision')) {
@@ -914,21 +912,18 @@ function TransformText ($text, $markup =
 
 if (empty($markup) || $markup < 2.0) {
- include_once("lib/transform.php");
- return do_transform($text);
- //$text = ConvertOldMarkup($text);
+ //include_once("lib/transform.php");
+ //return do_transform($text);
+ $text = ConvertOldMarkup($text);
 }
 
 // Expand leading tabs.
- // FIXME: do this better. also move it...
- $text = preg_replace('/^\ *[^\ \S\n][^\S\n]*/me', "str_repeat(' ', strlen('\0円'))", $text);
- assert(!preg_match('/^\ *\t/', $text));
+ $text = expand_tabs($text);
 
 //set_time_limit(3);
 
 $output = new WikiText($text);
- return $output;
+ return new XmlContent($output->getContent());
 }
 
- 
 // (c-file-style: "gnu")
 // Local Variables:
Index: stdlib.php
===================================================================
RCS file: /cvsroot/phpwiki/phpwiki/lib/stdlib.php,v
retrieving revision 1.124
retrieving revision 1.125
diff -u -2 -b -p -d -r1.124 -r1.125
--- stdlib.php	17 Sep 2002 15:23:32 -0000	1.124
+++ stdlib.php	17 Sep 2002 19:23:32 -0000	1.125
@@ -500,11 +500,13 @@ function ExtractLinks($content) {
 * @return string New-style wiki markup.
 *
- * @bugs FIXME: footnotes and old-style tables are known to be broken.
+ * @bugs Footnotes don't work quite as before (esp if there are
+ * multiple references to the same footnote. But close enough,
+ * probably for now....
 */
 function ConvertOldMarkup ($text, $markup_type = "block") {
 
- static $orig, $repl, $link_orig, $link_repl;
+ static $subs;
 
- if (empty($orig)) {
+ if (empty($subs)) {
 /*****************************************************************
 * Conversions for inline markup:
@@ -529,7 +531,28 @@ function ConvertOldMarkup ($text, $marku
 $repl[] = '~\1円';
 
+ $subs["links"] = array($orig, $repl);
 
- $link_orig = $orig;
- $link_repl = $repl;
+ // Escape '<'s
+ //$orig[] = '/<(?!\?plugin)|(?<!^)</m';
+ //$repl[] = '~<';
+ 
+ // Convert footnote references.
+ $orig[] = '/(?<=.)(?<!~)\[\s*(\d+)\s*\]/m';
+ $repl[] = '#[|ftnt_ref_\1円]<sup>~[[\1円|#ftnt_\1円]~]</sup>';
+
+ // Convert old style emphases to HTML style emphasis.
+ $orig[] = '/__(.*?)__/';
+ $repl[] = '<strong>\1円</strong>';
+ $orig[] = "/''(.*?)''/";
+ $repl[] = '<em>\1円</em>';
+
+
+ $subs["inline"] = array($orig, $repl);
+
+ // Escape nestled markup. (two versions: inline & block)
+ $subs["inline"][0][] = '/^(?<=^|\s)[=_*](?=\S)|(?<=\S)[=_*](?=\s|$)/m';
+ $subs["inline"][1][] = '/~\0円/';
+ $orig[] = '/^.*?(?:(?<=^|\s)[=_*](?=\S)|(?<=\S)[=_*](?=\s|$)).*$/me';
+ $repl[] = "_EscapeNestledMarkup('\0円')";
 
 /*****************************************************************
@@ -540,23 +563,36 @@ function ConvertOldMarkup ($text, $marku
 $repl[] = "<pre>\n\0円</pre>\n";
 
+ // convert tables
+ $orig[] = '/(?:^\|.*\n)+/m';
+ $repl[] = "<?plugin OldStyleTable\n\0円?>\n";
+
 // convert lists
 $orig[] = '/^([#*;]*)([*#]|;.*?:) */me';
 $repl[] = "_ConvertOldListMarkup('\1円', '\2円')";
- }
 
+ // convert footnote definitions
+ $orig[] = '/^\[\s*(\d+)\s*\]/m';
+ $repl[] = '#[|ftnt_\1円]~[[\1円|#ftnt_ref_\1円]~]';
 
- if ($markup_type == "block") {
- return preg_replace($orig, $repl, $text);
- }
- else {
- return preg_replace($link_orig, $link_repl, $text);
+ // in old markup headings only allowed at beginning of line
+ //$orig[] = '/(?<=[^!])!/';
+ $orig[] = '/([^\n!])!/';
+ $repl[] = '\1円~!';
+
+ $subs["block"] = array($orig, $repl);
 }
+ 
+ list ($orig, $repl) = $subs[$markup_type];
+ if ($markup_type == "block" and substr($text,-1) != "\n")
+ $text .= "\n";
+ return preg_replace($orig, $repl, $text);
 }
 
-function _ConvertOldListMarkup ($indent, $bullet) {
- $indent = str_repeat(' ', strlen($indent));
+function _ConvertOldListMarkup ($ind, $bullet) {
+ $indent = str_repeat(' ', strlen($ind));
 if ($bullet[0] == ';') {
- $term = ltrim(substr($bullet, 1));
- return $indent . $term . "\n" . $indent . ' ';
+ //$term = ltrim(substr($bullet, 1));
+ //return $indent . $term . "\n" . $indent . ' ';
+ return $ind . $bullet;
 }
 else
@@ -564,5 +600,31 @@ function _ConvertOldListMarkup ($indent,
 }
 
+function _EscapeNestledMarkup ($line) {
+ if (!preg_match('/^<\?plugin.*\?>/', $line))
+ $line = preg_replace('/[=_]|(?<!^|[*#;])\*/', '~\0円', $line);
+ return $line;
+}
+
 
+/**
+ * Expand tabs in string.
+ *
+ * Converts all tabs to (the appropriate number of) spaces.
+ *
+ * @param string $str
+ * @param integer $tab_width
+ * @return string
+ */
+function expand_tabs($str, $tab_width = 8) {
+ $split = split("\t", $str);
+ $tail = array_pop($split);
+ $expanded = "\n";
+ foreach ($split as $hunk) {
+ $expanded .= $hunk;
+ $pos = strlen(strrchr($expanded, "\n")) - 1;
+ $expanded .= str_repeat(" ", ($tab_width - $pos % $tab_width));
+ }
+ return substr($expanded, 1) . $tail;
+}
 
 /**
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /