mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-06-02 22:01:43 +02:00
feat(#148): add support for Math expression
This commit is contained in:
@@ -56,8 +56,11 @@
|
|||||||
<script src="/script/external/popper.min.js"></script>
|
<script src="/script/external/popper.min.js"></script>
|
||||||
<script src="/script/external/bootstrap.min.js"></script>
|
<script src="/script/external/bootstrap.min.js"></script>
|
||||||
|
|
||||||
|
<!-- PDF -->
|
||||||
<script src="/script/external/pdf.compat.js"></script>
|
<script src="/script/external/pdf.compat.js"></script>
|
||||||
<script src="/script/external/pdf.js"></script>
|
<script src="/script/external/pdf.js"></script>
|
||||||
|
|
||||||
|
<!-- Code -->
|
||||||
<script src="/script/external/ace/ace.js"></script>
|
<script src="/script/external/ace/ace.js"></script>
|
||||||
<script src="/script/external/ui-ace.min.js"></script>
|
<script src="/script/external/ui-ace.min.js"></script>
|
||||||
<script src="/script/langColors.js"></script>
|
<script src="/script/langColors.js"></script>
|
||||||
|
|||||||
@@ -259,7 +259,7 @@ angular
|
|||||||
},
|
},
|
||||||
link: function (scope, elem, attrs) {
|
link: function (scope, elem, attrs) {
|
||||||
function update() {
|
function update() {
|
||||||
elem.html(marked(scope.content, { baseUrl: $location.url() }));
|
elem.html(renderMD(scope.content, $location.url()));
|
||||||
}
|
}
|
||||||
scope.$watch(attrs.terms, update);
|
scope.$watch(attrs.terms, update);
|
||||||
scope.$watch("terms", update);
|
scope.$watch("terms", update);
|
||||||
@@ -1320,7 +1320,7 @@ angular
|
|||||||
}
|
}
|
||||||
|
|
||||||
$scope.anonymize_readme = content;
|
$scope.anonymize_readme = content;
|
||||||
const html = marked($scope.anonymize_readme);
|
const html = renderMD($scope.anonymize_readme, $location.url());
|
||||||
$scope.html_readme = $sce.trustAsHtml(html);
|
$scope.html_readme = $sce.trustAsHtml(html);
|
||||||
setTimeout(Prism.highlightAll, 150);
|
setTimeout(Prism.highlightAll, 150);
|
||||||
}
|
}
|
||||||
@@ -1642,9 +1642,8 @@ angular
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($scope.type == "md") {
|
if ($scope.type == "md") {
|
||||||
const md = contentAbs2Relative(res.data);
|
|
||||||
$scope.content = $sce.trustAsHtml(
|
$scope.content = $sce.trustAsHtml(
|
||||||
marked(md, { baseUrl: $location.url() })
|
renderMD(res.data, $location.url())
|
||||||
);
|
);
|
||||||
$scope.type = "html";
|
$scope.type = "html";
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+6
-1
File diff suppressed because one or more lines are too long
@@ -109,3 +109,44 @@ function parseGithubUrl(url) {
|
|||||||
throw "Invalid url";
|
throw "Invalid url";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function renderMD(md, baseUrl) {
|
||||||
|
md = contentAbs2Relative(md);
|
||||||
|
const renderer = new marked.Renderer();
|
||||||
|
// katex
|
||||||
|
function mathsExpression(expr) {
|
||||||
|
if (expr.match(/^\$\$[\s\S]*\$\$$/)) {
|
||||||
|
expr = expr.substr(2, expr.length - 4);
|
||||||
|
return katex.renderToString(expr, { displayMode: true });
|
||||||
|
} else if (expr.match(/^\$[\s\S]*\$$/)) {
|
||||||
|
expr = expr.substr(1, expr.length - 2);
|
||||||
|
return katex.renderToString(expr, { isplayMode: false });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const rendererCode = renderer.code;
|
||||||
|
renderer.code = function (code, lang, escaped) {
|
||||||
|
if (!lang) {
|
||||||
|
const math = mathsExpression(code);
|
||||||
|
if (math) {
|
||||||
|
return math;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// call default renderer
|
||||||
|
return rendererCode.call(this, code, lang, escaped);
|
||||||
|
|
||||||
|
// return rendererCode(code, lang, escaped);
|
||||||
|
};
|
||||||
|
|
||||||
|
const rendererCodespan = renderer.codespan;
|
||||||
|
renderer.codespan = function (text) {
|
||||||
|
const math = mathsExpression(text);
|
||||||
|
|
||||||
|
if (math) {
|
||||||
|
return math;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rendererCodespan(text);
|
||||||
|
};
|
||||||
|
return marked.parse(md, { baseUrl, renderer });
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user