Skip to content

Commit

Permalink
BugFix: fix DAG doc display (especially for TaskFlow DAGs) (#14564)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
XD-DENG authored Mar 2, 2021
1 parent 8fdee9d commit 22e3a4c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions airflow/www/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'<div class="{css_class}" >' + markdown.markdown(s, extensions=['tables']) + "</div>")


Expand Down
11 changes: 11 additions & 0 deletions tests/www/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,14 @@ def test_wrapped_markdown_with_table(self):
'</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

0 comments on commit 22e3a4c

Please sign in to comment.