Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hub
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
thomasDOTwtf
hub
Commits
fc69c9fc
Commit
fc69c9fc
authored
4 months ago
by
cubicroot
Browse files
Options
Downloads
Patches
Plain Diff
Add ID attribute to headings in wiki
parent
e95b3fdc
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/core/markdown.py
+6
-1
6 additions, 1 deletion
src/core/markdown.py
src/core/tests/markdown.py
+9
-0
9 additions, 0 deletions
src/core/tests/markdown.py
with
15 additions
and
1 deletion
src/core/markdown.py
+
6
−
1
View file @
fc69c9fc
...
...
@@ -3,7 +3,7 @@ import re
import
bleach
import
mistletoe
from
mistletoe.block_token
import
BlockToken
from
mistletoe.block_token
import
BlockToken
,
Heading
from
mistletoe.html_renderer
import
HTMLRenderer
from
mistletoe.span_token
import
AutoLink
,
Link
,
SpanToken
,
tokenize_inner
...
...
@@ -118,6 +118,11 @@ class MyHtmlRenderer(HTMLRenderer):
inner
=
self
.
render_inner
(
token
)
return
template
.
format
(
target
=
target
,
title
=
title
,
inner
=
inner
,
link_type
=
link_type
)
def
render_heading
(
self
,
token
:
Heading
)
->
str
:
content
=
'
'
.
join
([
child
.
content
for
child
in
token
.
children
])
heading
=
f
'
<h
{
token
.
level
}
id=
"
{
slugify
(
content
)
}
"
>
{
content
}
</h
{
token
.
level
}
>
'
return
heading
def
render_auto_link
(
self
,
token
:
AutoLink
)
->
str
:
link_type
,
url
=
resolve_link
(
token
.
target
)
self
.
result
.
linked_urls
.
add
(
url
)
...
...
This diff is collapsed.
Click to expand it.
src/core/tests/markdown.py
+
9
−
0
View file @
fc69c9fc
...
...
@@ -135,3 +135,12 @@ class MarkdownTest(TestCase):
# triple sanity check: we expected four links total (one of them not to a user)
self
.
assertEqual
(
4
,
len
(
re
.
findall
(
'
<a
'
,
md_rendered
)))
@override_settings
(
SELECTED_CONFERENCE_ID
=
TEST_CONF_ID
)
def
test_headings
(
self
):
conf
=
Conference
(
name
=
'
foo
'
,
id
=
TEST_CONF_ID
)
conf
.
save
()
self
.
assertEqual
(
render_markdown
(
conf
,
'
# Heading 1
'
),
'
<h1 id=
"
heading-1
"
>Heading 1</h1>
\n
'
)
self
.
assertEqual
(
render_markdown
(
conf
,
'
## Heading with Ü
'
),
'
<h2 id=
"
heading-with-u
"
>Heading with Ü</h2>
\n
'
)
self
.
assertEqual
(
render_markdown
(
conf
,
'
Multi
\n
line
\n
======
'
),
'
<h1 id=
"
multi-line
"
>Multi line</h1>
\n
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment