Skip to content

Commit

Permalink
More explicit ConfigDict repr, fix html escape issue
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 582240366
  • Loading branch information
Conchylicultor authored and The etils Authors committed Nov 14, 2023
1 parent 5341645 commit 767a3ea
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Changelog follow https://keepachangelog.com/ format.
* Support specifiers to customize auto-display (`;s`, `;a`, `;i`,
`;p`,...)
* Fixed auto-display when the line contain UTF-8 character
* Fix a bug for `ecolab.highlight_html` to escape HTML string.

## [1.5.2] - 2023-10-24

Expand Down
12 changes: 7 additions & 5 deletions etils/ecolab/highlight_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

"""Syntax highlighting utils."""

from etils import epy
import html

from etils import epy
from etils.ecolab.inspects import resource_utils


Expand Down Expand Up @@ -47,12 +48,13 @@ def _repr_html_(self) -> str:
theme = resource_utils.resource_import(
'static/highlight.css', module='etils.ecolab'
)
html = """
# html
html_str = """
{theme}
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>
<script>hljs.highlightAll();</script>
<pre><code class="language-python">{code}</code></pre>
"""
html = epy.dedent(html)
html = html.format(theme=theme, code=code)
return html
html_str = epy.dedent(html_str)
html_str = html_str.format(theme=theme, code=html.escape(code))
return html_str

0 comments on commit 767a3ea

Please sign in to comment.