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():
82
82
"<style>" + HtmlFormatter (style = "friendly" ).get_style_defs (".highlight" ) + "</style>" , unsafe_allow_html = True
83
83
)
84
84
85
- WIDTH = 80
85
+ WIDTH = 140
86
86
87
87
88
88
def 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
+
89
97
wrap = textwrap .fill (t , width = width , replace_whitespace = False )
90
98
out = highlight (wrap , DjangoLexer (), HtmlFormatter ())
99
+ out = replace_linebreaks (out )
91
100
st .write (out , unsafe_allow_html = True )
92
101
93
102
You can’t perform that action at this time.
0 commit comments