From 1a5985dc759c33e614eaa53ba9c4d2489c9e3495 Mon Sep 17 00:00:00 2001 From: Luiza Pagliari Date: Mon, 24 Aug 2015 07:58:45 -0700 Subject: [PATCH 1/3] Accepting Arrays on 'exportHtmlAdditionalTags' to handle attributes stored as ['key', 'value'] (and not only ['key', 'true']) --- doc/api/hooks_server-side.md | 11 ++++++++++- src/node/utils/ExportHtml.js | 22 ++++++++++++++++++++-- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/doc/api/hooks_server-side.md b/doc/api/hooks_server-side.md index 79879b2fe..4f441f58a 100644 --- a/doc/api/hooks_server-side.md +++ b/doc/api/hooks_server-side.md @@ -357,7 +357,7 @@ 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. +This hook will allow a plug-in developer to include more properties and attributes to support during HTML Export. An Array should be returned. If a value in this array is a string, the exported HTML will contain tags like `` for the content where attributes are `['tag_name', 'true']`; if a value in this array is a pair `['tag_name', 'value']`, the exported HTML will contain tags like `` for the content where attributes are `['tag_name', 'value']`. Example: ``` @@ -368,6 +368,15 @@ exports.exportHtmlAdditionalTags = function(hook, pad, cb){ }; ``` +Example when attributes are stores as `['color', 'red']` on the attribute pool: +``` +// Add the props to be supported in export +exports.exportHtmlAdditionalTags = function(hook, pad, cb){ + var padId = pad.id; + cb([["color", "red"], ["color", "blue"]]); +}; +``` + ## userLeave Called from src/node/handler/PadMessageHandler.js diff --git a/src/node/utils/ExportHtml.js b/src/node/utils/ExportHtml.js index 9e1ba1249..c5936cf9f 100644 --- a/src/node/utils/ExportHtml.js +++ b/src/node/utils/ExportHtml.js @@ -19,6 +19,7 @@ var async = require("async"); var Changeset = require("ep_etherpad-lite/static/js/Changeset"); var padManager = require("../db/PadManager"); var ERR = require("async-stacktrace"); +var _ = require('underscore'); var Security = require('ep_etherpad-lite/static/js/security'); var hooks = require('ep_etherpad-lite/static/js/pluginfw/hooks'); var _analyzeLine = require('./ExportHelper')._analyzeLine; @@ -78,8 +79,15 @@ function getHTMLFromAtext(pad, atext, authorColors) var props = ['heading1', 'heading2', 'bold', 'italic', 'underline', 'strikethrough']; hooks.aCallAll("exportHtmlAdditionalTags", pad, function(err, newProps){ + // newProps can be simply a string (which means it is stored as attribute in the form of ['tag', 'true']) + // or it can be a pair of values in an Array (for the case when it is stored as ['tag', 'value']). + // The later scenario will generate HTML with tags like newProps.forEach(function (propName, i){ - tags.push(propName); + if (_.isArray(propName)) { + tags.push(propName[0] + ":" + propName[1]); + } else { + tags.push(propName); + } props.push(propName); }); }); @@ -130,7 +138,12 @@ function getHTMLFromAtext(pad, atext, authorColors) // this pad, and if yes puts its attrib id->props value into anumMap props.forEach(function (propName, i) { - var propTrueNum = apool.putAttrib([propName, true], true); + var attrib = [propName, true]; + if (_.isArray(propName)) { + // propName can be in the form of ['color', 'red'] + attrib = propName; + } + var propTrueNum = apool.putAttrib(attrib, true); if (propTrueNum >= 0) { anumMap[propTrueNum] = i; @@ -154,6 +167,11 @@ function getHTMLFromAtext(pad, atext, authorColors) var property = props[i]; + // we are not insterested on properties in the form of ['color', 'red'] + if (_.isArray(property)) { + return false; + } + if(property.substr(0,6) === "author"){ return stripDotFromAuthorID(property); } From ed5262650af5feeb20bab2fa6173a0fe84821492 Mon Sep 17 00:00:00 2001 From: Luiza Pagliari Date: Mon, 7 Sep 2015 03:55:56 -0700 Subject: [PATCH 2/3] Generating pad HTML with tags like instead of --- doc/api/hooks_server-side.md | 2 +- src/node/utils/ExportHtml.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/api/hooks_server-side.md b/doc/api/hooks_server-side.md index 4f441f58a..dde61fe8f 100644 --- a/doc/api/hooks_server-side.md +++ b/doc/api/hooks_server-side.md @@ -357,7 +357,7 @@ 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. If a value in this array is a string, the exported HTML will contain tags like `` for the content where attributes are `['tag_name', 'true']`; if a value in this array is a pair `['tag_name', 'value']`, the exported HTML will contain tags like `` for the content where attributes are `['tag_name', 'value']`. +This hook will allow a plug-in developer to include more properties and attributes to support during HTML Export. An Array should be returned. If a value in this array is a string, the exported HTML will contain tags like `` for the content where attributes are `['tag_name', 'true']`; if a value in this array is a pair `['tag_name', 'value']`, the exported HTML will contain tags like `` for the content where attributes are `['tag_name', 'value']`. Example: ``` diff --git a/src/node/utils/ExportHtml.js b/src/node/utils/ExportHtml.js index c5936cf9f..ccdc3a59e 100644 --- a/src/node/utils/ExportHtml.js +++ b/src/node/utils/ExportHtml.js @@ -81,10 +81,10 @@ function getHTMLFromAtext(pad, atext, authorColors) hooks.aCallAll("exportHtmlAdditionalTags", pad, function(err, newProps){ // newProps can be simply a string (which means it is stored as attribute in the form of ['tag', 'true']) // or it can be a pair of values in an Array (for the case when it is stored as ['tag', 'value']). - // The later scenario will generate HTML with tags like + // The later scenario will generate HTML with tags like newProps.forEach(function (propName, i){ if (_.isArray(propName)) { - tags.push(propName[0] + ":" + propName[1]); + tags.push('span data-' + propName[0] + '="' + propName[1] + '"'); } else { tags.push(propName); } From 1d134f0b138ca23f548a2795e0c68bbc6ea17437 Mon Sep 17 00:00:00 2001 From: Luiza Pagliari Date: Thu, 17 Sep 2015 15:30:09 -0300 Subject: [PATCH 3/3] Fixing ed52626. It was closing the span with , not --- doc/api/hooks_server-side.md | 2 +- src/node/utils/ExportHtml.js | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/api/hooks_server-side.md b/doc/api/hooks_server-side.md index dde61fe8f..8467d0577 100644 --- a/doc/api/hooks_server-side.md +++ b/doc/api/hooks_server-side.md @@ -357,7 +357,7 @@ 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. If a value in this array is a string, the exported HTML will contain tags like `` for the content where attributes are `['tag_name', 'true']`; if a value in this array is a pair `['tag_name', 'value']`, the exported HTML will contain tags like `` for the content where attributes are `['tag_name', 'value']`. +This hook will allow a plug-in developer to include more properties and attributes to support during HTML Export. An Array should be returned. If a value in this array is a string, the exported HTML will contain tags like `` for the content where attributes are `['tag_name', 'true']`; if a value in this array is a pair `['tag_name', 'value']`, the exported HTML will contain tags like `` for the content where attributes are `['tag_name', 'value']`. Example: ``` diff --git a/src/node/utils/ExportHtml.js b/src/node/utils/ExportHtml.js index ccdc3a59e..53469c9b9 100644 --- a/src/node/utils/ExportHtml.js +++ b/src/node/utils/ExportHtml.js @@ -183,6 +183,11 @@ function getHTMLFromAtext(pad, atext, authorColors) return false; } + function isSpanWithData(i){ + var property = props[i]; + return _.isArray(property); + } + function emitOpenTag(i) { openTags.unshift(i); @@ -204,8 +209,9 @@ function getHTMLFromAtext(pad, atext, authorColors) { openTags.shift(); var spanClass = getSpanClassFor(i); + var spanWithData = isSpanWithData(i); - if(spanClass){ + if(spanClass || spanWithData){ assem.append(''); } else { assem.append('