Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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
edx
edx-platform
Commits
4a664d88
Commit
4a664d88
authored
Feb 07, 2012
by
Bridger Maxwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added new wiki link format. [Some Article](wiki:SomeArticle)
parent
ad027253
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
46 deletions
+45
-46
settings_new_askbot.py
+1
-1
simplewiki/mdx_wikipath.py
+40
-41
simplewiki/models.py
+2
-2
simplewiki/settings.py
+2
-2
No files found.
settings_new_askbot.py
View file @
4a664d88
...
@@ -210,7 +210,7 @@ LOGGING = {
...
@@ -210,7 +210,7 @@ LOGGING = {
'level'
:
'INFO'
'level'
:
'INFO'
},
},
'tracking'
:
{
'tracking'
:
{
'handlers'
:
handlers
,
'handlers'
:
[],
#
handlers,
'level'
:
'DEBUG'
,
'level'
:
'DEBUG'
,
'propagate'
:
False
,
'propagate'
:
False
,
},
},
...
...
simplewiki/mdx_
camelcase
.py
→
simplewiki/mdx_
wikipath
.py
View file @
4a664d88
...
@@ -75,68 +75,67 @@ except:
...
@@ -75,68 +75,67 @@ except:
from
markdown
import
etree
from
markdown
import
etree
class
CamelCase
Extension
(
markdown
.
Extension
):
class
WikiPath
Extension
(
markdown
.
Extension
):
def
__init__
(
self
,
configs
):
def
__init__
(
self
,
configs
):
# set extension defaults
# set extension defaults
self
.
config
=
{
self
.
config
=
{
'base_url'
:
[
'/'
,
'String to append to beginning or URL.'
],
'base_url'
:
[
'/'
,
'String to append to beginning or URL.'
],
'end_url'
:
[
'/'
,
'String to append to end of URL.'
],
'end_url'
:
[
'/'
,
'String to append to end of URL.'
],
'html_class'
:
[
'wiki
link
'
,
'CSS hook. Leave blank for none.'
]
'html_class'
:
[
'wiki
path
'
,
'CSS hook. Leave blank for none.'
]
}
}
# Override defaults with user settings
# Override defaults with user settings
for
key
,
value
in
configs
:
for
key
,
value
in
configs
:
# self.config[key][0] = value
# self.config[key][0] = value
self
.
setConfig
(
key
,
value
)
self
.
setConfig
(
key
,
value
)
def
add_inline
(
self
,
md
,
name
,
klass
,
re
):
pattern
=
klass
(
re
)
pattern
.
md
=
md
pattern
.
ext
=
self
md
.
inlinePatterns
.
add
(
name
,
pattern
,
"<reference"
)
def
extendMarkdown
(
self
,
md
,
md_globals
):
def
extendMarkdown
(
self
,
md
,
md_globals
):
self
.
add_inline
(
md
,
'camel'
,
CamelCaseLinks
,
self
.
md
=
md
r'''(?P<escape>\\|\b)(?P<camelcase>([A-Z]+[a-z-_]+){2,})(?:"")?\b'''
)
# append to end of inline patterns
class
CamelCaseLinks
(
markdown
.
inlinepatterns
.
Pattern
):
WIKI_RE
=
r'\[(?P<linkTitle>.+?)\]\(wiki:(?P<wikiTitle>[a-zA-Z\d/_-]*)\)'
wikiPathPattern
=
WikiPath
(
WIKI_RE
,
self
.
getConfigs
())
wikiPathPattern
.
md
=
md
md
.
inlinePatterns
.
add
(
'wikipath'
,
wikiPathPattern
,
"<reference"
)
class
WikiPath
(
markdown
.
inlinepatterns
.
Pattern
):
def
__init__
(
self
,
pattern
,
config
):
markdown
.
inlinepatterns
.
Pattern
.
__init__
(
self
,
pattern
)
self
.
config
=
config
def
handleMatch
(
self
,
m
)
:
def
handleMatch
(
self
,
m
)
:
if
m
.
group
(
'escape'
)
==
'
\\
'
:
article_title
=
m
.
group
(
'wikiTitle'
)
a
=
etree
.
Element
(
'a'
)
#doc.createTextNode(m.group('camelcase'))
if
article_title
.
startswith
(
"/"
):
else
:
article_title
=
article_title
[
1
:]
url
=
m
.
group
(
'camelcase'
)
+
"/"
#'%s%s%s'% (self.md.wiki_config['base_url'][0], \
url
=
self
.
config
[
'base_url'
]
+
article_title
#m.group('camelcase'), \
label
=
m
.
group
(
'linkTitle'
)
#self.md.wiki_config['end_url'][0])
a
=
etree
.
Element
(
'a'
)
label
=
m
.
group
(
'camelcase'
)
.
replace
(
'_'
,
' '
)
a
.
set
(
'href'
,
url
)
a
=
etree
.
Element
(
'a'
)
a
.
text
=
label
a
.
set
(
'href'
,
url
)
a
.
text
=
label
if
self
.
config
[
'html_class'
]:
a
.
set
(
'class'
,
'wikilink'
)
a
.
set
(
'class'
,
self
.
config
[
'html_class'
])
return
a
return
a
class
CamelCasePreprocessor
(
markdown
.
preprocessors
.
Preprocessor
)
:
def
run
(
self
,
lines
)
:
'''
Updates WikiLink Extension configs with Meta Data.
Passes "lines" through unchanged.
Run as a preprocessor because must run after the
def
_getMeta
(
self
):
MetaPreprocessor runs and only needs to run once.
""" Return meta data or config data. """
'''
base_url
=
self
.
config
[
'base_url'
]
end_url
=
self
.
config
[
'end_url'
]
html_class
=
self
.
config
[
'html_class'
]
if
hasattr
(
self
.
md
,
'Meta'
):
if
hasattr
(
self
.
md
,
'Meta'
):
if
self
.
md
.
Meta
.
has_key
(
'wiki_base_url'
):
if
self
.
md
.
Meta
.
has_key
(
'wiki_base_url'
):
self
.
md
.
wiki_config
[
'base_url'
][
0
]
=
self
.
md
.
Meta
[
'wiki_base_url'
][
0
]
base_url
=
self
.
md
.
Meta
[
'wiki_base_url'
][
0
]
if
self
.
md
.
Meta
.
has_key
(
'wiki_end_url'
):
if
self
.
md
.
Meta
.
has_key
(
'wiki_end_url'
):
self
.
md
.
wiki_config
[
'end_url'
][
0
]
=
self
.
md
.
Meta
[
'wiki_end_url'
][
0
]
end_url
=
self
.
md
.
Meta
[
'wiki_end_url'
][
0
]
if
self
.
md
.
Meta
.
has_key
(
'wiki_html_class'
):
if
self
.
md
.
Meta
.
has_key
(
'wiki_html_class'
):
self
.
md
.
wiki_config
[
'html_class'
][
0
]
=
self
.
md
.
Meta
[
'wiki_html_class'
][
0
]
html_class
=
self
.
md
.
Meta
[
'wiki_html_class'
][
0
]
return
base_url
,
end_url
,
html_class
return
lines
def
makeExtension
(
configs
=
None
)
:
def
makeExtension
(
configs
=
None
)
:
return
CamelCase
Extension
(
configs
=
configs
)
return
WikiPath
Extension
(
configs
=
configs
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
import
doctest
import
doctest
...
...
simplewiki/models.py
View file @
4a664d88
...
@@ -267,8 +267,8 @@ class Revision(models.Model):
...
@@ -267,8 +267,8 @@ class Revision(models.Model):
# Create pre-parsed contents - no need to parse on-the-fly
# Create pre-parsed contents - no need to parse on-the-fly
ext
=
WIKI_MARKDOWN_EXTENSIONS
ext
=
WIKI_MARKDOWN_EXTENSIONS
# TODO: Replace with a real wikilinks module
ext
+=
[
"wikipath(base_url=
%
s)"
%
reverse
(
'wiki_view'
,
args
=
(
'/'
,))]
# ext += ["wikilinks(base_url=%s/)" % reverse('wiki_view', args=('',))]
print
ext
self
.
contents_parsed
=
markdown
(
self
.
contents
,
self
.
contents_parsed
=
markdown
(
self
.
contents
,
extensions
=
ext
,
extensions
=
ext
,
safe_mode
=
'escape'
,)
safe_mode
=
'escape'
,)
...
...
simplewiki/settings.py
View file @
4a664d88
...
@@ -75,7 +75,7 @@ WIKI_CONTEXT_PREPROCESSORS = getattr(settings, 'SIMPLE_WIKI_CONTEXT_PREPROCESSOR
...
@@ -75,7 +75,7 @@ WIKI_CONTEXT_PREPROCESSORS = getattr(settings, 'SIMPLE_WIKI_CONTEXT_PREPROCESSOR
# List of extensions to be used by Markdown. Custom extensions (i.e., with file
# List of extensions to be used by Markdown. Custom extensions (i.e., with file
# names of mdx_*.py) can be dropped into the simplewiki (or project) directory
# names of mdx_*.py) can be dropped into the simplewiki (or project) directory
# and then added to this list to be utilized. Wiki
links is always enabled
.
# and then added to this list to be utilized. Wiki
is enabled automatically
.
#
#
# For more information, see
# For more information, see
# http://www.freewisdom.org/projects/python-markdown/Available_Extensions
# http://www.freewisdom.org/projects/python-markdown/Available_Extensions
...
@@ -90,7 +90,7 @@ WIKI_MARKDOWN_EXTENSIONS = getattr(settings, 'SIMPLE_WIKI_MARKDOWN_EXTENSIONS',
...
@@ -90,7 +90,7 @@ WIKI_MARKDOWN_EXTENSIONS = getattr(settings, 'SIMPLE_WIKI_MARKDOWN_EXTENSIONS',
'toc'
,
'toc'
,
'mathjax'
,
'mathjax'
,
'video'
,
# In-line embedding for YouTube, etc.
'video'
,
# In-line embedding for YouTube, etc.
'circuit'
'circuit'
,
])
])
...
...
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