Commit 1b26a2c4 authored by Matthieu Le Corre's avatar Matthieu Le Corre
Browse files

Fix UTF-8 loading & add mermaid + Latex


Signed-off-by: Matthieu Le Corre's avatarMatthieu Le Corre <matthieu.lecorre@univ-nantes.fr>
parent 22a123d6
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
{
"name": "files_readmemd",
"version": "1.1.2",
"version": "1.1.3",
"description": "show README.md github style",
"main": "./js/main.js",
"repository": "https://gitlab.univ-nantes.fr/uncloud/files_readmemd.git",
......@@ -17,6 +17,8 @@
"markdown-it": "^8.4.2",
"markdown-it-highlightjs": "^3.0.0",
"markdown-it-imsize": "^2.0.1",
"markdown-it-katex": "^2.0.3",
"markdown-it-mermaid-plus": "^0.2.5",
"markdown-it-replace-link": "^1.0.1",
"markdown-it-task-lists": "^2.1.1"
},
......@@ -24,6 +26,6 @@
"css-loader": "^2.1.1",
"style-loader": "^0.23.1",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.9"
"webpack-cli": "^3.3.10"
}
}
......@@ -74,7 +74,7 @@
//console.log( "Deleting " + zone + " -> " + fn ) ;
$.ajax({
url:OC.generateUrl("apps/files_readmemd/config/filenames/" + zone + "/" + fn ),
url:OC.generateUrl("apps/files_readmemd/config/filenames/" + zone + "/" + fn.replace("?","%3F") ),
type: 'DELETE',
success: function(data) {
$(self).parent().remove() ;
......@@ -91,7 +91,7 @@
var zone = "footer" ;
$.ajax({
url:OC.generateUrl("apps/files_readmemd/config/filenames/" + zone + "/" + fn ),
url:OC.generateUrl("apps/files_readmemd/config/filenames/" + zone + "/" + fn.replace("?","%3F") ),
type: 'PUT',
success: function(data) {
$("#readmeMD-filelist_footer").append(
......@@ -109,7 +109,7 @@
var zone = "header" ;
$.ajax({
url:OC.generateUrl("apps/files_readmemd/config/filenames/" + zone + "/" + fn ),
url:OC.generateUrl("apps/files_readmemd/config/filenames/" + zone + "/" + fn.replace("?","%3F") ),
type: 'PUT',
success: function(data) {
$("#readmeMD-filelist_header").append(
......
......@@ -340,8 +340,9 @@ OCA.ReadmeMD.App = {
}
);
}else{
var dir = OCA.Files.App.fileList._currentDirectory ;
var URL = OC.linkToRemoteBase('files'+ escape(dir) + '/' + escape(zone.filename))
var dir = OCA.Files.App.fileList._currentDirectory.replace("?","%3F") ;
var fname = zone.filename.replace("?","%3F") ;
var URL = OC.linkToRemoteBase('files'+ dir + '/' + fname ) ;
} ;
//load header file via remote call apps
$.get(URL)
......@@ -369,15 +370,17 @@ OCA.ReadmeMD.App = {
}
if (ext == "adoc" && this.show_asciidoc == "true") {
import('asciidoctor').then(Aconverter => {
zone.container.html(Aconverter.convert(zone.content)) ;
import(/* webpackChunkName: "asciidoctor" */ 'asciidoctor').then( Aconverter => {
console.log("ReadMeMD : asciidoctor loaded") ;
converter = Aconverter.default() ;
zone.container.html(converter.convert(zone.content)) ;
$("#filestable > tfoot > tr").height("auto") ;
});
} ;
if (ext == "md" || ext == "markdown") {
import('markdown-it').then(MDconverter => {
import(/* webpackChunkName: "markdown-it" */ 'markdown-it').then( MDconverter => {
var converter = MDconverter.default({
replaceLink: function(link,env){
if ( link.startsWith('mailto:') || link.startsWith('http://') || link.startsWith('https://') || link.startsWith(OC.generateUrl('core/preview')) ){
......@@ -396,22 +399,57 @@ OCA.ReadmeMD.App = {
})
.use(require('markdown-it-task-lists'), {enabled: true} )
.use(require('markdown-it-replace-link'))
.use(require('markdown-it-imsize'))
.use(require('markdown-it-imsize')) ;
/** this plugins is large, try to load only when needed*/
if (zone.content.indexOf('```') !== -1 ) {
import('markdown-it-highlightjs').then(module => {
converter.use(module) ;
}) ;
}
zone.container.html(converter.render(zone.content)) ;
$("#filestable > tfoot > tr").height("auto") ;
this.loadAdditionnalMDPlugins(zone,converter)
.then(function() {
zone.container.html(converter.render(zone.content)) ;
$("#filestable > tfoot > tr").height("auto") ;
})
});
};
},
/**
* load large MD plugins only when needed
*/
loadAdditionnalMDPlugins(zone,converter) {
promiseList = []
/** highlightjs*/
if (zone.content.indexOf('```') !== -1 ) {
promiseList.push(import(/* webpackChunkName: "m-it-highlightjs" */ 'markdown-it-highlightjs').then(module => {
converter.use(module.default) ;
console.log("ReadMeMD : highlightjs loaded") ;
})) ;
}
/** Mermaid */
if (zone.content.match(/(gantt|sequenceDiagram|graph (?:TB|BT|RL|LR|TD))/) !== null ) {
promiseList.push(import(/* webpackChunkName: "m-it-mermaid" */ 'markdown-it-mermaid-plus').then(module => {
converter.use(module.default) ;
console.log("ReadMeMD : Mermaid loaded") ;
}))
}
/** Latex*/
if (zone.content.indexOf('$') !== -1 ) {
promiseList.push(import(/* webpackChunkName: "katex" */ 'katex')) ;
promiseList.push(import(/* webpackChunkName: "m-it-katex" */ 'markdown-it-katex').then(module => {
converter.use(module.default) ;
console.log("ReadMeMD : Katex loaded") ;
})) ;
}
return Promise.all(promiseList) ;
}
};
OCA.ReadmeMD = OCA.ReadmeMD.App ;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment