summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn McLear <john@mclear.co.uk>2014-12-22 02:32:50 +0000
committerJohn McLear <john@mclear.co.uk>2014-12-22 02:32:50 +0000
commit70ba525430e42655699b35be1802a6e51d569f91 (patch)
tree7bc4170324938eb861f2212fbe5abeda4f862a38
parentee3f3b80603f96f76f6d830464d59ef1e36dcd06 (diff)
parentfdc930de3dffc72dc10791f83f87a8b5a55d07ec (diff)
downloadetherpad-lite-70ba525430e42655699b35be1802a6e51d569f91.zip
Merge pull request #2368 from ether/hook_for_exportHTMLStyles
Hook for export html styles
-rw-r--r--doc/api/hooks_client-side.md16
-rw-r--r--doc/api/hooks_server-side.md52
-rw-r--r--src/node/utils/ExportHtml.js68
-rw-r--r--src/static/css/pad.css11
-rw-r--r--src/static/js/broadcast.js2
-rw-r--r--src/static/js/linestylefilter.js8
6 files changed, 130 insertions, 27 deletions
diff --git a/doc/api/hooks_client-side.md b/doc/api/hooks_client-side.md
index b8a58b31..ca429a07 100644
--- a/doc/api/hooks_client-side.md
+++ b/doc/api/hooks_client-side.md
@@ -80,6 +80,22 @@ This hook is called during the attribute processing procedure, and should be use
The return value for this function should be a list of classes, which will then be parsed into a valid class string.
+## aceAttribClasses
+Called from: src/static/js/linestylefilter.js
+
+Things in context:
+1. Attributes - Object of Attributes
+
+This hook is called when attributes are investigated on a line. It is useful if you want to add another attribute type or property type to a pad.
+
+Example:
+```
+exports.aceAttribClasses = function(hook_name, attr, cb){
+ attr.sub = 'tag:sub';
+ cb(attr);
+}
+```
+
## aceGetFilterStack
Called from: src/static/js/linestylefilter.js
diff --git a/doc/api/hooks_server-side.md b/doc/api/hooks_server-side.md
index 435872ea..251cbf11 100644
--- a/doc/api/hooks_server-side.md
+++ b/doc/api/hooks_server-side.md
@@ -247,6 +247,40 @@ Things in context:
This hook will allow a plug-in developer to re-write each line when exporting to HTML.
+## stylesForExport
+Called from: src/node/utils/ExportHtml.js
+
+Things in context:
+
+1. padId - The Pad Id
+
+This hook will allow a plug-in developer to append Styles to the Exported HTML.
+
+Example:
+
+```
+exports.stylesForExport = function(hook, padId, cb){
+ cb("body{font-size:13.37em !important}");
+}
+```
+
+## aceAttribClasses
+Called from: src/static/js/linestylefilter.js
+
+Things in context:
+1. Attributes - Object of Attributes
+
+This hook is called when attributes are investigated on a line. It is useful if you want to add another attribute type or property type to a pad.
+
+Example:
+
+```
+exports.aceAttribClasses = function(hook_name, attr, cb){
+ attr.sub = 'tag:sub';
+ cb(attr);
+}
+```
+
## exportFileName
Called from src/node/handler/ExportHandler.js
@@ -264,6 +298,24 @@ exports.exportFileName = function(hook, padId, callback){
}
```
+## exportHtmlAdditionalTags
+Called from src/node/utils/ExportHtml.js
+
+Things in context:
+
+1. Pad object
+
+This hook will allow a plug-in developer to include more properties and attributes to support during HTML Export. An Array should be returned.
+
+Example:
+```
+// Add the props to be supported in export
+exports.exportHtmlAdditionalTags = function(hook, pad, cb){
+ var padId = pad.id;
+ cb(["massive","jugs"]);
+};
+
+
## userLeave
Called from src/node/handler/PadMessageHandler.js
diff --git a/src/node/utils/ExportHtml.js b/src/node/utils/ExportHtml.js
index 01920da7..693cf9cf 100644
--- a/src/node/utils/ExportHtml.js
+++ b/src/node/utils/ExportHtml.js
@@ -78,6 +78,14 @@ function getHTMLFromAtext(pad, atext, authorColors)
var tags = ['h1', 'h2', 'strong', 'em', 'u', 's'];
var props = ['heading1', 'heading2', 'bold', 'italic', 'underline', 'strikethrough'];
+
+ hooks.aCallAll("exportHtmlAdditionalTags", pad, function(err, newProps){
+ newProps.forEach(function (propName, i){
+ tags.push(propName);
+ props.push(propName);
+ });
+ });
+
// holds a map of used styling attributes (*1, *2, etc) in the apool
// and maps them to an index in props
// *3:2 -> the attribute *3 means strong
@@ -425,32 +433,40 @@ exports.getPadHTMLDocument = function (padId, revNum, noDocType, callback)
{
if(ERR(err, callback)) return;
- var head =
- (noDocType ? '' : '<!doctype html>\n') +
- '<html lang="en">\n' + (noDocType ? '' : '<head>\n' +
- '<title>' + Security.escapeHTML(padId) + '</title>\n' +
- '<meta charset="utf-8">\n' +
- '<style> * { font-family: arial, sans-serif;\n' +
- 'font-size: 13px;\n' +
- 'line-height: 17px; }' +
- 'ul.indent { list-style-type: none; }' +
- 'ol { list-style-type: decimal; }' +
- 'ol ol { list-style-type: lower-latin; }' +
- 'ol ol ol { list-style-type: lower-roman; }' +
- 'ol ol ol ol { list-style-type: decimal; }' +
- 'ol ol ol ol ol { list-style-type: lower-latin; }' +
- 'ol ol ol ol ol ol{ list-style-type: lower-roman; }' +
- 'ol ol ol ol ol ol ol { list-style-type: decimal; }' +
- 'ol ol ol ol ol ol ol ol{ list-style-type: lower-latin; }' +
- '</style>\n' + '</head>\n') +
- '<body>';
-
- var foot = '</body>\n</html>\n';
-
- getPadHTML(pad, revNum, function (err, html)
- {
- if(ERR(err, callback)) return;
- callback(null, head + html + foot);
+ var stylesForExportCSS = "";
+ // Include some Styles into the Head for Export
+ hooks.aCallAll("stylesForExport", padId, function(err, stylesForExport){
+ stylesForExport.forEach(function(css){
+ stylesForExportCSS += css;
+ });
+ // Core inclusion of head etc.
+ var head =
+ (noDocType ? '' : '<!doctype html>\n') +
+ '<html lang="en">\n' + (noDocType ? '' : '<head>\n' +
+ '<title>' + Security.escapeHTML(padId) + '</title>\n' +
+ '<meta charset="utf-8">\n' +
+ '<style> * { font-family: arial, sans-serif;\n' +
+ 'font-size: 13px;\n' +
+ 'line-height: 17px; }' +
+ 'ul.indent { list-style-type: none; }' +
+ 'ol { list-style-type: decimal; }' +
+ 'ol ol { list-style-type: lower-latin; }' +
+ 'ol ol ol { list-style-type: lower-roman; }' +
+ 'ol ol ol ol { list-style-type: decimal; }' +
+ 'ol ol ol ol ol { list-style-type: lower-latin; }' +
+ 'ol ol ol ol ol ol{ list-style-type: lower-roman; }' +
+ 'ol ol ol ol ol ol ol { list-style-type: decimal; }' +
+ 'ol ol ol ol ol ol ol ol{ list-style-type: lower-latin; }' +
+ stylesForExportCSS +
+ '</style>\n' + '</head>\n') +
+ '<body>';
+ var foot = '</body>\n</html>\n';
+
+ getPadHTML(pad, revNum, function (err, html)
+ {
+ if(ERR(err, callback)) return;
+ callback(null, head + html + foot);
+ });
});
});
};
diff --git a/src/static/css/pad.css b/src/static/css/pad.css
index fb2cb82b..7ecf8e22 100644
--- a/src/static/css/pad.css
+++ b/src/static/css/pad.css
@@ -105,6 +105,17 @@ a img {
-moz-box-shadow: 0 0 8px rgba(0,0,0,.1) inset;
box-shadow: 0 0 8px rgba(0,0,0,.1) inset;
}
+.toolbar ul li .activeButton {
+ background: #eee;
+ background: -webkit-linear-gradient(#ddd, #fff);
+ background: -moz-linear-gradient(#ddd, #fff);
+ background: -o-linear-gradient(#ddd, #fff);
+ background: -ms-linear-gradient(#ddd, #fff);
+ background: linear-gradient(#ddd, #fff);
+ -webkit-box-shadow: 0 0 8px rgba(0,0,0,.1) inset;
+ -moz-box-shadow: 0 0 8px rgba(0,0,0,.1) inset;
+ box-shadow: 0 0 8px rgba(0,0,0,.1) inset;
+}
.toolbar ul li a {
background: #fff;
background: -webkit-linear-gradient(#fff, #f0f0f0);
diff --git a/src/static/js/broadcast.js b/src/static/js/broadcast.js
index 191d802e..a25d889b 100644
--- a/src/static/js/broadcast.js
+++ b/src/static/js/broadcast.js
@@ -27,6 +27,7 @@ var Changeset = require('./Changeset');
var linestylefilter = require('./linestylefilter').linestylefilter;
var colorutils = require('./colorutils').colorutils;
var _ = require('./underscore');
+var hooks = require('./pluginfw/hooks');
// These parameters were global, now they are injected. A reference to the
// Timeslider controller would probably be more appropriate.
@@ -534,6 +535,7 @@ function loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, Bro
var savedRev = obj.savedRev;
BroadcastSlider.addSavedRevision(savedRev.revNum, savedRev);
}
+ hooks.callAll('handleClientTimesliderMessage_' + obj.type, {payload: obj});
}
else if(obj.type == "CHANGESET_REQ")
{
diff --git a/src/static/js/linestylefilter.js b/src/static/js/linestylefilter.js
index cb1ee1d5..757fac5a 100644
--- a/src/static/js/linestylefilter.js
+++ b/src/static/js/linestylefilter.js
@@ -34,7 +34,6 @@ var linestylefilter = {};
var _ = require('./underscore');
var AttributeManager = require('./AttributeManager');
-
linestylefilter.ATTRIB_CLASSES = {
'bold': 'tag:b',
'italic': 'tag:i',
@@ -59,6 +58,13 @@ linestylefilter.getAuthorClassName = function(author)
linestylefilter.getLineStyleFilter = function(lineLength, aline, textAndClassFunc, apool)
{
+ // Plugin Hook to add more Attrib Classes
+ hooks.aCallAll('aceAttribClasses', linestylefilter.ATTRIB_CLASSES, function(err, ATTRIB_CLASSES){
+ if(ATTRIB_CLASSES){
+ linestylefilter.ATTRIB_CLASSES = ATTRIB_CLASSES[0];
+ }
+ });
+
if (lineLength == 0) return textAndClassFunc;
var nextAfterAuthorColors = textAndClassFunc;