Exemple #1
0
function wikiToHtml(&$session, $wiki_text)
{
    $lines = explode("\n", $wiki_text);
    $session->trace(TC_Util1, 'wikiToHtml: ' . (0 + count($lines)) . ' Zeilen' . "({$lines['0']})");
    $status = new LayoutStatus($session);
    foreach ($lines as $ii => $line) {
        if (($line_trimmed = trim($line)) == '') {
            writeParagraphEnd($status);
        } else {
            #$session->trace (TC_X, "Neue Zeile: '$line_trimmed' $line]");
            if ($line_trimmed == '[code]') {
                $session->startCode();
            } elseif ($line_trimmed == '[/code]') {
                $session->finishCode();
            } elseif ($session->fPreformated) {
                echo htmlentities($line);
            } else {
                switch (substr($line, 0, 1)) {
                    case '!':
                        if (substr($line, 1, 1) == '|') {
                            writeTableHeader($line, $status);
                        } else {
                            writeHeader($line, $status);
                        }
                        break;
                    case ' ':
                        writeLine($line, $status);
                        break;
                        # writeIndent ($line, $status); break;
                    # writeIndent ($line, $status); break;
                    case '*':
                        writeUList($line, $status);
                        break;
                    case '#':
                        writeOrderedList($line, $status);
                        break;
                    case '|':
                        writeTable($line, $status);
                        break;
                    case '-':
                        writeHoricontalLine($line, $status);
                        break;
                    default:
                        writeLine($line, $status);
                        break;
                }
            }
        }
    }
    // foreach
    $session->trace(TC_Util1, 'wikiToHtml-Ende');
}
Exemple #2
0
function wikiToHtml(&$session, $wiki_text)
{
    $lines = explode("\n", $wiki_text);
    $session->trace(TC_Util1, 'wikiToHtml: ' . (0 + count($lines)) . ' Zeilen' . "({$lines['0']})");
    $status = new LayoutStatus($session);
    $last_linetype = '';
    foreach ($lines as $ii => $line) {
        $start_code = false;
        if (!$status->fPreformatted && ($line_trimmed = trim($line)) == '') {
            $last_linetype = '';
            $status->changeOfLineType($last_linetype, '');
        } else {
            $linetype = $status->fPreformatted ? '[' : substr($line, 0, 1);
            switch ($linetype) {
                case '-':
                    $count = countRepeats($line, '-');
                    if ($count < 4) {
                        $linetype = 'x';
                    }
                    break;
                case '[':
                    if (strpos($line, 'code]') == 1) {
                        $start_code = true;
                    } elseif (strpos($line, '/code]') == 1) {
                        $status->finishCode();
                        $last_linetype = 'x';
                        $line = $line_trimmed = substr($line, 7);
                        $session->trace(TC_Util2, 'wikiToHtml: /code-Restzeile: ' . $line);
                    } else {
                        $linetype = 'x';
                    }
                    break;
                case '!':
                case ';':
                case '*':
                case '#':
                case '|':
                    break;
                default:
                    $linetype = 'x';
                    break;
            }
            $last_linetype = $status->testChangeOfLineType($last_linetype, $linetype);
            switch ($linetype) {
                case '!':
                    if (strpos($line, '|') != 1) {
                        writeHeader($line, $status);
                    } else {
                        writeTableHeader($line, $status);
                        $last_linetype = '|';
                    }
                    break;
                case '[':
                    if ($start_code) {
                        $status->startCode();
                    }
                    $line = substr($line_trimmed, 6);
                    if (!empty($line)) {
                        writeLine($line, $status);
                    }
                    break;
                case ';':
                    writeIndent($line, $status);
                    break;
                case '*':
                    writeUList($line, $status);
                    break;
                case '#':
                    writeOrderedList($line, $status);
                    break;
                case '|':
                    writeTable($line, $status);
                    break;
                case '-':
                    guiLine($status->fSession, $count - 3);
                    break;
                default:
                    writeLine($line, $status);
                    break;
            }
        }
    }
    // foreach
    if ($status->fPreformatted) {
        $session->trace(TC_Warning, PREFIX_Warning . '[/code] fehlt');
    }
    $session->trace(TC_Util1, 'wikiToHtml-Ende');
}