Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-wiki
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
django-wiki
Commits
d7465435
Commit
d7465435
authored
Apr 06, 2013
by
benjaoming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#140 - Markdown 2.2/2.3 API change - do not rely on markdown.extensions.headerid.unique
parent
f6eb8be3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
5 deletions
+19
-5
wiki/plugins/macros/mdx/toc.py
+19
-5
No files found.
wiki/plugins/macros/mdx/toc.py
View file @
d7465435
...
...
@@ -17,12 +17,24 @@ Until it's released, we have a copy here.
"""
import
markdown
from
markdown.util
import
etree
from
markdown.extensions.headerid
import
slugify
,
unique
,
itertext
from
markdown.extensions.headerid
import
slugify
,
itertext
import
re
from
wiki.plugins.macros
import
settings
IDCOUNT_RE
=
re
.
compile
(
r'^(.*)_([0-9]+)$'
)
def
unique
(
elem_id
,
ids
):
""" Ensure id is unique in set of ids. Append '_1', '_2'... if not """
while
elem_id
in
ids
:
m
=
IDCOUNT_RE
.
match
(
elem_id
)
if
m
:
elem_id
=
'
%
s_
%
d'
%
(
m
.
group
(
1
),
int
(
m
.
group
(
2
))
+
1
)
else
:
elem_id
=
'
%
s_
%
d'
%
(
elem_id
,
1
)
ids
.
add
(
elem_id
)
return
elem_id
def
order_toc_list
(
toc_list
):
"""Given an unsorted list with errors and skips, return a nested one.
[{'level': 1}, {'level': 2}]
...
...
@@ -135,10 +147,10 @@ class TocTreeprocessor(markdown.treeprocessors.Treeprocessor):
self
.
use_anchors
=
self
.
config
[
"anchorlink"
]
in
[
1
,
'1'
,
True
,
'True'
,
'true'
]
# Get a list of id attributes
used_ids
=
[]
used_ids
=
set
()
for
c
in
doc
.
getiterator
():
if
"id"
in
c
.
attrib
:
used_ids
.
a
ppen
d
(
c
.
attrib
[
"id"
])
used_ids
.
a
d
d
(
c
.
attrib
[
"id"
])
toc_list
=
[]
marker_found
=
False
...
...
@@ -172,9 +184,11 @@ class TocTreeprocessor(markdown.treeprocessors.Treeprocessor):
tag_level
=
int
(
c
.
tag
[
-
1
])
toc_list
.
append
({
'level'
:
tag_level
,
toc_list
.
append
({
'level'
:
tag_level
,
'id'
:
elem_id
,
'name'
:
c
.
text
})
'name'
:
c
.
text
})
self
.
add_anchor
(
c
,
elem_id
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment