ubuntu-touch-coreapps-reviewers team mailing list archive
-
ubuntu-touch-coreapps-reviewers team
-
Mailing list archive
-
Message #02041
[Merge] lp:~dholbach/help-app/1433525 into lp:help-app
Daniel Holbach has proposed merging lp:~dholbach/help-app/1433525 into lp:help-app.
Commit message:
Add markdown extension to make external links use target="_blank".
Requested reviews:
Ubuntu Help app developers (help-app-dev)
Related bugs:
Bug #1433525 in Ubuntu Help App: "use target="_blank" to open links in the browser"
https://bugs.launchpad.net/help-app/+bug/1433525
For more details, see:
https://code.launchpad.net/~dholbach/help-app/1433525/+merge/258866
Add markdown extension to make external links use target="_blank".
--
Your team Ubuntu Help app developers is requested to review the proposed merge of lp:~dholbach/help-app/1433525 into lp:help-app.
=== modified file 'HACKING'
--- HACKING 2015-03-31 12:27:56 +0000
+++ HACKING 2015-05-12 11:48:12 +0000
@@ -86,7 +86,7 @@
sudo apt install python-pelican po4a make bzrtools \
ubuntu-html5-ui-toolkit python3-polib python3-magic \
- python3-markdown pep8 pyflakes
+ python3-markdown pep8 pyflakes python-magic python-polib
This will install the necessary files, so you can build the app or web build
locally and check if your changes actually make sense and look and work well.
=== modified file 'debian/control'
--- debian/control 2015-03-25 10:14:27 +0000
+++ debian/control 2015-05-12 11:48:12 +0000
@@ -8,6 +8,8 @@
po4a,
pyflakes,
python-pelican (>= 3.5.0~),
+ python-magic,
+ python-polib,
python3-magic,
python3-markdown,
python3-polib,
=== added file 'internals/local/external-links.py'
--- internals/local/external-links.py 1970-01-01 00:00:00 +0000
+++ internals/local/external-links.py 2015-05-12 11:48:12 +0000
@@ -0,0 +1,26 @@
+from __future__ import absolute_import
+from __future__ import unicode_literals
+from markdown import Extension
+from markdown.treeprocessors import Treeprocessor
+
+from translations.utils import link_is_local
+
+
+class ExternalLinksProcessor(Treeprocessor):
+ def run(self, doc):
+ for elem in doc.iter('a'):
+ if 'href' in elem.attrib and \
+ not link_is_local(elem.get('href')):
+ elem.set('target', '_blank')
+
+
+class ExternalLinksExtension(Extension):
+ def extendMarkdown(self, md, md_globals):
+ md.treeprocessors.add('external-links',
+ ExternalLinksProcessor(md.parser),
+ '_end')
+ md.registerExtension(self)
+
+
+def makeExtension(*args, **kwargs):
+ return ExternalLinksExtension(*args, **kwargs)
=== modified file 'internals/pelicanconf.py'
--- internals/pelicanconf.py 2015-03-31 08:18:07 +0000
+++ internals/pelicanconf.py 2015-05-12 11:48:12 +0000
@@ -54,7 +54,7 @@
TAG_SAVE_AS = ''
THEME = TOP_LEVEL_DIR+'static/themes/app/'
-MD_EXTENSIONS = ['local.q-and-a', 'attr_list', 'toc']
+MD_EXTENSIONS = ['local.q-and-a', 'local.external-links', 'attr_list', 'toc']
META_TAGS = [
'[TOC]',
=== modified file 'internals/tests/test_links.py'
--- internals/tests/test_links.py 2015-03-31 06:25:44 +0000
+++ internals/tests/test_links.py 2015-05-12 11:48:12 +0000
@@ -5,9 +5,12 @@
import subprocess
import tempfile
from unittest import TestCase
-import urllib.parse
-from translations.utils import use_top_level_dir
+from translations.utils import (
+ link_is_anchor,
+ link_is_local,
+ use_top_level_dir,
+)
def require_build(build):
@@ -34,11 +37,9 @@
def handle_starttag(self, tag, attrs):
if tag == "a":
for name, value in attrs:
- if name == "href":
- url = urllib.parse.urlparse(value)
- if not value.startswith('#') and \
- url.netloc in [None, '', 'localhost']:
- self.links += [value]
+ if name == "href" and not link_is_anchor(value) and \
+ link_is_local(value):
+ self.links += [value]
def reload(self):
links = self.links
=== modified file 'internals/translations/build.py'
--- internals/translations/build.py 2015-03-31 11:38:30 +0000
+++ internals/translations/build.py 2015-05-12 11:48:12 +0000
@@ -20,7 +20,7 @@
try:
import polib
except ImportError:
- require('python3-polib')
+ require('python3-polib pyton-polib')
from pelicanconf import (
DOCS_PATH,
=== modified file 'internals/translations/utils.py'
--- internals/translations/utils.py 2015-03-31 07:57:56 +0000
+++ internals/translations/utils.py 2015-05-12 11:48:12 +0000
@@ -1,6 +1,10 @@
import os
import sys
import tempfile
+if sys.version_info.major == 2:
+ import urlparse
+else:
+ import urllib.parse
def require(package):
@@ -11,7 +15,7 @@
try:
import magic
except:
- require('python3-magic')
+ require('python3-magic python-magic')
try:
import markdown
@@ -37,6 +41,18 @@
]
+def link_is_anchor(link):
+ return link.startswith('#')
+
+
+def link_is_local(link):
+ if sys.version_info.major == 2:
+ url = urlparse.urlparse(link)
+ else:
+ url = urllib.parse.urlparse(link)
+ return url.netloc in [None, '', 'localhost']
+
+
def normalise_path(path):
return os.path.relpath(path, TOP_LEVEL_DIR)
Follow ups