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
bd4a386d
Commit
bd4a386d
authored
Aug 06, 2012
by
Rocky Duan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
highlighting while skipping code and mathjax (ugly and slow solution)
parent
39ae9343
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
78 additions
and
10 deletions
+78
-10
lms/static/coffee/src/customwmd.coffee
+6
-4
lms/static/coffee/src/discussion/content.coffee
+7
-5
lms/static/coffee/src/discussion/utils.coffee
+65
-1
No files found.
lms/static/coffee/src/customwmd.coffee
View file @
bd4a386d
...
@@ -112,14 +112,16 @@ $ ->
...
@@ -112,14 +112,16 @@ $ ->
if
Markdown
?
if
Markdown
?
Markdown
.
getMathCompatibleConverter
=
->
Markdown
.
getMathCompatibleConverter
=
(
postProcessor
)
->
postProcessor
||=
((
text
)
->
text
)
converter
=
Markdown
.
getSanitizingConverter
()
converter
=
Markdown
.
getSanitizingConverter
()
processor
=
new
MathJaxProcessor
()
processor
=
new
MathJaxProcessor
()
converter
.
hooks
.
chain
"preConversion"
,
MathJaxProcessor
.
removeMathWrapper
(
processor
)
converter
.
hooks
.
chain
"preConversion"
,
MathJaxProcessor
.
removeMathWrapper
(
processor
)
converter
.
hooks
.
chain
"postConversion"
,
MathJaxProcessor
.
replaceMathWrapper
(
processor
)
converter
.
hooks
.
chain
"postConversion"
,
(
text
)
->
postProcessor
(
MathJaxProcessor
.
replaceMathWrapper
(
processor
)(
text
))
converter
converter
Markdown
.
makeWmdEditor
=
(
elem
,
appended_id
,
imageUploadUrl
)
->
Markdown
.
makeWmdEditor
=
(
elem
,
appended_id
,
imageUploadUrl
,
postProcessor
)
->
$elem
=
$
(
elem
)
$elem
=
$
(
elem
)
if
not
$elem
.
length
if
not
$elem
.
length
...
@@ -136,7 +138,7 @@ $ ->
...
@@ -136,7 +138,7 @@ $ ->
.
append
(
$
(
"<div>"
).
attr
(
"id"
,
"wmd-preview
#{
_append
}
"
).
addClass
(
"wmd-panel wmd-preview"
))
.
append
(
$
(
"<div>"
).
attr
(
"id"
,
"wmd-preview
#{
_append
}
"
).
addClass
(
"wmd-panel wmd-preview"
))
$elem
.
append
(
$wmdPanel
)
$elem
.
append
(
$wmdPanel
)
converter
=
Markdown
.
getMathCompatibleConverter
()
converter
=
Markdown
.
getMathCompatibleConverter
(
postProcessor
)
ajaxFileUpload
=
(
imageUploadUrl
,
input
,
startUploadHandler
)
->
ajaxFileUpload
=
(
imageUploadUrl
,
input
,
startUploadHandler
)
->
$
(
"#loading"
).
ajaxStart
(
->
$
(
this
).
show
()).
ajaxComplete
(
->
$
(
this
).
hide
())
$
(
"#loading"
).
ajaxStart
(
->
$
(
this
).
show
()).
ajaxComplete
(
->
$
(
this
).
hide
())
...
...
lms/static/coffee/src/discussion/content.coffee
View file @
bd4a386d
...
@@ -283,8 +283,13 @@ initializeFollowThread = (thread) ->
...
@@ -283,8 +283,13 @@ initializeFollowThread = (thread) ->
text
.
replace
(
/\<\;highlight\>\;/g
,
"<span class='search-highlight'>"
)
text
.
replace
(
/\<\;highlight\>\;/g
,
"<span class='search-highlight'>"
)
.
replace
(
/\<\;\/highlight\>\;/g
,
"</span>"
)
.
replace
(
/\<\;\/highlight\>\;/g
,
"</span>"
)
stripHighlight
=
(
text
,
type
)
->
text
.
replace
(
/\&(amp\;)?lt\;highlight\&(amp\;)?gt\;/g
,
""
)
.
replace
(
/\&(amp\;)?lt\;\/highlight\&(amp\;)?gt\;/g
,
""
)
stripLatexHighlight
=
(
text
)
->
stripLatexHighlight
=
(
text
)
->
tex
t
Discussion
.
processEachMathAndCode
text
,
stripHighligh
t
markdownWithHighlight
=
(
text
)
->
markdownWithHighlight
=
(
text
)
->
converter
=
Markdown
.
getMathCompatibleConverter
()
converter
=
Markdown
.
getMathCompatibleConverter
()
...
@@ -303,10 +308,7 @@ initializeFollowThread = (thread) ->
...
@@ -303,10 +308,7 @@ initializeFollowThread = (thread) ->
$contentBody
=
$local
(
".content-body"
)
$contentBody
=
$local
(
".content-body"
)
console
.
log
"raw html:"
$contentBody
.
html
Discussion
.
postMathJaxProcessor
markdownWithHighlight
$contentBody
.
html
()
console
.
log
$contentBody
.
html
()
$contentBody
.
html
markdownWithHighlight
$contentBody
.
html
()
MathJax
.
Hub
.
Queue
[
"Typeset"
,
MathJax
.
Hub
,
$contentBody
.
attr
(
"id"
)]
MathJax
.
Hub
.
Queue
[
"Typeset"
,
MathJax
.
Hub
,
$contentBody
.
attr
(
"id"
)]
id
=
$content
.
attr
(
"_id"
)
id
=
$content
.
attr
(
"_id"
)
...
...
lms/static/coffee/src/discussion/utils.coffee
View file @
bd4a386d
...
@@ -95,12 +95,25 @@ wmdEditors = {}
...
@@ -95,12 +95,25 @@ wmdEditors = {}
else
else
success
(
response
,
textStatus
,
xhr
)
success
(
response
,
textStatus
,
xhr
)
postMathJaxProcessor
:
(
text
)
->
RE_INLINEMATH
=
/^\$([^\$]*)\$/g
RE_DISPLAYMATH
=
/^\$\$([^\$]*)\$\$/g
Discussion
.
processEachMathAndCode
text
,
(
s
,
type
)
->
if
type
==
'display'
s
.
replace
RE_DISPLAYMATH
,
(
$0
,
$1
)
->
"
\\
["
+
$1
+
"
\\
]"
else
if
type
==
'inline'
s
.
replace
RE_INLINEMATH
,
(
$0
,
$1
)
->
"
\\
("
+
$1
+
"
\\
)"
else
s
makeWmdEditor
:
(
$content
,
$local
,
cls_identifier
)
->
makeWmdEditor
:
(
$content
,
$local
,
cls_identifier
)
->
elem
=
$local
(
".
#{
cls_identifier
}
"
)
elem
=
$local
(
".
#{
cls_identifier
}
"
)
id
=
$content
.
attr
(
"_id"
)
id
=
$content
.
attr
(
"_id"
)
appended_id
=
"-
#{
cls_identifier
}
-
#{
id
}
"
appended_id
=
"-
#{
cls_identifier
}
-
#{
id
}
"
imageUploadUrl
=
Discussion
.
urlFor
(
'upload'
)
imageUploadUrl
=
Discussion
.
urlFor
(
'upload'
)
editor
=
Markdown
.
makeWmdEditor
elem
,
appended_id
,
imageUploadUrl
editor
=
Markdown
.
makeWmdEditor
elem
,
appended_id
,
imageUploadUrl
,
Discussion
.
postMathJaxProcessor
wmdEditors
[
"
#{
cls_identifier
}
-
#{
id
}
"
]
=
editor
wmdEditors
[
"
#{
cls_identifier
}
-
#{
id
}
"
]
=
editor
editor
editor
...
@@ -164,3 +177,54 @@ wmdEditors = {}
...
@@ -164,3 +177,54 @@ wmdEditors = {}
unfollowLink
()
unfollowLink
()
else
else
followLink
()
followLink
()
processEachMathAndCode
:
(
text
,
processor
)
->
codeArchive
=
[]
RE_DISPLAYMATH
=
/^([^\$]*?)\$\$([^\$].+?)\$\$(.*)$/m
RE_INLINEMATH
=
/^([^\$]*?)\$([^\$]+?)\$(.*)$/m
ESCAPED_DOLLAR
=
'@@ESCAPED_D@@'
ESCAPED_BACKSLASH
=
'@@ESCAPED_B@@'
processedText
=
""
$div
=
$
(
"<div>"
).
html
(
text
)
$div
.
find
(
"code"
).
each
(
index
,
code
)
->
codeArchive
.
push
$
(
code
).
html
()
$
(
code
).
html
(
codeArchive
.
length
-
1
)
text
=
$div
.
html
()
text
=
text
.
replace
/\\\$/g
,
ESCAPED_DOLLAR
while
true
if
RE_INLINEMATH
.
test
(
text
)
text
=
text
.
replace
RE_INLINEMATH
,
(
$0
,
$1
,
$2
,
$3
)
->
processedText
+=
$1
+
processor
(
"$"
+
$2
+
"$"
,
'inline'
)
$3
else
if
RE_DISPLAYMATH
.
test
(
text
)
text
=
text
.
replace
RE_DISPLAYMATH
,
(
$0
,
$1
,
$2
,
$3
)
->
processedText
+=
$1
+
processor
(
"$$"
+
$2
+
"$$"
,
'display'
)
$3
else
processedText
+=
text
break
text
=
processedText
text
=
text
.
replace
(
new
RegExp
(
ESCAPED_DOLLAR
),
'
\\
$'
)
text
=
text
.
replace
/\\\\\\\\/g
,
ESCAPED_BACKSLASH
text
=
text
.
replace
/\\begin\{([a-z]*\*?)\}([\s\S]*?)\\end\{\1\}/img
,
(
$0
,
$1
,
$2
)
->
processor
(
"
\\
begin{
#{
$1
}
}"
+
$2
+
"
\\
end{
#{
$1
}
}"
)
text
=
text
.
replace
(
new
RegExp
(
ESCAPED_BACKSLASH
),
'
\\\\\\\\
'
)
$div
=
$
(
"<div>"
).
html
(
text
)
cnt
=
0
$div
.
find
(
"code"
).
each
(
index
,
code
)
->
$
(
code
).
html
(
processor
(
codeArchive
[
cnt
],
'code'
))
cnt
+=
1
$div
.
html
()
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