Closed Snack-X closed 9 years ago
모바일 환경 상에서 페이지 상의 <pre> 태그의 내용이 한 줄로 붙어나오는 문제가 있습니다. library/view/view.php의 getEntryContentView() 함수에서 호출하는 stripHTML() 에서 모든 연속된 whitespace character를 한개의 space로 치환하면서 생기는 문제로 보입니다.
<pre>
library/view/view.php
getEntryContentView()
stripHTML()
아래는 테스트 코드이며, 실행 결과는 https://ideone.com/RZu0HS 를 참조하셔도 됩니다.
<?php // from library/function/html.php function stripHTML($text, $allowTags = array()) { $text = preg_replace('/<(script|style)[^>]*>.*?<\/\1>/si', '', $text); if(count($allowTags) == 0) $text = preg_replace('/<[\w\/!]+[^>]*>/', '', $text); else { preg_match_all('/<\/?([\w!]+)[^>]*?>/s', $text, $matches); for($i=0; $i<count($matches[0]); $i++) { if (!in_array(strtolower($matches[1][$i]), $allowTags)) $text = str_replace($matches[0][$i], '', $text); } } $text = preg_replace('/ ?|\xc2\xa0\x20/', ' ', $text); $text = trim(preg_replace('/\s+/', ' ', $text)); if(!empty($text)) $text = str_replace(array(''', ''', '"'), array('\'', '\'', '"'), $text); return $text; } // sample content $input = <<<CODE <pre>#include <stdio.h> int main() { printf("Hello, world!"); return 0; } </pre> CODE; echo "Without stripHTML:\n"; echo $input; echo "\n\n"; // from library/view/view.php getEntryContentView() $output = stripHTML($input, array('a', 'abbr', 'acronym', 'address','b', 'blockquote', 'br', 'caption', 'cite', 'code', 'dd', 'del', 'dfn', 'div', 'dl', 'dt', 'em', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'i', 'iframe', 'img', 'ins', 'kbd', 'li', 'ol', 'p', 'pre', 'q', 's', 'samp', 'span', 'strike', 'strong', 'sub', 'sup', 'table', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'u', 'ul', 'var')); echo "With stripHTML:\n"; echo $output;
모바일 환경 상에서 페이지 상의
<pre>
태그의 내용이 한 줄로 붙어나오는 문제가 있습니다.library/view/view.php
의getEntryContentView()
함수에서 호출하는stripHTML()
에서 모든 연속된 whitespace character를 한개의 space로 치환하면서 생기는 문제로 보입니다.아래는 테스트 코드이며, 실행 결과는 https://ideone.com/RZu0HS 를 참조하셔도 됩니다.