File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -82,12 +82,21 @@ def reset_template_state():
8282 "<style>" + HtmlFormatter (style = "friendly" ).get_style_defs (".highlight" ) + "</style>" , unsafe_allow_html = True
8383)
8484
85- WIDTH = 80
85+ WIDTH = 140
8686
8787
8888def show_jinja (t , width = WIDTH ):
89+ def replace_linebreaks (t ):
90+ """
91+ st.write does not handle double breaklines very well. When it encounters `\n \n `, it exit the curent <div> block.
92+ Explicitely replacing all `\n ` with their html equivalent to bypass this issue.
93+ Also stripping the trailing `\n ` first.
94+ """
95+ return t .strip ("\n " ).replace ("\n " , "<br/>" )
96+
8997 wrap = textwrap .fill (t , width = width , replace_whitespace = False )
9098 out = highlight (wrap , DjangoLexer (), HtmlFormatter ())
99+ out = replace_linebreaks (out )
91100 st .write (out , unsafe_allow_html = True )
92101
93102
You can’t perform that action at this time.
0 commit comments