“If debugging is the process of removing bugs, then programming must be the process of putting them in.” – Edsger Dijkstra
This is the Bug Tracking System for the Flyspray project. This is not a demo! Before opening a new task, please read the guidelines!
Do not issue bugs reports against versions earlier than 0.9.9.6
Security problem? Check the security section.
FS#1569 - Simple Text-Formatter
Attached to Project:
Flyspray - The bug killer!
Opened by Andreas Gohr (andi) - Tuesday, 26 May 2009, 15:09 GMT+2
Opened by Andreas Gohr (andi) - Tuesday, 26 May 2009, 15:09 GMT+2
|
DetailsI couldn’t find a way to add this to the wiki, so I thought to post it here. Maybe you want to include it in the next release. I wanted a very simple text formatter which preserves whitespaces as much as possible but still wraps lines when needed. This is what I came up with. I’m using a similar formatter for my blog comments. <?php class simple_TextFormatter { function render($text, $onlyfs = false, $type = null, $id = null, $instructions = null) { $text = htmlspecialchars($text, ENT_QUOTES, 'utf-8'); $text = preg_replace('/\t/',' ',$text); $text = preg_replace('/ /',' ',$text); // Change URLs into hyperlinks if (!$onlyfs) { $text = preg_replace('|[[:space:]]+[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]|', '<a href="\0">\0</a>', $text); $text = preg_replace('/[a-zA-Z0-9._-]+@[a-zA-Z0-9-.]+\.[a-zA-Z]{2,5}/', '<a href="mailto:\0">\0</a>', $text); } // Change FS#123 into hyperlinks to tasks $text = preg_replace_callback("/\b(?:FS#|bug )(\d+)\b/", 'tpl_fast_tasklink', $text); $text = nl2br($text); // add some inline styling $text = '<div style="font-family: monospace">'.$text.'</div>'; return $text; } } ?> |
This task depends upon