Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
a8b7a4b7
Commit
a8b7a4b7
authored
Apr 13, 2017
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pulled in latest changes
parent
2f36c549
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
14 deletions
+59
-14
app/assets/javascripts/notebook/cells/markdown.vue
app/assets/javascripts/notebook/cells/markdown.vue
+59
-14
No files found.
app/assets/javascripts/notebook/cells/markdown.vue
View file @
a8b7a4b7
...
...
@@ -10,8 +10,61 @@
import
marked
from
'
marked
'
;
import
Prompt
from
'
./prompt.vue
'
;
const
renderer
=
new
marked
.
Renderer
();
/*
Regex to match KaTex blocks.
Supports the following:
\begin{equation}<math>\end{equation}
$$<math>$$
inline $<math>$
The matched text then goes through the KaTex renderer & then outputs the HTML
*/
const
katexRegexString
=
`(
^\\\\begin{[a-zA-Z]+}\\s
|
^\\$\\$
|
\\s\\$(?!\\$)
)
(.+?)
(
\\s\\\\end{[a-zA-Z]+}$
|
\\$\\$$
|
\\$
)
`
.
replace
(
/
\s
/g
,
''
).
trim
();
renderer
.
paragraph
=
(
t
)
=>
{
let
text
=
t
;
let
inline
=
false
;
if
(
typeof
katex
!==
'
undefined
'
)
{
const
katexString
=
text
.
replace
(
/
\\
/g
,
'
\\
'
);
const
matches
=
new
RegExp
(
katexRegexString
,
'
gi
'
).
exec
(
katexString
);
if
(
matches
&&
matches
.
length
>
0
)
{
if
(
matches
[
1
].
trim
()
===
'
$
'
&&
matches
[
3
].
trim
()
===
'
$
'
)
{
inline
=
true
;
text
=
`
${
katexString
.
replace
(
matches
[
0
],
''
)}
${
katex
.
renderToString
(
matches
[
2
])}
`
;
}
else
{
text
=
katex
.
renderToString
(
matches
[
2
]);
}
}
}
return
`<p class="
${
inline
?
'
inline-katex
'
:
''
}
">
${
text
}
</p>`
;
};
marked
.
setOptions
({
sanitize
:
true
,
renderer
,
});
export
default
{
...
...
@@ -26,20 +79,7 @@
},
computed
:
{
markdown
()
{
const
regex
=
new
RegExp
(
'
^
\\
$
\\
$(.*)
\\
$
\\
$$
'
,
'
g
'
);
const
source
=
this
.
cell
.
source
.
map
((
line
)
=>
{
const
matches
=
regex
.
exec
(
line
.
trim
());
// Only render use the Katex library if it is actually loaded
if
(
matches
&&
matches
.
length
>
0
&&
typeof
katex
!==
'
undefined
'
)
{
return
katex
.
renderToString
(
matches
[
1
]);
}
return
line
;
});
return
marked
(
source
.
join
(
''
));
return
marked
(
this
.
cell
.
source
.
join
(
''
));
},
},
};
...
...
@@ -50,4 +90,9 @@
display
:
block
;
text-align
:
center
;
}
.markdown
.inline-katex
.katex
{
display
:
inline
;
text-align
:
initial
;
}
</
style
>
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