ep_font_color
Advanced tools
Comparing version 0.0.15 to 0.0.16
@@ -1,12 +0,9 @@ | ||
var eejs = require('ep_etherpad-lite/node/eejs/'); | ||
var _ = require('ep_etherpad-lite/static/js/underscore'); | ||
const _ = require('ep_etherpad-lite/static/js/underscore'); | ||
const eejs = require('ep_etherpad-lite/node/eejs/'); | ||
var colors = ['black', 'red', 'green', 'blue', 'yellow', 'orange']; | ||
const colors = ['black', 'red', 'green', 'blue', 'yellow', 'orange']; | ||
// Add the props to be supported in export | ||
exports.exportHtmlAdditionalTagsWithData = function(hook, pad, cb){ | ||
var colors_used = findAllColorUsedOn(pad); | ||
var tags = transformColorsIntoTags(colors_used); | ||
cb(tags); | ||
exports.exportHtmlAdditionalTagsWithData = async (hookName, pad) => { | ||
return findAllColorUsedOn(pad).map((name) => ['color', name]); | ||
}; | ||
@@ -16,45 +13,16 @@ | ||
function findAllColorUsedOn(pad) { | ||
var colors_used = []; | ||
pad.pool.eachAttrib(function(key, value){ | ||
if (key === "color") { | ||
colors_used.push(value); | ||
} | ||
}); | ||
return colors_used; | ||
const colorsUsed = []; | ||
pad.pool.eachAttrib((key, value) => { if (key === 'color') colorsUsed.push(value); }); | ||
return colorsUsed; | ||
} | ||
// Transforms an array of color names into color tags like ["color", "red"] | ||
function transformColorsIntoTags(color_names) { | ||
return _.map(color_names, function(color_name) { | ||
return ["color", color_name]; | ||
}); | ||
} | ||
// Include CSS for HTML export | ||
exports.stylesForExport = function(hook, padId, cb){ | ||
var style = eejs.require("ep_font_color/static/css/color.css"); | ||
cb(style); | ||
exports.stylesForExport = async (hookName, padId) => { | ||
return eejs.require('ep_font_color/static/css/color.css'); | ||
}; | ||
// TODO: when "asyncLineHTMLForExport" hook is available on Etherpad, use it instead of "getLineHTMLForExport" | ||
// exports.asyncLineHTMLForExport = function (hook, context, cb) { | ||
// cb(rewriteLine); | ||
// } | ||
exports.getLineHTMLForExport = function (hook, context) { | ||
rewriteLine(context); | ||
} | ||
function rewriteLine(context){ | ||
var lineContent = context.lineContent; | ||
lineContent = replaceDataByClass(lineContent); | ||
// TODO: when "asyncLineHTMLForExport" hook is available on Etherpad, return "lineContent" instead of re-setting it | ||
context.lineContent = lineContent; | ||
} | ||
// Change from <span data-color:x to <span class:color:x | ||
function replaceDataByClass(text) { | ||
return text.replace(/data-color=["|']([0-9a-zA-Z]+)["|']/gi, "class='color:$1'"); | ||
} | ||
exports.getLineHTMLForExport = async (hookName, context) => { | ||
// Replace data-color="foo" with class="color:x". | ||
context.lineContent = | ||
context.lineContent.replace(/data-color=["|']([0-9a-zA-Z]+)["|']/gi, 'class="color:$1"'); | ||
}; |
{ | ||
"description": "Apply colors to fonts", | ||
"name": "ep_font_color", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"license": "Apache-2.0", | ||
@@ -6,0 +6,0 @@ "author": { |
35518
24
509