From 1cbf264e37cbbed86102ed43b41fc571e7c11063 Mon Sep 17 00:00:00 2001
From: Bob Mottram
Date: Wed, 21 Aug 2019 13:07:30 +0100
Subject: [PATCH] Add web links
---
content.py | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/content.py b/content.py
index a3fa40e2..caabb179 100644
--- a/content.py
+++ b/content.py
@@ -10,6 +10,29 @@ import os
import commentjson
from shutil import copyfile
+def addWebLinks(content: str) -> str:
+ """Adds markup for web links
+ """
+ if not ('https://' in content or 'http://' in content):
+ return content
+
+ words=content.split(' ')
+ replaceDict={}
+ for w in words:
+ if w.startswith('http://') or w.startswith('http://'):
+ if w.endswith('.') or w.endswith(';'):
+ w=w[:-1]
+ markup=''
+ if w.startswith('https://'):
+ markup+='https://'
+ elif w.startswith('http://'):
+ markup+='http://'
+ markup+=''+w.replace('https://','').replace('http://','')+''
+ replaceDict[w]=markup
+ for url,markup in replaceDict.items():
+ content=content.replace(url,markup)
+ return content
+
def validHashTag(hashtag: str) -> bool:
"""Returns true if the give hashtag contains valid characters
"""
@@ -221,6 +244,7 @@ def addHtmlTags(baseDir: str,httpPrefix: str, \
content=content.replace(wordStr,replaceStr)
content=content.replace('\n','
')
+ content=addWebLinks(content)
return '
'+content+'
'
def getMentionsFromHtml(htmlText: str,matchStr=" []: