diff options
author | James Taylor <user234683@users.noreply.github.com> | 2021-08-08 20:29:42 -0700 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2021-08-09 12:27:49 -0500 |
commit | 6c6c469fbd4277d80b3309b796466c32ec19a0d0 (patch) | |
tree | c65314b3680b62c8e4c2d482b027b9900b3d042b /youtube/__init__.py | |
parent | 2039972ab32ac7d7ceb6be811a7d7d9019377b2c (diff) | |
download | yt-local-6c6c469fbd4277d80b3309b796466c32ec19a0d0.tar.lz yt-local-6c6c469fbd4277d80b3309b796466c32ec19a0d0.tar.xz yt-local-6c6c469fbd4277d80b3309b796466c32ec19a0d0.zip |
Prefix youtube URLs in video descriptions and channel about page
Closes #75
Signed-off-by: Jesús <heckyel@hyperbola.info>
Diffstat (limited to 'youtube/__init__.py')
-rw-r--r-- | youtube/__init__.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/youtube/__init__.py b/youtube/__init__.py index 08f4f6f..3604b21 100644 --- a/youtube/__init__.py +++ b/youtube/__init__.py @@ -2,6 +2,7 @@ from youtube import util from .get_app_version import app_version import flask from flask import request +import jinja2 import settings import traceback import re @@ -135,3 +136,17 @@ def get_css(): ), mimetype='text/css', ) + + +# This is okay because the flask urlize function puts the href as the first +# property +YOUTUBE_LINK_RE = re.compile(r'<a href="(' + util.YOUTUBE_URL_RE_STR + ')"') +old_urlize = jinja2.filters.urlize + + +def prefix_urlize(*args, **kwargs): + result = old_urlize(*args, **kwargs) + return YOUTUBE_LINK_RE.sub(r'<a href="/\1"', result) + + +jinja2.filters.urlize = prefix_urlize |