From 1c05933dc91c9669a2f8407ab471c204f6975e98 Mon Sep 17 00:00:00 2001 From: Thomas Muehlichen Date: Thu, 26 Mar 2015 18:49:35 +0100 Subject: [PATCH 1/2] Feature #2567 Added workaround to enable contentcollector to write key-value attributes --- src/static/js/contentcollector.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/static/js/contentcollector.js b/src/static/js/contentcollector.js index e428c63f..cb3cf7b0 100644 --- a/src/static/js/contentcollector.js +++ b/src/static/js/contentcollector.js @@ -297,7 +297,23 @@ function makeContentCollector(collectStyles, abrowser, apool, domInterface, clas { if (state.attribs[a]) { - lst.push([a, 'true']); + // The following splitting of the attribute name is a workaround + // to enable the content collector to store key-value attributes + // see https://github.com/ether/etherpad-lite/issues/2567 for more information + // in long term the contentcollector should be refactored to get rid of this workaround + var ATTRIBUTE_SPLIT_STRING = "::"; + + // see if attributeString is splittable + var attributeSplits = a.split(ATTRIBUTE_SPLIT_STRING); + if (attributeSplits.length > 1) { + // the attribute name follows the convention key::value + // so save it as a key value attribute + lst.push([attributeSplits[0], attributeSplits[1]]); + } else { + // the "normal" case, the attribute is just a switch + // so set it true + lst.push([a, 'true']); + } } } if (state.authorLevel > 0) From 1e8e64d675691b4c8dc0f461958a439ec33d6154 Mon Sep 17 00:00:00 2001 From: Thomas Muehlichen Date: Tue, 31 Mar 2015 10:50:20 +0200 Subject: [PATCH 2/2] feature #2567 added documentation --- doc/api/hooks_client-side.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/api/hooks_client-side.md b/doc/api/hooks_client-side.md index 8e2d3da7..f9ad9147 100644 --- a/doc/api/hooks_client-side.md +++ b/doc/api/hooks_client-side.md @@ -203,6 +203,13 @@ Things in context: This hook is called before the content of a node is collected by the usual methods. The cc object can be used to do a bunch of things that modify the content of the pad. See, for example, the heading1 plugin for etherpad original. +E.g. if you need to apply an attribute to newly inserted characters, +call cc.doAttrib(state, "attributeName") which results in an attribute attributeName=true. + +If you want to specify also a value, call cc.doAttrib(state, "attributeName:value") +which results in an attribute attributeName=value. + + ## collectContentImage Called from: src/static/js/contentcollector.js