You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by as...@apache.org on 2021/03/19 15:06:29 UTC

[airflow] 27/42: BugFix: fix DAG doc display (especially for TaskFlow DAGs) (#14564)

This is an automated email from the ASF dual-hosted git repository.

ash pushed a commit to branch v2-0-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit a1560534f6936ac2758dd64d15eeb980b91ff11a
Author: Xiaodong DENG <xd...@apache.org>
AuthorDate: Wed Mar 3 00:11:07 2021 +0100

    BugFix: fix DAG doc display (especially for TaskFlow DAGs) (#14564)
    
    Because of how TaskFlow DAGs are constructed, their __doc__ lines
    may start with spaces. This fails markdown.markdown(), and the
    doc in Markdown format cannot be transformed into HTML properly,
    and further fails the doc display in the UI.
    
    This commit fixes this by always doing left strip for each line for the doc md.
    
    (cherry picked from commit 22e3a4cc01d31024ffaa6c9c7767eec8467a9df7)
---
 airflow/www/utils.py    |  2 ++
 tests/www/test_utils.py | 11 +++++++++++
 2 files changed, 13 insertions(+)

diff --git a/airflow/www/utils.py b/airflow/www/utils.py
index 265a12f..afd94c6 100644
--- a/airflow/www/utils.py
+++ b/airflow/www/utils.py
@@ -326,6 +326,8 @@ def wrapped_markdown(s, css_class=None):
     if s is None:
         return None
 
+    s = '\n'.join(line.lstrip() for line in s.split('\n'))
+
     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 f6e53e4..5ced73a 100644
--- a/tests/www/test_utils.py
+++ b/tests/www/test_utils.py
@@ -245,3 +245,14 @@ class TestWrappedMarkdown(unittest.TestCase):
             '</td>\n<td>14m</td>\n</tr>\n</tbody>\n'
             '</table></div>'
         ) == rendered
+
+    def test_wrapped_markdown_with_indented_lines(self):
+        rendered = wrapped_markdown(
+            """
+                # header
+                1st line
+                2nd line
+            """
+        )
+
+        assert '<div class="None" ><h1>header</h1>\n<p>1st line\n2nd line</p></div>' == rendered