From 6fe8de46be85fbec0c1d13752458bdedcc58117b Mon Sep 17 00:00:00 2001 From: XD-DENG Date: Tue, 2 Mar 2021 16:09:05 +0100 Subject: [PATCH 1/3] BugFix: fix DAG doc display (especially for TaskFlow DAGs) 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. --- airflow/www/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/airflow/www/utils.py b/airflow/www/utils.py index 45507ccd9d7775..2e815296a84508 100644 --- a/airflow/www/utils.py +++ b/airflow/www/utils.py @@ -337,6 +337,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'
' + markdown.markdown(s, extensions=['tables']) + "
") From 33b69565c8f9c2a24ac00c747447b279594e25fe Mon Sep 17 00:00:00 2001 From: XD-DENG Date: Tue, 2 Mar 2021 22:00:26 +0100 Subject: [PATCH 2/3] Add test --- tests/www/test_utils.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/www/test_utils.py b/tests/www/test_utils.py index f6e53e4dbfbe16..956a98972bbaf7 100644 --- a/tests/www/test_utils.py +++ b/tests/www/test_utils.py @@ -245,3 +245,16 @@ def test_wrapped_markdown_with_table(self): '\n14m\n\n\n' '' ) == rendered + + def test_wrapped_markdown_with_indented_lines(self): + rendered = wrapped_markdown( + """ + # header + 1st line + 2nd line + """ + ) + + assert ( + '

header

\n

1st line\n2nd line

' + ) == rendered From dedd0223be618381e23e2fe5309e3d723e1f1ceb Mon Sep 17 00:00:00 2001 From: XD-DENG Date: Tue, 2 Mar 2021 22:32:37 +0100 Subject: [PATCH 3/3] Fixup --- tests/www/test_utils.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/www/test_utils.py b/tests/www/test_utils.py index 956a98972bbaf7..5ced73a6a7700d 100644 --- a/tests/www/test_utils.py +++ b/tests/www/test_utils.py @@ -255,6 +255,4 @@ def test_wrapped_markdown_with_indented_lines(self): """ ) - assert ( - '

header

\n

1st line\n2nd line

' - ) == rendered + assert '

header

\n

1st line\n2nd line

' == rendered