55 | 55 |
|
56 | 56 |
def extract_links_from_documents(documents):
|
57 | 57 |
links = []
|
|
58 |
|
|
59 |
def make_link(url, section=None, **kwargs):
|
|
60 |
link = {
|
|
61 |
'url': url,
|
|
62 |
}
|
|
63 |
if section:
|
|
64 |
link.update({
|
|
65 |
'section': section.title,
|
|
66 |
'document': section.document.title,
|
|
67 |
})
|
|
68 |
link.update(kwargs)
|
|
69 |
return link
|
|
70 |
|
|
71 |
def extend_links(section, md):
|
|
72 |
links.extend([make_link(url, section=section) for url in extract_links(markdown_to_html5(md))])
|
|
73 |
|
58 | 74 |
for document in documents:
|
59 | 75 |
for name, url in document.reference_links:
|
60 | |
links.append((url, None))
|
|
76 |
links.append(make_link(url, name=name))
|
61 | 77 |
for section in document.sections:
|
62 | 78 |
for (name, url) in section.images:
|
63 | |
links.append((url, section))
|
|
79 |
links.append(make_link(url, section=section, name=name))
|
64 | 80 |
for key, value in section.properties.iteritems():
|
65 | 81 |
if isinstance(value, list):
|
66 | 82 |
for subitem in value:
|
67 | |
links.extend([(url, section) for url in extract_links(markdown_to_html5(subitem))])
|
|
83 |
extend_links(section, subitem)
|
68 | 84 |
else:
|
69 | |
links.extend([(url, section) for url in extract_links(markdown_to_html5(value))])
|
|
85 |
extend_links(section, value)
|
70 | 86 |
for name, url in section.reference_links:
|
71 | |
links.append((url, section))
|
72 | |
links.extend([(url, section) for url in extract_links(markdown_to_html5(section.body))])
|
|
87 |
links.append(make_link(url, section=section, name=name))
|
|
88 |
extend_links(section, section.body)
|
73 | 89 |
return links
|