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
1e9d5b56
Commit
1e9d5b56
authored
Feb 22, 2013
by
benjaoming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove print stm
parent
bcddb0b3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
102 deletions
+0
-102
wiki/plugins/macros/markdown_extensions.py
+0
-101
wiki/plugins/macros/mdx/toc.py
+0
-1
No files found.
wiki/plugins/macros/markdown_extensions.py
deleted
100644 → 0
View file @
bcddb0b3
# -*- coding: utf-8 -*-
import
markdown
import
re
from
django.utils.translation
import
ugettext
as
_
from
django.template.loader
import
render_to_string
from
django.template
import
Context
# See: http://stackoverflow.com/questions/430759/regex-for-managing-escaped-characters-for-items-like-string-literals
re_sq_short
=
r"'([^'\\]*(?:\\.[^'\\]*)*)'"
MACRO_RE
=
re
.
compile
(
r'.*(\[(?P<macro>\w+)(?P<kwargs>\s\w+\:.+)*\]).*'
,
re
.
IGNORECASE
)
KWARG_RE
=
re
.
compile
(
r'\s*(?P<arg>\w+)(:(?P<value>([^\']+|
%
s)))?'
%
re_sq_short
,
re
.
IGNORECASE
)
class
SimplePreprocessorExtension
(
markdown
.
Extension
):
"""Extend this class to create a simple [name arg:val] markdown tag
and replace each tag with your own html stack"""
UNSET
=
"OVERRIDE THIS"
markdown_id
=
UNSET
tagname
=
UNSET
def
extendMarkdown
(
self
,
md
,
md_globals
):
if
SimplePreprocessorExtension
.
UNSET
in
(
self
.
markdown_id
,
self
.
tagname
):
raise
NotImplementedError
(
"You need to set all required properties"
)
""" Insert ImagePreprocessor before ReferencePreprocessor. """
md
.
preprocessors
.
add
(
'dw-
%
s'
%
self
.
markdown_id
,
self
.
get_preprocessor
(
md
,
self
.
tagname
),
'>html_block'
)
def
get_preprocessor
(
self
,
md
,
tagname
):
return
SimplePreprocessor
(
md
,
tagname
)
class
Preprocessor
(
markdown
.
preprocessors
.
Preprocessor
):
pass
from
wiki.plugins.macros
import
settings
class
MacroExtension
(
markdown
.
Extension
):
""" Macro plugin markdown extension for django-wiki. """
def
extendMarkdown
(
self
,
md
,
md_globals
):
""" Insert MacroPreprocessor before ReferencePreprocessor. """
md
.
preprocessors
.
add
(
'dw-macros'
,
MacroPreprocessor
(
md
),
'>html_block'
)
class
MacroPreprocessor
(
markdown
.
preprocessors
.
Preprocessor
):
"""django-wiki macro preprocessor - parse text for various [some_macro] and
[some_macro (kw:arg)*] references. """
allowed_methods
=
settings
.
METHODS
def
run
(
self
,
lines
):
# Look at all those indentations.
# That's insane, let's get a helper library
# Please note that this pattern is also in plugins.images
new_text
=
[]
for
line
in
lines
:
m
=
MACRO_RE
.
match
(
line
)
if
m
:
macro
=
m
.
group
(
'macro'
)
.
strip
()
if
macro
in
MacroPreprocessor
.
allowed_methods
:
kwargs
=
m
.
group
(
'kwargs'
)
if
kwargs
:
kwargs_dict
=
{}
for
kwarg
in
KWARG_RE
.
finditer
(
kwargs
):
arg
=
kwarg
.
group
(
'arg'
)
value
=
kwarg
.
group
(
'value'
)
if
value
is
None
:
value
=
True
if
isinstance
(
value
,
basestring
):
# If value is enclosed with ': Remove and remove escape sequences
if
value
.
startswith
(
u"'"
)
and
len
(
value
)
>
2
:
value
=
value
[
1
:
-
1
]
value
=
value
.
replace
(
u"
\\\\
"
,
u"¤KEEPME¤"
)
value
=
value
.
replace
(
u"
\\
"
,
u""
)
value
=
value
.
replace
(
u"¤KEEPME¤"
,
u"
\\
"
)
kwargs_dict
[
str
(
arg
)]
=
value
line
=
getattr
(
self
,
macro
)(
**
kwargs_dict
)
else
:
line
=
getattr
(
self
,
macro
)()
if
not
line
is
None
:
new_text
.
append
(
line
)
return
new_text
def
article_list
(
self
,
depth
=
"2"
):
html
=
render_to_string
(
"wiki/plugins/macros/article_list.html"
,
Context
({
'article_children'
:
self
.
markdown
.
article
.
get_children
(
article__current_revision__deleted
=
False
),
'depth'
:
int
(
depth
)
+
1
,
})
)
return
self
.
markdown
.
htmlStash
.
store
(
html
,
safe
=
True
)
article_list
.
meta
=
dict
(
short_description
=
_
(
u'Article list'
),
help_text
=
_
(
u'Insert a list of articles in this level.'
),
example_code
=
_
(
u'[article_list depth:2]'
),
args
=
{
'depth'
:
_
(
'Maximum depth to show levels for.'
)}
)
wiki/plugins/macros/mdx/toc.py
View file @
1e9d5b56
...
@@ -255,5 +255,4 @@ class WikiTocExtension(TocExtension):
...
@@ -255,5 +255,4 @@ class WikiTocExtension(TocExtension):
def
extendMarkdown
(
self
,
md
,
md_globals
):
def
extendMarkdown
(
self
,
md
,
md_globals
):
if
'toc'
in
settings
.
METHODS
:
if
'toc'
in
settings
.
METHODS
:
print
md
,
md_globals
TocExtension
.
extendMarkdown
(
self
,
md
,
md_globals
)
TocExtension
.
extendMarkdown
(
self
,
md
,
md_globals
)
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