diff --git a/frontend_tests/node_tests/echo.js b/frontend_tests/node_tests/echo.js index e105189eff..a6517a5cbf 100644 --- a/frontend_tests/node_tests/echo.js +++ b/frontend_tests/node_tests/echo.js @@ -38,6 +38,7 @@ add_dependencies({ hashchange: 'js/hashchange', fenced_code: 'js/fenced_code.js', katex: 'node_modules/katex/dist/katex.min.js', + util: 'js/util.js', }); var doc = ""; @@ -184,6 +185,8 @@ var bugdown_data = JSON.parse(fs.readFileSync(path.join(__dirname, '../../zerver {input: '__hello__', expected: '
__hello__
'}, {input: '\n```\nfenced code\n```\n\nand then after\n', expected: 'fenced code\n
and then after
'}, + {input: '\n```\n fenced code trailing whitespace \n```\n\nand then after\n', + expected: 'fenced code trailing whitespace\n
and then after
'}, {input: '* a\n* list \n* here', expected: 'Hamlet once said
\ndef func():\n x = 1\n\n y = 2\n\n z = 3\n
And all was good.
", "bugdown_matches_marked": true }, + { + "name": "codeblock_trailing_whitespace", + "input": "Hamlet once said\n~~~~\ndef func():\n x = 1\n\n y = 2\t\t\n\n z = 3 \n~~~~\nAnd all was good.", + "expected_output": "Hamlet once said
\ndef func():\n x = 1\n\n y = 2\n\n z = 3\n
And all was good.
", + "bugdown_matches_marked": true + }, { "name": "codeblock_backticks", "input": "\n```\nfenced code\n```\n\n```inline code```\n", diff --git a/zerver/lib/bugdown/fenced_code.py b/zerver/lib/bugdown/fenced_code.py index 830ce0dd11..620044bbd5 100644 --- a/zerver/lib/bugdown/fenced_code.py +++ b/zerver/lib/bugdown/fenced_code.py @@ -37,6 +37,21 @@ Include tilde's in a code block and wrap with blank lines: ~~~~ +Removes trailing whitespace from code blocks that cause horizontal scrolling + >>> import markdown + >>> text = ''' + ... A paragraph before a fenced code block: + ... + ... ~~~ + ... Fenced code block \t\t\t\t\t\t\t + ... ~~~ + ... ''' + >>> html = markdown.markdown(text, extensions=['fenced_code']) + >>> print html +A paragraph before a fenced code block:
+Fenced code block
+
+
Language tags:
>>> text = '''
@@ -92,7 +107,7 @@ FENCE_RE = re.compile(u"""
""", re.VERBOSE)
-CODE_WRAP = u'%s
'
+CODE_WRAP = u'%s\n
'
LANG_TAG = u' class="%s"'
class FencedCodeExtension(markdown.Extension):
@@ -193,7 +208,7 @@ class FencedBlockPreprocessor(markdown.preprocessors.Preprocessor):
if line.rstrip() == self.fence:
self.done()
else:
- self.lines.append(line)
+ self.lines.append(line.rstrip())
def done(self):
# type: () -> None