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
a8ccebf5
Commit
a8ccebf5
authored
Nov 23, 2017
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
EE port of fix-mermaid-import
parent
fabe0eb2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
51 deletions
+42
-51
app/assets/javascripts/main.js
app/assets/javascripts/main.js
+0
-1
app/assets/javascripts/render_gfm.js
app/assets/javascripts/render_gfm.js
+7
-9
app/assets/javascripts/render_math.js
app/assets/javascripts/render_math.js
+35
-40
spec/javascripts/notes_spec.js
spec/javascripts/notes_spec.js
+0
-1
No files found.
app/assets/javascripts/main.js
View file @
a8ccebf5
...
...
@@ -72,7 +72,6 @@ import './project_import';
import
'
./projects_dropdown
'
;
import
'
./projects_list
'
;
import
'
./syntax_highlight
'
;
import
'
./render_math
'
;
import
'
./render_gfm
'
;
import
'
./right_sidebar
'
;
import
'
./search
'
;
...
...
app/assets/javascripts/render_gfm.js
View file @
a8ccebf5
/* eslint-disable func-names, space-before-function-paren, consistent-return, no-var, no-else-return, prefer-arrow-callback, max-len */
import
renderMath
from
'
./render_math
'
;
// Render Gitlab flavoured Markdown
//
// Delegates to syntax highlight and render math
//
(
function
()
{
$
.
fn
.
renderGFM
=
function
()
{
this
.
find
(
'
.js-syntax-highlight
'
).
syntaxHighlight
();
this
.
find
(
'
.js-render-math
'
).
renderMath
();
return
this
;
};
$
.
fn
.
renderGFM
=
function
renderGFM
()
{
this
.
find
(
'
.js-syntax-highlight
'
).
syntaxHighlight
();
renderMath
(
this
.
find
(
'
.js-render-math
'
));
return
this
;
};
$
(()
=>
$
(
'
body
'
).
renderGFM
());
}).
call
(
window
);
$
(()
=>
$
(
'
body
'
).
renderGFM
());
app/assets/javascripts/render_math.js
View file @
a8ccebf5
/* eslint-disable func-names, space-before-function-paren, consistent-return, no-var, no-else-return, prefer-arrow-callback, max-len, no-console */
/* global katex */
// Renders math using KaTeX in any element with the
...
...
@@ -8,49 +7,45 @@
//
// <code class="js-render-math"></div>
//
(
function
()
{
// Only load once
var
katexLoaded
=
false
;
let
katexLoaded
=
false
;
// Loop over all math elements and render math
var
renderWithKaTeX
=
function
(
elements
)
{
elements
.
each
(
function
()
{
var
mathNode
=
$
(
'
<span></span>
'
);
var
$this
=
$
(
this
);
// Loop over all math elements and render math
function
renderWithKaTeX
(
elements
)
{
elements
.
each
(
function
katexElementsLoop
()
{
const
mathNode
=
$
(
'
<span></span>
'
);
const
$this
=
$
(
this
);
var
display
=
$this
.
attr
(
'
data-math-style
'
)
===
'
display
'
;
try
{
katex
.
render
(
$this
.
text
(),
mathNode
.
get
(
0
),
{
displayMode
:
display
});
mathNode
.
insertAfter
(
$this
);
$this
.
remove
();
}
catch
(
err
)
{
// What can we do??
console
.
log
(
err
.
message
);
}
});
};
const
display
=
$this
.
attr
(
'
data-math-style
'
)
===
'
display
'
;
try
{
katex
.
render
(
$this
.
text
(),
mathNode
.
get
(
0
),
{
displayMode
:
display
});
mathNode
.
insertAfter
(
$this
);
$this
.
remove
();
}
catch
(
err
)
{
throw
err
;
}
});
}
$
.
fn
.
renderMath
=
function
()
{
var
$this
=
this
;
if
(
$this
.
length
===
0
)
return
;
export
default
function
renderMath
(
$els
)
{
if
(
!
$els
.
length
)
return
;
if
(
katexLoaded
)
renderWithKaTeX
(
$this
);
else
{
// Request CSS file so it is in the cache
$
.
get
(
gon
.
katex_css_url
,
function
()
{
var
css
=
$
(
'
<link>
'
,
{
rel
:
'
stylesheet
'
,
type
:
'
text/css
'
,
href
:
gon
.
katex_css_url
,
});
css
.
appendTo
(
'
head
'
);
if
(
katexLoaded
)
{
renderWithKaTeX
(
$els
);
}
else
{
$
.
get
(
gon
.
katex_css_url
,
()
=>
{
const
css
=
$
(
'
<link>
'
,
{
rel
:
'
stylesheet
'
,
type
:
'
text/css
'
,
href
:
gon
.
katex_css_url
,
});
css
.
appendTo
(
'
head
'
);
// Load KaTeX js
$
.
getScript
(
gon
.
katex_js_url
,
function
()
{
katexLoaded
=
true
;
renderWithKaTeX
(
$this
);
// Run KaTeX
});
// Load KaTeX js
$
.
getScript
(
gon
.
katex_js_url
,
()
=>
{
katexLoaded
=
true
;
renderWithKaTeX
(
$els
);
// Run KaTeX
});
}
}
;
}
).
call
(
window
);
}
);
}
}
spec/javascripts/notes_spec.js
View file @
a8ccebf5
...
...
@@ -5,7 +5,6 @@ import 'autosize';
import
'
~/gl_form
'
;
import
'
~/lib/utils/text_utility
'
;
import
'
~/render_gfm
'
;
import
'
~/render_math
'
;
import
'
~/notes
'
;
(
function
()
{
...
...
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