Commit 474f84e0 authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_corporate_identity: make inline anchors work

parent 4bc22d6c
...@@ -15,14 +15,13 @@ blank = "" ...@@ -15,14 +15,13 @@ blank = ""
header_current = 1 header_current = 1
header_initial = None header_initial = None
table_of_content = blank table_of_content = blank
index = 0
for header in re.findall("<h[1-6].*?</h[1-6]>", doc_content or blank): for header in re.findall("<h[1-6].*?</h[1-6]>", doc_content or blank):
header_level = header[2] header_level = header[2]
header_initial = header_initial or header_level header_initial = header_initial or header_level
header_reference = re.findall(">(.*)<", header)[0] header_reference = re.findall(">(.*)<", header)[0]
header_lowercase = header_reference.lower() header_lowercase = header_reference.lower()
header_reference_prefix = header_lowercase.replace(" ", "-") header_reference_prefix = header_lowercase.replace(" ", "-") + str(index)
if header_level == header_current: if header_level == header_current:
table_of_content += '</li>' table_of_content += '</li>'
...@@ -37,15 +36,16 @@ for header in re.findall("<h[1-6].*?</h[1-6]>", doc_content or blank): ...@@ -37,15 +36,16 @@ for header in re.findall("<h[1-6].*?</h[1-6]>", doc_content or blank):
table_of_content += '</li></ol>' * iterations table_of_content += '</li></ol>' * iterations
header_current = header_level header_current = header_level
index += 1
# add anchor in content # add anchor in content
snippet = ''.join(['>', header_reference]) snippet = ''.join(['>', header_reference])
named_snippet = ''.join([ named_snippet = ''.join([
'>', '>',
'<a name="', html_quote(header_reference_prefix), '_anchor"></a>', '<a name="', html_quote(header_reference_prefix), '_anchor"></a>',
header_reference, header_reference,
'<a class="custom-para" href=', doc_reference, '#', header_reference_prefix, '><span style="font-size:.75em;line-height:1em;padding-left:.5em;">&para;</span></a>' '<a class="custom-para" href=', '#', header_reference_prefix, '_anchor', '><span style="font-size:.75em;line-height:1em;padding-left:.5em;">&para;</span></a>'
]) ])
doc_content = doc_content.replace(snippet, named_snippet) doc_content = doc_content.replace(header, header.replace(snippet, named_snippet), 1)
# create table of content entry # create table of content entry
table_of_content += ''.join([ table_of_content += ''.join([
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment