Skip to content

How can I create an HTML notification like in the diff view? #1997

Answered by weikinhuang
geimist asked this question in Q&A
Discussion options

You must be logged in to vote

I figured it out with a jinja template

{%- set lines = diff_patch.replace('<br>', '\n').splitlines() -%}
<pre style="padding: 16px 0">
{%- for line in lines %}
{%- if line.startswith("---") or line.startswith("+++") %}
<span>{{ line }}</span>
{%- elif line.startswith("-") %}
<del style="text-decoration: none; color: #b30000; background: #fadad7">{{ line }}</del>
{%- elif line.startswith("+") %}
<ins style="text-decoration: none; color: #406619; background: #eaf2c2">{{ line }}</ins>
{%- else %}
<span>{{ line }}</span>
{%- endif %}
{%- endfor %}
</pre>

Replies: 3 comments 8 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
6 replies
@dgtlmoon
Comment options

@dgtlmoon
Comment options

@weikinhuang
Comment options

@dgtlmoon
Comment options

@weikinhuang
Comment options

Answer selected by dgtlmoon
Comment options

You must be logged in to vote
2 replies
@dgtlmoon
Comment options

@geimist
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants