From 6ba9bd5757b03237b7cd5685a01d5251074f5bf5 Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 26 May 2020 12:11:51 +0200 Subject: [PATCH 1/3] Export to .doc --- www/common/sframe-app-framework.js | 41 +++++++++++++++++++++--------- www/pad/export.js | 40 ++++++++++++++++++++++------- www/pad/inner.js | 4 +-- 3 files changed, 62 insertions(+), 23 deletions(-) diff --git a/www/common/sframe-app-framework.js b/www/common/sframe-app-framework.js index e690bfb08..6e10b0a77 100644 --- a/www/common/sframe-app-framework.js +++ b/www/common/sframe-app-framework.js @@ -433,21 +433,37 @@ define([ var ext = (typeof(extension) === 'function') ? extension() : extension; var suggestion = title.suggestTitle('cryptpad-document'); ext = ext || '.txt'; - var types = [{ - tag: 'a', - attributes: { - 'data-value': ext, - 'href': '#' - }, - content: ext - }, { + var types = []; + if (Array.isArray(ext) && ext.length) { + ext.forEach(function (_ext) { + types.push({ + tag: 'a', + attributes: { + 'data-value': _ext, + 'href': '#' + }, + content: _ext + }); + }); + ext = ext[0]; + } else { + types.push({ + tag: 'a', + attributes: { + 'data-value': ext, + 'href': '#' + }, + content: ext + }); + } + types.push({ tag: 'a', attributes: { 'data-value': '', 'href': '#' }, content: ' ' - }]; + }); var dropdownConfig = { text: ext, // Button initial text caretDown: true, @@ -461,14 +477,15 @@ define([ Util.fixFileName(suggestion), function (filename) { if (!(typeof(filename) === 'string' && filename)) { return; } - filename = filename + $select.getValue(); + var ext = $select.getValue(); + filename = filename + ext; if (async) { fe(function (blob) { SaveAs(blob, filename); - }); + }, ext); return; } - var blob = fe(); + var blob = fe(null, ext); SaveAs(blob, filename); }, { typeInput: $select[0] diff --git a/www/pad/export.js b/www/pad/export.js index d1deef146..f1e3497c9 100644 --- a/www/pad/export.js +++ b/www/pad/export.js @@ -5,15 +5,17 @@ define([ '/bower_components/nthen/index.js', ], function ($, Util, Hyperjson, nThen) { var module = { - ext: '.html' + ext: '.html', // default + exts: ['.html', '.doc'] }; var exportMediaTags = function (inner, cb) { var $clone = $(inner).clone(); nThen(function (waitFor) { $(inner).find('media-tag').each(function (i, el) { - if (!$(el).data('blob') || !el.blob) { return; } - Util.blobToImage(el.blob || $(el).data('blob'), waitFor(function (imgSrc) { + var blob = Util.find(el, ['_mediaObject','_blob', 'content']); + if (!blob) { return; } + Util.blobToImage(blob, waitFor(function (imgSrc) { $clone.find('media-tag[src="' + $(el).attr('src') + '"] img') .attr('src', imgSrc); $clone.find('media-tag').parent() @@ -25,18 +27,31 @@ define([ }); }; + var cleanHtml = function (inner) { + return inner.innerHTML.replace(/]*class="cke_anchor"[^>]*data-cke-realelement="([^"]*)"[^>]*>/g, + function(match,realElt){ + //console.log("returning realElt \"" + unescape(realElt)+ "\"."); + return decodeURIComponent(realElt); + }); + }; module.getHTML = function (inner) { return ('\n' + '\n' + ' \n ' + - inner.innerHTML.replace(/]*class="cke_anchor"[^>]*data-cke-realelement="([^"]*)"[^>]*>/g, - function(match,realElt){ - //console.log("returning realElt \"" + unescape(realElt)+ "\"."); - return decodeURIComponent(realElt); }) + + cleanHtml(inner) + ' \n' ); }; - module.main = function (userDoc, cb) { + var exportDoc = function (inner) { + var preHtml = "Export HTML To Doc"; + var postHtml = ""; + var _html = preHtml+cleanHtml(inner)+postHtml; + return _html; + }; + + module.main = function (userDoc, cb, ext) { + if (!ext || module.exts.indexOf(ext) === -1) { ext = module.ext; } + var inner; if (userDoc && userDoc.tagName) { inner = userDoc; @@ -56,7 +71,14 @@ define([ } } exportMediaTags(inner, function (toExport) { - cb(new Blob([ module.getHTML(toExport) ], { type: "text/html;charset=utf-8" })); + if (ext === ".doc") { + var blob = new Blob(['\ufeff', exportDoc(toExport)], { + type: 'application/msword' + }); + return void cb(blob); + } + var html = module.getHTML(toExport); + cb(new Blob([ html ], { type: "text/html;charset=utf-8" })); }); }; diff --git a/www/pad/inner.js b/www/pad/inner.js index b7f309c35..05cf2c788 100644 --- a/www/pad/inner.js +++ b/www/pad/inner.js @@ -793,8 +793,8 @@ define([ }); }, true); - framework.setFileExporter(Exporter.ext, function(cb) { - Exporter.main(inner, cb); + framework.setFileExporter(Exporter.exts, function(cb, ext) { + Exporter.main(inner, cb, ext); }, true); framework.setNormalizer(function(hjson) { From ee9f725b3ccc73442cff5036438a94331062ecee Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 27 May 2020 16:36:02 +0200 Subject: [PATCH 2/3] Fix help box overflowing --- customize.dist/src/less2/include/help.less | 2 ++ 1 file changed, 2 insertions(+) diff --git a/customize.dist/src/less2/include/help.less b/customize.dist/src/less2/include/help.less index b8a6123df..3bc9ae1e0 100644 --- a/customize.dist/src/less2/include/help.less +++ b/customize.dist/src/less2/include/help.less @@ -8,6 +8,8 @@ position: relative; background-color: @colortheme_help-bg; + max-height: 50%; + overflow-y: auto; &.cp-help-hidden { display: none; } From 043b2d24ea411e0942b4facbeff35b8287949a1b Mon Sep 17 00:00:00 2001 From: ansuz Date: Wed, 27 May 2020 12:26:24 -0400 Subject: [PATCH 3/3] remove invalid XXX note --- www/common/sframe-common-codemirror.js | 1 - 1 file changed, 1 deletion(-) diff --git a/www/common/sframe-common-codemirror.js b/www/common/sframe-common-codemirror.js index 13655a333..fe251e696 100644 --- a/www/common/sframe-common-codemirror.js +++ b/www/common/sframe-common-codemirror.js @@ -369,7 +369,6 @@ define([ }; var $block = exp.$theme = UIElements.createDropdown(dropdownConfig); $block.find('button').attr('title', Messages.themeButtonTitle).click(function () { - // XXX copy-pasted code from configureLanguage. We can refactor this. var state = $block.find('.cp-dropdown-content').is(':visible'); var $c = $block.closest('.cp-toolbar-drawer-content'); $c.removeClass('cp-dropdown-visible');