This is an automated email from the ASF dual-hosted git repository. ash pushed a commit to branch v2-1-test in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 4c06aaebde277ce037de0ed81ec9d91a28b798bf Author: Tzu-ping Chung <[email protected]> AuthorDate: Sun Jun 13 08:30:11 2021 +0800 Clean Markdown with dedent to respect indents (#16414) (cherry picked from commit 6f9c0ceeb40947c226d35587097529d04c3e3e59) --- airflow/www/utils.py | 5 ++--- tests/www/test_utils.py | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/airflow/www/utils.py b/airflow/www/utils.py index b0c93ba..e0ba0db 100644 --- a/airflow/www/utils.py +++ b/airflow/www/utils.py @@ -16,6 +16,7 @@ # specific language governing permissions and limitations # under the License. import json +import textwrap import time from urllib.parse import urlencode @@ -344,9 +345,7 @@ def wrapped_markdown(s, css_class='rich_doc'): """Convert a Markdown string to HTML.""" if s is None: return None - - s = '\n'.join(line.lstrip() for line in s.split('\n')) - + s = textwrap.dedent(s) return Markup(f'<div class="{css_class}" >' + markdown.markdown(s, extensions=['tables']) + "</div>") diff --git a/tests/www/test_utils.py b/tests/www/test_utils.py index 8f381a5..01c49e1 100644 --- a/tests/www/test_utils.py +++ b/tests/www/test_utils.py @@ -218,3 +218,39 @@ class TestWrappedMarkdown(unittest.TestCase): ) assert '<div class="rich_doc" ><h1>header</h1>\n<p>1st line\n2nd line</p></div>' == rendered + + def test_wrapped_markdown_with_raw_code_block(self): + rendered = wrapped_markdown( + """\ + # Markdown code block + + Inline `code` works well. + + Code block + does not + respect + newlines + + """ + ) + + assert ( + '<div class="rich_doc" ><h1>Markdown code block</h1>\n' + '<p>Inline <code>code</code> works well.</p>\n' + '<pre><code>Code block\ndoes not\nrespect\nnewlines\n</code></pre></div>' + ) == rendered + + def test_wrapped_markdown_with_nested_list(self): + rendered = wrapped_markdown( + """ + ### Docstring with a code block + + - And + - A nested list + """ + ) + + assert ( + '<div class="rich_doc" ><h3>Docstring with a code block</h3>\n' + '<ul>\n<li>And<ul>\n<li>A nested list</li>\n</ul>\n</li>\n</ul></div>' + ) == rendered
