Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

be a bit more intelligent with adding/removing newlines and <br>'s

  • Loading branch information...
commit 07ad863976002269361cdd5798912f331bd7de1e 1 parent 66babbb
Bill Fraser authored

Showing 1 changed file with 18 additions and 4 deletions. Show diff stats Hide diff stats

  1. +18 4 topic.php
22 topic.php
@@ -113,17 +113,31 @@ function display_post($post, $highlight = FALSE, $topic_urltitle = "")
113 113
114 114 function output_topic_text($text)
115 115 {
  116 + $text = str_replace("\r", "", $text);
  117 +
116 118 $text = preg_replace("/&(?![a-zA-Z]+;)/", "&amp;", $text);
117 119
118   - $parts = preg_split("/(<noautobr>(.*)<\/noautobr>)/Us", $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
  120 + $tags = "pre|ol|ul";
  121 + $text = preg_replace("#\n\n<($tags)#", "\n<$1", $text);
  122 + $text = preg_replace("#</($tags)>\n\n#", "</$1>", $text);
  123 + $text = str_replace("</noautobr>\n\n", "</noautobr>\n", $text);
  124 +
  125 + $parts = preg_split("/(<(noautobr|pre)>(.*)<\/\\2>)/Us", $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
119 126
120 127 $text = "";
121 128 for($i = 0; $i < count($parts); $i++)
122 129 {
123   - if(strpos($parts[$i], "<noautobr>") === 0)
124   - $text .= textprocess($parts[++$i], FALSE);
125   - else
  130 + if (strpos($parts[$i], "<noautobr>") === 0) {
  131 + $i += 2;
  132 + $text .= textprocess($parts[$i], FALSE);
  133 + }
  134 + else if(strpos($parts[$i], "<pre>") === 0) {
  135 + $text .= textprocess($parts[$i], FALSE);
  136 + $i += 2;
  137 + }
  138 + else {
126 139 $text .= textprocess($parts[$i]);
  140 + }
127 141 }
128 142
129 143 return $text;

0 comments on commit 07ad863

Please sign in to comment.
Something went wrong with that request. Please try again.