Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion appinfo/app.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php

$eventDispatcher = \OC::$server->getEventDispatcher();

// only load text editor if the user is logged in
if (\OCP\User::isLoggedIn()) {
$eventDispatcher = \OC::$server->getEventDispatcher();
$eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', function() {
OCP\Util::addStyle('files_texteditor', 'merged');
OCP\Util::addScript('files_texteditor', 'merged');
Expand All @@ -14,3 +15,8 @@
});
}

$eventDispatcher->addListener('OCA\Files_Sharing::loadAdditionalScripts', function() {
OC_Util::addVendorScript('core', 'marked/marked.min');
OCP\Util::addScript('files_texteditor', 'public-share');
OCP\Util::addStyle('files_texteditor', 'public-share');
});
77 changes: 77 additions & 0 deletions css/public-share.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
.preview {
max-width: 700px;
padding: 0px 20px !important;
box-sizing: border-box;
font-size: 18px;
line-height: 1.6em;
min-height: 440px;
color: #333;
text-align: left;
margin-bottom: 170px !important;
}

.preview h1,
.preview h2,
.preview h3 {
margin-top: 1em;
}

.preview h1 {
line-height: 1.1em;
margin-bottom: 1em;
text-align: center;
font-size: 3em;
}

.preview h2 {
line-height: 1.1em;
margin-bottom: .5em;
font-size: 2em;
}

.preview h3 {
line-height: 1.1em;
margin-bottom: .6em;
font-size: 1.4em;
}

.preview p,
.preview ul,
.preview ol,
.preview pre {
margin-bottom: 17.6px;
line-height: 1.45em;
}
.preview ul,
.preview ol {
padding-left: 25px;
}

.preview ul {
list-style-type: square;
}

.preview ul ul {
list-style-type: circle;
}

.preview a {
color: #448ac9;
text-decoration: none;
}
.preview a:hover,
.preview a:focus,
.preview a:active {
text-decoration: underline;
}

.preview em {
opacity: 1;
font-style: italic;
}

/* hide image preview during loading or if it renders fine */
.icon-loading .text-preview,
.preview .text-preview {
display: none !important;
}
68 changes: 68 additions & 0 deletions js/public-share.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// FIXME: Hack for single public file view since it is not attached to the fileslist
$(document).ready(function(){
if ($('#isPublic').val() &&
$('#mimetype').val() === 'text/markdown' &&
$('#filesize').val() < 524288) {

var sharingToken = $('#sharingToken').val();
var downloadUrl = OC.generateUrl('/s/{token}/download', {token: sharingToken});
var previewElement = $('#imgframe');
var renderer = new marked.Renderer();
renderer.link = function(href, title, text) {
try {
var prot = decodeURIComponent(unescape(href))
.replace(/[^\w:]/g, '')
.toLowerCase();
} catch (e) {
return '';
}

if (prot.indexOf('http:') !== 0 && prot.indexOf('https:') !== 0) {
return '';
}

var out = '<a href="' + href + '" rel="noreferrer noopener"';
if (title) {
out += ' title="' + title + '"';
}
out += '>' + text + '</a>';
return out;
};
renderer.image = function(href, title, text) {
if (text) {
return text;
}
return title;
};
renderer.blockquote = function(quote) {
return quote;
};

previewElement
.addClass('icon-loading')
.children().detach();

$.get(downloadUrl).success(function(content) {
previewElement
.removeClass('icon-loading')
.addClass('preview')
.html(DOMPurify.sanitize(
marked(content, {
renderer: renderer,
gfm: false,
breaks: false,
pedantic: false,
sanitize: true,
smartLists: true,
smartypants: false
}),
{
SAFE_FOR_JQUERY: true
}
));
}).fail(function(result){
previewElement
.removeClass('icon-loading');
});
}
});