Skip to content

Commit

Permalink
Merge pull request phpbb#3625 from s9e/ticket/11742
Browse files Browse the repository at this point in the history
[ticket/11742] Remove tabs-to-space conversion in [code]
  • Loading branch information
Tristan Darricau committed May 29, 2015
2 parents 0e48d25 + 3f52429 commit 835a2eb
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 54 deletions.
8 changes: 4 additions & 4 deletions phpBB/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 0 additions & 43 deletions phpBB/phpbb/textformatter/s9e/renderer.php
Expand Up @@ -234,10 +234,6 @@ public function render($xml)
}

$html = $this->renderer->render($xml);
if (stripos($html, '<code') !== false)
{
$html = $this->replace_tabs_in_code($html);
}

/**
* Modify a rendered text
Expand All @@ -253,45 +249,6 @@ public function render($xml)
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}
*/
Expand Down
4 changes: 2 additions & 2 deletions phpBB/styles/prosilver/template/bbcode.html
Expand Up @@ -12,8 +12,8 @@
<!-- BEGIN quote_open --><blockquote class="uncited"><div><!-- END quote_open -->
<!-- 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_close --></code></div><!-- END code_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><pre><code><!-- END code_open -->
<!-- BEGIN code_close --></code></pre></div><!-- END code_close -->

<!-- BEGIN inline_attachment_open --><div class="inline-attachment"><!-- END inline_attachment_open -->
<!-- BEGIN inline_attachment_close --></div><!-- END inline_attachment_close -->
Expand Down
1 change: 0 additions & 1 deletion phpBB/styles/prosilver/theme/content.css
Expand Up @@ -513,7 +513,6 @@ blockquote .codebox {
display: block;
height: auto;
max-height: 200px;
white-space: normal;
padding-top: 5px;
font: 0.9em Monaco, "Andale Mono","Courier New", Courier, mono;
line-height: 1.3em;
Expand Down
12 changes: 8 additions & 4 deletions tests/text_formatter/s9e/default_formatting_test.php
Expand Up @@ -68,7 +68,7 @@ public function get_default_formatting_tests()
),
array(
'[code]unparsed code[/code]',
'<div class="codebox"><p>CODE: <a href="#" onclick="selectCode(this); return false;">Select all</a></p><code>unparsed code</code></div>'
'<div class="codebox"><p>CODE: <a href="#" onclick="selectCode(this); return false;">Select all</a></p><pre><code>unparsed code</code></pre></div>'
),
array(
'[list]no item[/list]',
Expand Down Expand Up @@ -181,12 +181,12 @@ public function get_default_formatting_tests()
array(
// Do not parse textual bbcodes in code
'[code]unparsed code [b]bold [i]bold + italic[/i][/b][/code]',
'<div class="codebox"><p>CODE: <a href="#" onclick="selectCode(this); return false;">Select all</a></p><code>unparsed code [b]bold [i]bold + italic[/i][/b]</code></div>'
'<div class="codebox"><p>CODE: <a href="#" onclick="selectCode(this); return false;">Select all</a></p><pre><code>unparsed code [b]bold [i]bold + italic[/i][/b]</code></pre></div>'
),
array(
// Do not parse quote bbcodes in code
'[code]unparsed code [quote="username"]quoted[/quote][/code]',
'<div class="codebox"><p>CODE: <a href="#" onclick="selectCode(this); return false;">Select all</a></p><code>unparsed code [quote="username"]quoted[/quote]</code></div>'
'<div class="codebox"><p>CODE: <a href="#" onclick="selectCode(this); return false;">Select all</a></p><pre><code>unparsed code [quote="username"]quoted[/quote]</code></pre></div>'
),
array(
// Textual bbcode nesting into textual bbcode
Expand All @@ -195,7 +195,11 @@ public function get_default_formatting_tests()
),
array(
"[code]\tline1\n line2[/code]",
'<div class="codebox"><p>CODE: <a href="#" onclick="selectCode(this); return false;">Select all</a></p><code>&nbsp; &nbsp;line1<br>' . "\n" . '&nbsp; line2</code></div>'
'<div class="codebox"><p>CODE: <a href="#" onclick="selectCode(this); return false;">Select all</a></p><pre><code>' . "\tline1\n line2</code></pre></div>"
),
array(
"[code]\n\tline1\n line2[/code]",
'<div class="codebox"><p>CODE: <a href="#" onclick="selectCode(this); return false;">Select all</a></p><pre><code>' . "\tline1\n line2</code></pre></div>"
),
array(
'... http://example.org ...',
Expand Down
1 change: 1 addition & 0 deletions tests/text_processing/tickets_data/PHPBB3-11742.html
@@ -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>
1 change: 1 addition & 0 deletions tests/text_processing/tickets_data/PHPBB3-11742.txt
@@ -0,0 +1 @@
[code] tab[/code]

0 comments on commit 835a2eb

Please sign in to comment.