mirror of
https://github.com/Kozea/WeasyPrint.git
synced 2024-10-04 07:57:52 +03:00
Allow absolute URLs without a base URL. Fix #42.
This commit is contained in:
parent
a80d65eef5
commit
89bd068990
@ -158,4 +158,4 @@ Windows
|
||||
<http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml>`_ for CFFI and lxml,
|
||||
* and `Alexander Shaduri’s GTK+ installer
|
||||
<http://gtk-win.sourceforge.net/home/index.php/Main/Downloads>`_.
|
||||
Make sure the *Set up PATH environment variable* checkbox is checked.
|
||||
Make sure that *Set up PATH environment variable* checked.
|
||||
|
@ -777,16 +777,20 @@ def test_links():
|
||||
"WARNING: Ignored `-weasy-link: url(../lipsum)` at 1:1, "
|
||||
"Relative URI reference without a base URI: '../lipsum'."])
|
||||
|
||||
# Internal URI reference without a base URI: OK
|
||||
# Internal or absolute URI reference without a base URI: OK
|
||||
assert_links('''
|
||||
<body style="width: 200px">
|
||||
<a href="#lipsum" id="lipsum" style="display: block; margin: 10px 5px">
|
||||
<a href="#lipsum" id="lipsum"
|
||||
style="display: block; margin: 10px 5px"></a>
|
||||
<a href="http://weasyprint.org/" style="display: block"></a>
|
||||
''', [[
|
||||
('internal', 'lipsum', (5, 10, 190, 0)),
|
||||
('external', 'http://weasyprint.org/', (0, 10, 200, 0)),
|
||||
]], [
|
||||
{'lipsum': (5, 10)}
|
||||
], [[
|
||||
('internal', (0, 5, 10), (5, 10, 190, 0)),
|
||||
('external', 'http://weasyprint.org/', (0, 10, 200, 0)),
|
||||
]], base_url=None)
|
||||
|
||||
assert_links('''
|
||||
|
@ -141,19 +141,18 @@ def get_link_attribute(element, attr_name):
|
||||
|
||||
"""
|
||||
attr_value = element.get(attr_name, '').strip()
|
||||
if attr_value.startswith('#'):
|
||||
if attr_value.startswith('#') and len(attr_value) > 1:
|
||||
# Do not require a base_url when the value is just a fragment.
|
||||
return 'internal', unquote(attr_value[1:])
|
||||
else:
|
||||
uri = get_url_attribute(element, attr_name)
|
||||
uri = get_url_attribute(element, attr_name)
|
||||
if uri:
|
||||
document_url = element_base_url(element)
|
||||
if uri and document_url:
|
||||
if document_url:
|
||||
parsed = urlsplit(uri)
|
||||
# Compare with fragments removed
|
||||
if parsed[:-1] == urlsplit(document_url)[:-1]:
|
||||
return 'internal', unquote(parsed.fragment)
|
||||
else:
|
||||
return 'external', uri
|
||||
return 'external', uri
|
||||
|
||||
|
||||
def ensure_url(string):
|
||||
|
Loading…
Reference in New Issue
Block a user