diff options
author | Tristan Darricau <tristan.darricau@sensiolabs.com> | 2015-05-29 13:03:12 +0200 |
---|---|---|
committer | Tristan Darricau <tristan.darricau@sensiolabs.com> | 2015-05-29 13:03:12 +0200 |
commit | 835a2ebcb874377a7c450bea85b98d4d84cd0493 (patch) | |
tree | 67c1be522e964c5bd450195e0afca318c37343df | |
parent | 0e48d250d348cf451ebebe1fa89f3e9e3a992074 (diff) | |
parent | 3f52429e3d1548ca1faa203047d9326b0e6d4baa (diff) | |
download | forums-835a2ebcb874377a7c450bea85b98d4d84cd0493.tar forums-835a2ebcb874377a7c450bea85b98d4d84cd0493.tar.gz forums-835a2ebcb874377a7c450bea85b98d4d84cd0493.tar.bz2 forums-835a2ebcb874377a7c450bea85b98d4d84cd0493.tar.xz forums-835a2ebcb874377a7c450bea85b98d4d84cd0493.zip |
Merge pull request #3625 from s9e/ticket/11742
[ticket/11742] Remove tabs-to-space conversion in [code]
-rw-r--r-- | phpBB/composer.lock | 8 | ||||
-rw-r--r-- | phpBB/phpbb/textformatter/s9e/renderer.php | 43 | ||||
-rw-r--r-- | phpBB/styles/prosilver/template/bbcode.html | 4 | ||||
-rw-r--r-- | phpBB/styles/prosilver/theme/content.css | 1 | ||||
-rw-r--r-- | tests/text_formatter/s9e/default_formatting_test.php | 12 | ||||
-rw-r--r-- | tests/text_processing/tickets_data/PHPBB3-11742.html | 1 | ||||
-rw-r--r-- | tests/text_processing/tickets_data/PHPBB3-11742.txt | 1 |
7 files changed, 16 insertions, 54 deletions
diff --git a/phpBB/composer.lock b/phpBB/composer.lock index dc7608b37e..64927a409a 100644 --- a/phpBB/composer.lock +++ b/phpBB/composer.lock @@ -220,12 +220,12 @@ "source": { "type": "git", "url": "https://github.com/s9e/TextFormatter.git", - "reference": "29c5959f4425934a53b6fdb42760d719b95a6e82" + "reference": "0a6016ab96ab1da5be73f7a407f96f57d307b6b6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/29c5959f4425934a53b6fdb42760d719b95a6e82", - "reference": "29c5959f4425934a53b6fdb42760d719b95a6e82", + "url": "https://api.github.com/repos/s9e/TextFormatter/zipball/0a6016ab96ab1da5be73f7a407f96f57d307b6b6", + "reference": "0a6016ab96ab1da5be73f7a407f96f57d307b6b6", "shasum": "" }, "require": { @@ -270,7 +270,7 @@ "parser", "shortcodes" ], - "time": "2015-05-18 04:48:32" + "time": "2015-05-23 17:07:15" }, { "name": "symfony/config", diff --git a/phpBB/phpbb/textformatter/s9e/renderer.php b/phpBB/phpbb/textformatter/s9e/renderer.php index 8999f1d25f..51bc44f339 100644 --- a/phpBB/phpbb/textformatter/s9e/renderer.php +++ b/phpBB/phpbb/textformatter/s9e/renderer.php @@ -234,10 +234,6 @@ class renderer implements \phpbb\textformatter\renderer_interface } $html = $this->renderer->render($xml); - if (stripos($html, '<code') !== false) - { - $html = $this->replace_tabs_in_code($html); - } /** * Modify a rendered text @@ -254,45 +250,6 @@ class renderer implements \phpbb\textformatter\renderer_interface } /** - * 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", ' ', $code); - $code = str_replace(' ', ' ', $code); - $code = str_replace(' ', ' ', $code); - $code = str_replace("\n ", "\n ", $code); - - // keep space at the beginning - if (!empty($code) && $code[0] == ' ') - { - $code = ' ' . 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} */ public function set_smilies_path($path) diff --git a/phpBB/styles/prosilver/template/bbcode.html b/phpBB/styles/prosilver/template/bbcode.html index 3e38d13a32..af8e6ae4b0 100644 --- a/phpBB/styles/prosilver/template/bbcode.html +++ b/phpBB/styles/prosilver/template/bbcode.html @@ -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 --> diff --git a/phpBB/styles/prosilver/theme/content.css b/phpBB/styles/prosilver/theme/content.css index 380b285b83..85c3cb9f4c 100644 --- a/phpBB/styles/prosilver/theme/content.css +++ b/phpBB/styles/prosilver/theme/content.css @@ -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; diff --git a/tests/text_formatter/s9e/default_formatting_test.php b/tests/text_formatter/s9e/default_formatting_test.php index 79232562cf..2aa15146aa 100644 --- a/tests/text_formatter/s9e/default_formatting_test.php +++ b/tests/text_formatter/s9e/default_formatting_test.php @@ -68,7 +68,7 @@ class phpbb_textformatter_s9e_default_formatting_test extends phpbb_test_case ), 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]', @@ -181,12 +181,12 @@ class phpbb_textformatter_s9e_default_formatting_test extends phpbb_test_case 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 @@ -195,7 +195,11 @@ class phpbb_textformatter_s9e_default_formatting_test extends phpbb_test_case ), array( "[code]\tline1\n line2[/code]", - '<div class="codebox"><p>CODE: <a href="#" onclick="selectCode(this); return false;">Select all</a></p><code> line1<br>' . "\n" . ' 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 ...', diff --git a/tests/text_processing/tickets_data/PHPBB3-11742.html b/tests/text_processing/tickets_data/PHPBB3-11742.html new file mode 100644 index 0000000000..e7890eef19 --- /dev/null +++ b/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>
\ No newline at end of file diff --git a/tests/text_processing/tickets_data/PHPBB3-11742.txt b/tests/text_processing/tickets_data/PHPBB3-11742.txt new file mode 100644 index 0000000000..db72e5dda0 --- /dev/null +++ b/tests/text_processing/tickets_data/PHPBB3-11742.txt @@ -0,0 +1 @@ +[code] tab[/code]
\ No newline at end of file |