mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-02-01 03:12:42 +01:00
made domline and content collector lineAttributes compatible
This commit is contained in:
parent
9efe838a32
commit
6507614e45
2 changed files with 62 additions and 22 deletions
|
@ -27,6 +27,7 @@ var _MAX_LIST_LEVEL = 8;
|
||||||
|
|
||||||
var Changeset = require('./Changeset');
|
var Changeset = require('./Changeset');
|
||||||
var hooks = require('./pluginfw/hooks');
|
var hooks = require('./pluginfw/hooks');
|
||||||
|
var _ = require('./underscore');
|
||||||
|
|
||||||
function sanitizeUnicode(s)
|
function sanitizeUnicode(s)
|
||||||
{
|
{
|
||||||
|
@ -182,7 +183,7 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class
|
||||||
{
|
{
|
||||||
var ln = lines.length() - 1;
|
var ln = lines.length() - 1;
|
||||||
var chr = lines.textOfLine(ln).length;
|
var chr = lines.textOfLine(ln).length;
|
||||||
if (chr == 0 && state.listType && state.listType != 'none')
|
if (chr == 0 && !_.isEmpty(state.lineAttributes))
|
||||||
{
|
{
|
||||||
chr += 1; // listMarker
|
chr += 1; // listMarker
|
||||||
}
|
}
|
||||||
|
@ -234,25 +235,30 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class
|
||||||
|
|
||||||
function _enterList(state, listType)
|
function _enterList(state, listType)
|
||||||
{
|
{
|
||||||
var oldListType = state.listType;
|
var oldListType = state.lineAttributes['list'];
|
||||||
state.listLevel = (state.listLevel || 0) + 1;
|
|
||||||
if (listType != 'none')
|
if (listType != 'none')
|
||||||
{
|
{
|
||||||
state.listNesting = (state.listNesting || 0) + 1;
|
state.listNesting = (state.listNesting || 0) + 1;
|
||||||
}
|
}
|
||||||
state.listType = listType;
|
|
||||||
|
if(listType === 'none' || !listType ){
|
||||||
|
delete state.lineAttributes['list'];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
state.lineAttributes['list'] = listType;
|
||||||
|
}
|
||||||
|
|
||||||
_recalcAttribString(state);
|
_recalcAttribString(state);
|
||||||
return oldListType;
|
return oldListType;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _exitList(state, oldListType)
|
function _exitList(state, oldListType)
|
||||||
{
|
{
|
||||||
state.listLevel--;
|
if (state.lineAttributes['list'])
|
||||||
if (state.listType != 'none')
|
|
||||||
{
|
{
|
||||||
state.listNesting--;
|
state.listNesting--;
|
||||||
}
|
}
|
||||||
state.listType = oldListType;
|
if(oldListType) state.lineAttributes['list'] = oldListType;
|
||||||
_recalcAttribString(state);
|
_recalcAttribString(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,21 +301,29 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class
|
||||||
state.attribString = Changeset.makeAttribsString('+', lst, apool);
|
state.attribString = Changeset.makeAttribsString('+', lst, apool);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _produceListMarker(state)
|
function _produceLineAttributesMarker(state)
|
||||||
{
|
{
|
||||||
lines.appendText('*', Changeset.makeAttribsString('+', [
|
// TODO: This has to go to AttributeManager.
|
||||||
['list', state.listType],
|
var attributes = [
|
||||||
|
['lmkr', '1'],
|
||||||
['insertorder', 'first']
|
['insertorder', 'first']
|
||||||
], apool));
|
].concat(
|
||||||
|
_.map(state.lineAttributes,function(value,key){
|
||||||
|
console.log([key, value])
|
||||||
|
return [key, value];
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
lines.appendText('*', Changeset.makeAttribsString('+', attributes , apool));
|
||||||
}
|
}
|
||||||
cc.startNewLine = function(state)
|
cc.startNewLine = function(state)
|
||||||
{
|
{
|
||||||
if (state)
|
if (state)
|
||||||
{
|
{
|
||||||
var atBeginningOfLine = lines.textOfLine(lines.length() - 1).length == 0;
|
var atBeginningOfLine = lines.textOfLine(lines.length() - 1).length == 0;
|
||||||
if (atBeginningOfLine && state.listType && state.listType != 'none')
|
if (atBeginningOfLine && !_.isEmpty(state.lineAttributes))
|
||||||
{
|
{
|
||||||
_produceListMarker(state);
|
_produceLineAttributesMarker(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lines.startNew();
|
lines.startNew();
|
||||||
|
@ -339,7 +353,14 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class
|
||||||
localAttribs: null,
|
localAttribs: null,
|
||||||
attribs: { /*name -> nesting counter*/
|
attribs: { /*name -> nesting counter*/
|
||||||
},
|
},
|
||||||
attribString: ''
|
attribString: '',
|
||||||
|
// lineAttributes maintain a map from attributes to attribute values set on a line
|
||||||
|
lineAttributes: {
|
||||||
|
/*
|
||||||
|
example:
|
||||||
|
'list': 'bullet1',
|
||||||
|
*/
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
var localAttribs = state.localAttribs;
|
var localAttribs = state.localAttribs;
|
||||||
|
@ -401,9 +422,9 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class
|
||||||
// newlines in the source mustn't become spaces at beginning of line box
|
// newlines in the source mustn't become spaces at beginning of line box
|
||||||
txt2 = txt2.replace(/^\n*/, '');
|
txt2 = txt2.replace(/^\n*/, '');
|
||||||
}
|
}
|
||||||
if (atBeginningOfLine && state.listType && state.listType != 'none')
|
if (atBeginningOfLine && !_.isEmpty(state.lineAttributes))
|
||||||
{
|
{
|
||||||
_produceListMarker(state);
|
_produceLineAttributesMarker(state);
|
||||||
}
|
}
|
||||||
lines.appendText(textify(txt2), state.attribString);
|
lines.appendText(textify(txt2), state.attribString);
|
||||||
x += consumed;
|
x += consumed;
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
var Security = require('./security');
|
var Security = require('./security');
|
||||||
var hooks = require('./pluginfw/hooks');
|
var hooks = require('./pluginfw/hooks');
|
||||||
var _ = require('./underscore');
|
var _ = require('./underscore');
|
||||||
|
var lineAttributeMarker = require('./linestylefilter').lineAttributeMarker;
|
||||||
var Ace2Common = require('./ace2_common');
|
var Ace2Common = require('./ace2_common');
|
||||||
var noop = Ace2Common.noop;
|
var noop = Ace2Common.noop;
|
||||||
|
|
||||||
|
@ -82,7 +82,8 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument)
|
||||||
}
|
}
|
||||||
|
|
||||||
var html = [];
|
var html = [];
|
||||||
var preHtml, postHtml;
|
var preHtml = '',
|
||||||
|
postHtml = '';
|
||||||
var curHTML = null;
|
var curHTML = null;
|
||||||
|
|
||||||
function processSpaces(s)
|
function processSpaces(s)
|
||||||
|
@ -95,7 +96,9 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument)
|
||||||
var lineClass = 'ace-line';
|
var lineClass = 'ace-line';
|
||||||
result.appendSpan = function(txt, cls)
|
result.appendSpan = function(txt, cls)
|
||||||
{
|
{
|
||||||
if (cls.indexOf('list') >= 0)
|
var processedMarker = false;
|
||||||
|
// Handle lineAttributeMarker, if present
|
||||||
|
if (cls.indexOf(lineAttributeMarker) >= 0)
|
||||||
{
|
{
|
||||||
var listType = /(?:^| )list:(\S+)/.exec(cls);
|
var listType = /(?:^| )list:(\S+)/.exec(cls);
|
||||||
var start = /(?:^| )start:(\S+)/.exec(cls);
|
var start = /(?:^| )start:(\S+)/.exec(cls);
|
||||||
|
@ -116,9 +119,25 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument)
|
||||||
postHtml = '</li></ol>';
|
postHtml = '</li></ol>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
processedMarker = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
_.map(hooks.callAll("aceDomLineProcessLineAttributes", {
|
||||||
|
domline: domline,
|
||||||
|
cls: cls
|
||||||
|
}), function(modifier)
|
||||||
|
{
|
||||||
|
preHtml += modifier.preHtml;
|
||||||
|
postHtml += modifier.postHtml;
|
||||||
|
processedMarker |= modifier.processedMarker;
|
||||||
|
});
|
||||||
|
|
||||||
|
if( processedMarker ){
|
||||||
result.lineMarker += txt.length;
|
result.lineMarker += txt.length;
|
||||||
return; // don't append any text
|
return; // don't append any text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
var href = null;
|
var href = null;
|
||||||
var simpleTags = null;
|
var simpleTags = null;
|
||||||
|
@ -203,7 +222,7 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument)
|
||||||
{
|
{
|
||||||
newHTML = (preHtml || '') + newHTML + (postHtml || '');
|
newHTML = (preHtml || '') + newHTML + (postHtml || '');
|
||||||
}
|
}
|
||||||
html = preHtml = postHtml = null; // free memory
|
html = preHtml = postHtml = ''; // free memory
|
||||||
if (newHTML !== curHTML)
|
if (newHTML !== curHTML)
|
||||||
{
|
{
|
||||||
curHTML = newHTML;
|
curHTML = newHTML;
|
||||||
|
|
Loading…
Reference in a new issue