mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 14:13:34 +01:00
Merge pull request #2827 from storytouch/exportHtmlAdditionalTagsWithData
Create hook exportHtmlAdditionalTagsWithData
This commit is contained in:
commit
062e6f308f
2 changed files with 32 additions and 17 deletions
|
@ -81,7 +81,7 @@ Available blocks in `pad.html` are:
|
||||||
* `modals` - Contains all connectivity messages
|
* `modals` - Contains all connectivity messages
|
||||||
* `embedPopup` - the embed dropdown
|
* `embedPopup` - the embed dropdown
|
||||||
* `scripts` - Add your script tags here, if you really have to (consider use client-side hooks instead)
|
* `scripts` - Add your script tags here, if you really have to (consider use client-side hooks instead)
|
||||||
|
|
||||||
`timeslider.html` blocks:
|
`timeslider.html` blocks:
|
||||||
|
|
||||||
* `timesliderStyles`
|
* `timesliderStyles`
|
||||||
|
@ -90,9 +90,9 @@ Available blocks in `pad.html` are:
|
||||||
* `timesliderTop`
|
* `timesliderTop`
|
||||||
* `timesliderEditbarRight`
|
* `timesliderEditbarRight`
|
||||||
* `modals`
|
* `modals`
|
||||||
|
|
||||||
`index.html` blocks:
|
`index.html` blocks:
|
||||||
|
|
||||||
* `indexWrapper` - contains the form for creating new pads
|
* `indexWrapper` - contains the form for creating new pads
|
||||||
|
|
||||||
## padInitToolbar
|
## padInitToolbar
|
||||||
|
@ -334,7 +334,7 @@ exports.aceAttribClasses = function(hook_name, attr, cb){
|
||||||
```
|
```
|
||||||
|
|
||||||
## exportFileName
|
## exportFileName
|
||||||
Called from src/node/handler/ExportHandler.js
|
Called from src/node/handler/ExportHandler.js
|
||||||
|
|
||||||
Things in context:
|
Things in context:
|
||||||
|
|
||||||
|
@ -357,7 +357,7 @@ Things in context:
|
||||||
|
|
||||||
1. Pad object
|
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 `<tag_name>` 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 `<span data-tag_name="value">` 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. If tags are stored as `['color', 'red']` on the attribute pool, use `exportHtmlAdditionalTagsWithData` instead. An Array should be returned.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
```
|
```
|
||||||
|
@ -368,10 +368,19 @@ exports.exportHtmlAdditionalTags = function(hook, pad, cb){
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
Example when attributes are stores as `['color', 'red']` on the attribute pool:
|
## exportHtmlAdditionalTagsWithData
|
||||||
|
Called from src/node/utils/ExportHtml.js
|
||||||
|
|
||||||
|
Things in context:
|
||||||
|
|
||||||
|
1. Pad object
|
||||||
|
|
||||||
|
Identical to `exportHtmlAdditionalTags`, but for tags that are stored with an specific value (not simply `true`) on the attribute pool. For example `['color', 'red']`, instead of `['bold', true]`. This hook will allow a plug-in developer to include more properties and attributes to support during HTML Export. An Array of arrays should be returned. The exported HTML will contain tags like `<span data-color="red">` for the content where attributes are `['color', 'red']`.
|
||||||
|
|
||||||
|
Example:
|
||||||
```
|
```
|
||||||
// Add the props to be supported in export
|
// Add the props to be supported in export
|
||||||
exports.exportHtmlAdditionalTags = function(hook, pad, cb){
|
exports.exportHtmlAdditionalTagsWithData = function(hook, pad, cb){
|
||||||
var padId = pad.id;
|
var padId = pad.id;
|
||||||
cb([["color", "red"], ["color", "blue"]]);
|
cb([["color", "red"], ["color", "blue"]]);
|
||||||
};
|
};
|
||||||
|
|
|
@ -78,16 +78,18 @@ function getHTMLFromAtext(pad, atext, authorColors)
|
||||||
var tags = ['h1', 'h2', 'strong', 'em', 'u', 's'];
|
var tags = ['h1', 'h2', 'strong', 'em', 'u', 's'];
|
||||||
var props = ['heading1', 'heading2', 'bold', 'italic', 'underline', 'strikethrough'];
|
var props = ['heading1', 'heading2', 'bold', 'italic', 'underline', 'strikethrough'];
|
||||||
|
|
||||||
|
// prepare tags stored as ['tag', true] to be exported
|
||||||
hooks.aCallAll("exportHtmlAdditionalTags", pad, function(err, newProps){
|
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 <span data-tag="value">
|
|
||||||
newProps.forEach(function (propName, i){
|
newProps.forEach(function (propName, i){
|
||||||
if (_.isArray(propName)) {
|
tags.push(propName);
|
||||||
tags.push('span data-' + propName[0] + '="' + propName[1] + '"');
|
props.push(propName);
|
||||||
} else {
|
});
|
||||||
tags.push(propName);
|
});
|
||||||
}
|
// prepare tags stored as ['tag', 'value'] to be exported. This will generate HTML
|
||||||
|
// with tags like <span data-tag="value">
|
||||||
|
hooks.aCallAll("exportHtmlAdditionalTagsWithData", pad, function(err, newProps){
|
||||||
|
newProps.forEach(function (propName, i){
|
||||||
|
tags.push('span data-' + propName[0] + '="' + propName[1] + '"');
|
||||||
props.push(propName);
|
props.push(propName);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -140,7 +142,8 @@ function getHTMLFromAtext(pad, atext, authorColors)
|
||||||
{
|
{
|
||||||
var attrib = [propName, true];
|
var attrib = [propName, true];
|
||||||
if (_.isArray(propName)) {
|
if (_.isArray(propName)) {
|
||||||
// propName can be in the form of ['color', 'red']
|
// propName can be in the form of ['color', 'red'],
|
||||||
|
// see hook exportHtmlAdditionalTagsWithData
|
||||||
attrib = propName;
|
attrib = propName;
|
||||||
}
|
}
|
||||||
var propTrueNum = apool.putAttrib(attrib, true);
|
var propTrueNum = apool.putAttrib(attrib, true);
|
||||||
|
@ -167,7 +170,8 @@ function getHTMLFromAtext(pad, atext, authorColors)
|
||||||
|
|
||||||
var property = props[i];
|
var property = props[i];
|
||||||
|
|
||||||
// we are not insterested on properties in the form of ['color', 'red']
|
// we are not insterested on properties in the form of ['color', 'red'],
|
||||||
|
// see hook exportHtmlAdditionalTagsWithData
|
||||||
if (_.isArray(property)) {
|
if (_.isArray(property)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -183,6 +187,8 @@ function getHTMLFromAtext(pad, atext, authorColors)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// tags added by exportHtmlAdditionalTagsWithData will be exported as <span> with
|
||||||
|
// data attributes
|
||||||
function isSpanWithData(i){
|
function isSpanWithData(i){
|
||||||
var property = props[i];
|
var property = props[i];
|
||||||
return _.isArray(property);
|
return _.isArray(property);
|
||||||
|
|
Loading…
Reference in a new issue