Skip to content

Commit

Permalink
Feature: detect http links in log lines and output them as links.
Browse files Browse the repository at this point in the history
  • Loading branch information
frosch123 authored and TrueBrain committed May 24, 2021
1 parent 65b4071 commit ecb1c89
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions plugins/WebLogsS3/render_day.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import html
import os
import re
import urllib.parse

FIRST_LOGDATE = {}

Expand Down Expand Up @@ -105,6 +106,13 @@ def render_day(base_url, channel, date, has_prev_day=None):
text = html.escape(text)
anchor = f'{time.replace(":", "")}-{lineno}'

# Detect links
text = re.sub(
r"\bhttps?:\/\/([^\s()\.,]|\([^)\s]*\)|[\.,]\S)+",
lambda m: f'<a href="{urllib.parse.quote(html.unescape(m.group()), safe="/:")}">{m.group()}</a>',
text,
)

classname = "text"
if text.startswith("***"):
# Remove the *** and username
Expand Down

0 comments on commit ecb1c89

Please sign in to comment.