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
67d8cf38
Commit
67d8cf38
authored
Feb 03, 2013
by
benjaoming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Security fix, do not call eval on input
parent
d9d19f0d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
27 additions
and
3 deletions
+27
-3
wiki/plugins/images/markdown_extensions.py
+1
-0
wiki/plugins/links/mdx/djangowikilinks.py
+1
-0
wiki/plugins/links/mdx/urlize.py
+1
-0
wiki/plugins/macros/markdown_extensions.py
+23
-3
wiki/plugins/macros/settings.py
+1
-0
No files found.
wiki/plugins/images/markdown_extensions.py
View file @
67d8cf38
# -*- coding: utf-8 -*-
import
markdown
import
markdown
import
re
import
re
...
...
wiki/plugins/links/mdx/djangowikilinks.py
View file @
67d8cf38
#!/usr/bin/env python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
'''
Wikipath Extension for Python-Markdown
Wikipath Extension for Python-Markdown
...
...
wiki/plugins/links/mdx/urlize.py
View file @
67d8cf38
# -*- coding: utf-8 -*-
"""
"""
Code modified from:
Code modified from:
https://github.com/r0wb0t/markdown-urlize
https://github.com/r0wb0t/markdown-urlize
...
...
wiki/plugins/macros/markdown_extensions.py
View file @
67d8cf38
# -*- coding: utf-8 -*-
import
markdown
import
markdown
import
re
import
re
...
@@ -5,8 +6,11 @@ from django.utils.translation import ugettext as _
...
@@ -5,8 +6,11 @@ from django.utils.translation import ugettext as _
from
django.template.loader
import
render_to_string
from
django.template.loader
import
render_to_string
from
django.template
import
Context
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
)
MACRO_RE
=
re
.
compile
(
r'.*(\[(?P<macro>\w+)(?P<kwargs>\s\w+\:.+)*\]).*'
,
re
.
IGNORECASE
)
KWARG_RE
=
re
.
compile
(
r'
([^ |:]+):([^ |$]+)'
,
re
.
IGNORECASE
)
KWARG_RE
=
re
.
compile
(
r'
\s*(?P<arg>\w+)(:(?P<value>([^\']|
%
s)))?'
%
re_sq_short
,
re
.
IGNORECASE
)
from
wiki.plugins.macros
import
settings
from
wiki.plugins.macros
import
settings
...
@@ -25,6 +29,9 @@ class MacroPreprocessor(markdown.preprocessors.Preprocessor):
...
@@ -25,6 +29,9 @@ class MacroPreprocessor(markdown.preprocessors.Preprocessor):
allowed_methods
=
settings
.
METHODS
allowed_methods
=
settings
.
METHODS
def
run
(
self
,
lines
):
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
=
[]
new_text
=
[]
for
line
in
lines
:
for
line
in
lines
:
m
=
MACRO_RE
.
match
(
line
)
m
=
MACRO_RE
.
match
(
line
)
...
@@ -33,8 +40,21 @@ class MacroPreprocessor(markdown.preprocessors.Preprocessor):
...
@@ -33,8 +40,21 @@ class MacroPreprocessor(markdown.preprocessors.Preprocessor):
if
macro
in
MacroPreprocessor
.
allowed_methods
:
if
macro
in
MacroPreprocessor
.
allowed_methods
:
kwargs
=
m
.
group
(
'kwargs'
)
kwargs
=
m
.
group
(
'kwargs'
)
if
kwargs
:
if
kwargs
:
kwargs
=
eval
(
'{'
+
KWARG_RE
.
sub
(
r'"\1":"\2",'
,
kwargs
)
+
'}'
)
kwargs_dict
=
{}
line
=
getattr
(
self
,
macro
)(
**
kwargs
)
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
[
arg
]
=
value
line
=
getattr
(
self
,
macro
)(
**
kwargs_dict
)
else
:
else
:
line
=
getattr
(
self
,
macro
)()
line
=
getattr
(
self
,
macro
)()
if
not
line
is
None
:
if
not
line
is
None
:
...
...
wiki/plugins/macros/settings.py
View file @
67d8cf38
# -*- coding: utf-8 -*-
from
django.conf
import
settings
as
django_settings
from
django.conf
import
settings
as
django_settings
SLUG
=
'macros'
SLUG
=
'macros'
...
...
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