Public feed #893349

Unnamed

public text v1 · immutable
Raw Edit
·published 2008-02-06 01:41 UTC
rendered paste body
                // bold, italic, underline, and strikethrough
                // These are worse than sed. Not only do you have to escape stuff, you have to
                // escape it again for PHP.
                $text = preg_replace('/(?<!\\\\)\*\*(.*)(?!\\\\)\*\*/sU', '<b>\1</b>', $text);
                $text = preg_replace('/(\\\\)\*\*/', '**', $text);
                $text = preg_replace('/(?<!\\\\)\/\/(.*)(?!\\\\)\/\//sU', '<i>\1</i>', $text);
                $text = preg_replace('/(\\\\)\/\//', '//', $text);
                $text = preg_replace('/(?<!\\\\)__(.*)(?!\\\\)__/sU', '<u>\1</u>', $text);
                $text = preg_replace('/(\\\\)__/', '__', $text);
                $text = preg_replace('/(?<!\\\\)--(.*)(?!\\\\)--/sU', '<del>\1</del>', $text);
                $text = preg_replace('/(\\\\)--/', '--', $text);

                // external links
                $text = convert_urls($text);

                // links to wiki pages
                $text = preg_replace_callback('/(?<!\\\\)\[\[(.+)(?!\\\\)\]\]/sU', 'make_link', $text);
                $text = preg_replace('/(\\\\)\\[\\[/', '[[', $text);
                $text = preg_replace('/(\\\\)\\]\\]/', ']]', $text);

                // headers
                $text = preg_replace_callback('/(?<!\\\\)==\(1\)(.+)(?!\\\\)==/sU', 'make_h1', $text);
                $text = preg_replace('/(\\\\)==\\(1\\)/', '==(1)', $text);
                $text = preg_replace_callback('/(?<!\\\\)==\(2\)(.+)(?!\\\\)==/sU', 'make_h2', $text);
                $text = preg_replace('/(\\\\)==\\(2\\)/', '==(2)', $text);
                $text = preg_replace_callback('/(?<!\\\\)==\(3\)(.+)(?!\\\\)==/sU', 'make_h3', $text);
                $text = preg_replace('/(\\\\)==\\(3\\)/', '==(3)', $text);
                $text = preg_replace('/(\\\\)==/', '==', $text);

                $text = preg_replace('/\n/', '<br>', $text);

                return $text;
        }