[ticket/11742] Removed tabs-to-space conversion in [code]

PHPBB3-11742
This commit is contained in:
JoshyPHP 2015-04-29 23:22:30 +02:00
parent 466b710235
commit 92078dce33
4 changed files with 4 additions and 45 deletions

View file

@ -234,10 +234,6 @@ class renderer implements \phpbb\textformatter\renderer_interface
} }
$html = $this->renderer->render($xml); $html = $this->renderer->render($xml);
if (stripos($html, '<code') !== false)
{
$html = $this->replace_tabs_in_code($html);
}
/** /**
* Modify a rendered text * Modify a rendered text
@ -253,45 +249,6 @@ class renderer implements \phpbb\textformatter\renderer_interface
return $html; return $html;
} }
/**
* Replace tabs in code elements
*
* @see bbcode::bbcode_second_pass_code()
*
* @param string $html Original HTML
* @return string Modified HTML
*/
protected function replace_tabs_in_code($html)
{
return preg_replace_callback(
'((<code[^>]*>)(.*?)(</code>))is',
function ($captures)
{
$code = $captures[2];
$code = str_replace("\t", '&nbsp; &nbsp;', $code);
$code = str_replace(' ', '&nbsp; ', $code);
$code = str_replace(' ', ' &nbsp;', $code);
$code = str_replace("\n ", "\n&nbsp;", $code);
// keep space at the beginning
if (!empty($code) && $code[0] == ' ')
{
$code = '&nbsp;' . substr($code, 1);
}
// remove newline at the beginning
if (!empty($code) && $code[0] == "\n")
{
$code = substr($code, 1);
}
return $captures[1] . $code . $captures[3];
},
$html
);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View file

@ -12,8 +12,8 @@
<!-- BEGIN quote_open --><blockquote class="uncited"><div><!-- END quote_open --> <!-- BEGIN quote_open --><blockquote class="uncited"><div><!-- END quote_open -->
<!-- BEGIN quote_close --></div></blockquote><!-- END quote_close --> <!-- BEGIN quote_close --></div></blockquote><!-- END quote_close -->
<!-- BEGIN code_open --><div class="codebox"><p>{L_CODE}{L_COLON} <a href="#" onclick="selectCode(this); return false;">{L_SELECT_ALL_CODE}</a></p><code><!-- END code_open --> <!-- BEGIN code_open --><div class="codebox"><p>{L_CODE}{L_COLON} <a href="#" onclick="selectCode(this); return false;">{L_SELECT_ALL_CODE}</a></p><pre><code><!-- END code_open -->
<!-- BEGIN code_close --></code></div><!-- END code_close --> <!-- BEGIN code_close --></code></pre></div><!-- END code_close -->
<!-- BEGIN inline_attachment_open --><div class="inline-attachment"><!-- END inline_attachment_open --> <!-- BEGIN inline_attachment_open --><div class="inline-attachment"><!-- END inline_attachment_open -->
<!-- BEGIN inline_attachment_close --></div><!-- END inline_attachment_close --> <!-- BEGIN inline_attachment_close --></div><!-- END inline_attachment_close -->

View file

@ -0,0 +1 @@
<div class="codebox"><p>CODE: <a href="#" onclick="selectCode(this); return false;">Select all</a></p><pre><code> tab</code></pre></div>

View file

@ -0,0 +1 @@
[code] tab[/code]