-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathadd_old_ids.py
More file actions
22 lines (19 loc) · 820 Bytes
/
add_old_ids.py
File metadata and controls
22 lines (19 loc) · 820 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import mkdocs.plugins
from bs4 import BeautifulSoup
@mkdocs.plugins.event_priority(-50)
def on_page_content(content, page, **kwargs):
path = page.file.src_uri
if (path == 'admin/configuration/toplevel.md' or
path == 'admin/configuration/modules.md' or
path == 'admin/configuration/listen.md' or
path == 'admin/configuration/listen-options.md' or
path == 'developer/ejabberd-api/admin-api.md' or
path == 'developer/ejabberd-api/admin-tags.md'):
return add_old_anchors(content)
def add_old_anchors(html):
soup = BeautifulSoup(html, 'html.parser')
for h2 in soup.find_all('h2'):
idcurrent = h2.get('id')
if idcurrent and '_' in idcurrent:
h2.insert_before(soup.new_tag('a', id=idcurrent.replace('_', '-')))
return str(soup)