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
c8d93079
Commit
c8d93079
authored
Sep 28, 2013
by
benjaoming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix [TOC] compatibility with custom ids and add support for [[WikiLink]] #179
parent
c73d3310
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
74 additions
and
8 deletions
+74
-8
wiki/plugins/macros/mdx/macro.py
+9
-0
wiki/plugins/macros/mdx/toc.py
+2
-7
wiki/plugins/macros/mdx/wikilinks.py
+61
-0
wiki/plugins/macros/wiki_plugin.py
+2
-1
No files found.
wiki/plugins/macros/mdx/macro.py
View file @
c8d93079
...
...
@@ -83,3 +83,12 @@ class MacroPreprocessor(markdown.preprocessors.Preprocessor):
example_code
=
_
(
u'[TOC]'
),
args
=
{}
)
def
wikilink
(
self
):
return
""
toc
.
meta
=
dict
(
short_description
=
_
(
u'WikiLinks'
),
help_text
=
_
(
u'Insert a link to another wiki page with a short notation.'
),
example_code
=
_
(
u'[[WikiLink]]'
),
args
=
{}
)
wiki/plugins/macros/mdx/toc.py
View file @
c8d93079
...
...
@@ -118,11 +118,6 @@ class TocTreeprocessor(markdown.treeprocessors.Treeprocessor):
c
.
append
(
anchor
)
def
build_toc_etree
(
self
,
div
,
toc_list
):
# Add title to the div
if
self
.
config
[
"title"
]:
header
=
etree
.
SubElement
(
div
,
"span"
)
header
.
attrib
[
"class"
]
=
"toctitle"
header
.
text
=
self
.
config
[
"title"
]
def
build_etree_ul
(
toc_list
,
parent
):
ul
=
etree
.
SubElement
(
parent
,
"ul"
)
...
...
@@ -172,7 +167,7 @@ class TocTreeprocessor(markdown.treeprocessors.Treeprocessor):
p
[
i
]
=
div
break
marker_found
=
True
if
header_rgx
.
match
(
c
.
tag
):
# Do not override pre-existing ids
...
...
@@ -233,7 +228,7 @@ class TocExtension(markdown.Extension):
# by the header id extension) if both are used. Same goes for
# attr_list extension. This must come last because we don't want
# to redefine ids after toc is created. But we do want toc prettified.
md
.
treeprocessors
.
add
(
"toc"
,
tocext
,
"
<prettify
"
)
md
.
treeprocessors
.
add
(
"toc"
,
tocext
,
"
>headerid
"
)
def
makeExtension
(
configs
=
{}):
...
...
wiki/plugins/macros/mdx/wikilinks.py
0 → 100644
View file @
c8d93079
#!/usr/bin/env python
"""
Extend the shipped Markdown extension 'wikilinks'
"""
from
markdown.extensions
import
wikilinks
import
markdown
import
re
def
build_url
(
label
,
base
,
end
,
md
):
""" Build a url from the label, a base, and an end. """
clean_label
=
re
.
sub
(
r'([ ]+_)|(_[ ]+)|([ ]+)'
,
'_'
,
label
)
urlpaths
=
md
.
article
.
urlpath_set
.
all
()
# Nevermind about the base we are fed, just keep the original
# call pattern from the wikilinks plugin for later...
base
=
'/'
for
urlpath
in
urlpaths
:
if
urlpath
.
children
.
filter
(
slug
=
clean_label
)
.
exists
():
base
=
''
break
return
'
%
s
%
s
%
s'
%
(
base
,
clean_label
,
end
)
class
WikiLinkExtension
(
wikilinks
.
WikiLinkExtension
):
def
__init__
(
self
,
configs
=
{}):
# set extension defaults
self
.
config
=
{
'base_url'
:
[
''
,
'String to append to beginning or URL.'
],
'end_url'
:
[
'/'
,
'String to append to end of URL.'
],
'html_class'
:
[
'wiki_wikilink'
,
'CSS hook. Leave blank for none.'
],
'build_url'
:
[
build_url
,
'Callable formats URL from label.'
],
}
# Override defaults with user settings
for
key
,
value
in
configs
:
self
.
setConfig
(
key
,
value
)
def
extendMarkdown
(
self
,
md
,
md_globals
):
self
.
md
=
md
# append to end of inline patterns
WIKILINK_RE
=
r'\[\[([\w0-9_ -]+)\]\]'
wikilinkPattern
=
WikiLinks
(
WIKILINK_RE
,
self
.
getConfigs
())
wikilinkPattern
.
md
=
md
md
.
inlinePatterns
.
add
(
'wikilink'
,
wikilinkPattern
,
"<not_strong"
)
class
WikiLinks
(
wikilinks
.
WikiLinks
):
def
handleMatch
(
self
,
m
):
if
m
.
group
(
2
)
.
strip
():
base_url
,
end_url
,
html_class
=
self
.
_getMeta
()
label
=
m
.
group
(
2
)
.
strip
()
url
=
self
.
config
[
'build_url'
](
label
,
base_url
,
end_url
,
self
.
md
)
a
=
markdown
.
util
.
etree
.
Element
(
'a'
)
a
.
text
=
label
a
.
set
(
'href'
,
url
)
if
html_class
:
a
.
set
(
'class'
,
html_class
)
else
:
a
=
''
return
a
wiki/plugins/macros/wiki_plugin.py
View file @
c8d93079
...
...
@@ -7,6 +7,7 @@ from wiki.plugins.macros import settings
from
wiki.plugins.macros.mdx.macro
import
MacroExtension
from
wiki.plugins.macros.mdx.toc
import
WikiTocExtension
from
wiki.plugins.macros.mdx.wikilinks
import
WikiLinkExtension
class
MacroPlugin
(
BasePlugin
):
...
...
@@ -18,7 +19,7 @@ class MacroPlugin(BasePlugin):
'form_class'
:
None
,
'get_form_kwargs'
:
(
lambda
a
:
{})}
markdown_extensions
=
[
MacroExtension
(),
WikiTocExtension
()]
markdown_extensions
=
[
WikiLinkExtension
(),
MacroExtension
(),
WikiTocExtension
()]
def
__init__
(
self
):
pass
...
...
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