Recent Changes - Search:

Home Pages Pidgin   Azarennya (S|N) Mac Textanium Reference ToDo Food Local Edit

Local: Hide

Language: Hide

Fantasy: Hide

SciFi: Hide

Film: Hide

Music: Hide

REALbasic: Hide

ResourcesGarageUniversityWebRingForums:REALElfDataPlugins and Code:BKeeneyDeclareSubEinhugurJoeRestrepoTempelmannZAZ

Coding: Hide

Forums:PowWebPHPWebmasterCodingWalkersPerlIntroMonksPHPJavaScriptToolboxUnobtrusiveJavaScriptJavaScriptCompressorRegularExpressions (test)JSLintSQLCocoaCocoaBuilderCocoaDevCocoaLabAppleScriptBBSUserlandFaqintoshFileMakerFileMakerTipsFileMakerWorldFileMakerPlugins

Science: Hide

History: Hide

1421

News/Politics: Hide

Cults/Crime: Hide

ClambakeInfidels

Miscellaneous: Hide

MarkupLinoleumJustTextAndTables

Suppose Linoleum 0.1 supports only text and tables. Table cell lines begin with '%' ('' starts a new row, and '%' starts a header row), while text lines can begin with anything else.

What does the code look like that processes lines of Wiki text? (Could use a PHPCompressor?.)

	$marks = array('%', '\\');
	// for each line
		$trimmed = trim($line);
		$c = $trimmed{0};
		if (!in_array($c, $marks)) $c = '\\';

		// If the mark character is '%',
		// count how many mark characters begin the line.

		if ($c == '%') {
			$marksize = 1;
			while ($trimmed{$marksize} == $c) ++$marksize;
		}

		// Get actual text from line; convert special characters.

		$text = htmlspecialchars(substr($trimmed, $marksize), ENT_NOQUOTES);

		// If a closing tag has been pushed onto the stack, and the
		// current tag differs from the previous tag, then pop the
		// closing tag from the stack and send it to output.

		if ($prev_c != '' && $c != $prev_c) {
			$tag = $stack[$sp--]; // pop the closing-tag stack
			$output .= $tag . "\n";
			if ($tag == '</td>' or $tag == '</th>') {
				$output .= '</tr></table>';
			}
		}

		// Whether or not a closing tag has been pushed onto the
		// stack, if the current tag differs from the previous tag,
		// send the opening tag to output and push the closing tag
		// onto the stack.

		if ($c != $prev_c) {
			if ($c == '%') {
				$output .= "<table><tr>\n";
				if ($marksize < 3) {
					$output .= "<td>\n";
					$stack[++$sp] = "</td>";
				} else {
					$output .= "<th>\n";
					$stack[++$sp] = "</th>";
				}
			} else {
				$output .= "<p>\n";
				$stack[++$sp] = "</p>";
			}
		}

		// Now output the text.

		$output .= $text . "\n";
	}
	// If there's anything left on the stack,
	// pop it and add it to output here.
Edit - History - Print - Recent Changes - Search
Page last modified on February 04, 2008, at 01:47 PM