Commit 8248023a authored by Matthieu Le Corre's avatar Matthieu Le Corre
Browse files

Initial commit

parents
<?php
$eventDispatcher = \OC::$server->getEventDispatcher();
$eventDispatcher->addListener('OCA\Files::loadAdditionalScripts',
function() {
OCP\Util::addscript('files_readmemd', 'script');
OCP\Util::addStyle('files_readmemd','style') ;
});
<?xml version="1.0"?>
<info>
<id>files_readmemd</id>
<name>README.md</name>
<summary>Show README.md gitlab style</summary>
<description><![CDATA[Show README.md gitlab style ]]></description>
<version>0.0.1</version>
<licence>agpl</licence>
<author mail="matthieu.lecorre@univ-nantes.fr" homepage="http://www.univ-nantes.fr">Matthieu Le Corre</author>
<namespace>ReadMeMd</namespace>
<bugs>https://gitlab.univ-nantes.fr</bugs>
<dependencies>
<nextcloud min-version="12" max-version="14"/>
</dependencies>
<types>
<filesystem/>
</types>
</info>
.readmemd {
padding: 2em ;
border-top: 1px solid silver ;
margin-top: 1em ;
background-color: #c6d6390f ;
}
.readmemd::before {
content:"README.md" ;
color: silver ;
}
.headermd {
padding: 2em ;
border-bottom: 1px solid silver ;
margin-bottom: 1em ;
background-color: #c6d6390f ;
}
/**
* @namespace OCA.IndexMD
*/
OCA.ReadmeMD = {};
/**
* @namespace OCA.IndexMD.App
*/
OCA.ReadmeMD.App = {
/**
* Holds the MD container and content
*/
container: null,
content: null,
/**
* Setup on page load
*/
initialize: function (container) {
// Don't load if not in the files app
if (!$('#content.app-files').length) {
return;
}
//Don't load if the markdown apps is not present
if (! OCA.Files_Texteditor.previewPlugins["text/markdown"]) {
console.error('MarkDown Apps not available !') ;
return;
}
//initialise MD renderer
OCA.Files_Texteditor.previewPlugins["text/markdown"].init() ;
// trigger on filetable
$("#filestable").on('updated',this.checkMD);
// container creation
this.container = container;
this.createContainer() ;
},
/**
* check MD handler
*/
checkMD: function() {
OCA.ReadmeMD.container.addClass("hidden") ;
for (var filenum in OCA.Files.App.fileList.files) {
if ( OCA.Files.App.fileList.files[filenum].name == "README.md") {
OCA.ReadmeMD.container.removeClass("hidden") ;
OCA.ReadmeMD.fillContainer() ;
} ;
} ;
},
/**
* show contenair
*/
createContainer: function() {
$('#filestable').after(this.container) ;
},
/**
* fill contant
*/
fillContainer: function() {
dir=OCA.Files.App.fileList._currentDirectory ;
filename ="README.md" ;
$.get(
OC.generateUrl('/apps/files_texteditor/ajax/loadfile'),
{
filename: filename,
dir: dir
}
).done(function(data) {
OCA.ReadmeMD.content=data.filecontents ;
OCA.ReadmeMD.renderMD() ;
}) ;
},
/**
* Render Markdown
**/
renderMD: function() {
OCA.ReadmeMD.container
.addClass('icon-loading')
.children().remove();
OCA.Files_Texteditor.previewPlugins["text/markdown"].renderer.renderText(
OCA.ReadmeMD.content,
OCA.ReadmeMD.container
).done(function(data) {
$("#filestable > tfoot > tr").height("auto") ;
OCA.ReadmeMD.container.removeClass('icon-loading') ;
});
}
};
OCA.ReadmeMD = OCA.ReadmeMD.App ;
$(document).ready(function () {
OCA.ReadmeMD.initialize($('<div id="preview" class="hidden text-markdown readmemd"></div>') );
});
Supports Markdown
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