All new
alle new
This commit is contained in:
1 parent
da64472251
commit
5b20adee48
1605 files changed
+396517
-1674
No files matched your search
+100
@@ -0,0 +1,100 @@
|
||||
exports.paragraph = paragraph;
|
||||
exports.run = run;
|
||||
exports.table = table;
|
||||
exports.bold = new Matcher("bold");
|
||||
exports.italic = new Matcher("italic");
|
||||
exports.underline = new Matcher("underline");
|
||||
exports.strikethrough = new Matcher("strikethrough");
|
||||
exports.allCaps = new Matcher("allCaps");
|
||||
exports.smallCaps = new Matcher("smallCaps");
|
||||
exports.highlight = highlight;
|
||||
exports.commentReference = new Matcher("commentReference");
|
||||
exports.lineBreak = new BreakMatcher({breakType: "line"});
|
||||
exports.pageBreak = new BreakMatcher({breakType: "page"});
|
||||
exports.columnBreak = new BreakMatcher({breakType: "column"});
|
||||
exports.equalTo = equalTo;
|
||||
exports.startsWith = startsWith;
|
||||
|
||||
|
||||
function paragraph(options) {
|
||||
return new Matcher("paragraph", options);
|
||||
}
|
||||
|
||||
function run(options) {
|
||||
return new Matcher("run", options);
|
||||
}
|
||||
|
||||
function table(options) {
|
||||
return new Matcher("table", options);
|
||||
}
|
||||
|
||||
function highlight(options) {
|
||||
return new HighlightMatcher(options);
|
||||
}
|
||||
|
||||
function Matcher(elementType, options) {
|
||||
options = options || {};
|
||||
this._elementType = elementType;
|
||||
this._styleId = options.styleId;
|
||||
this._styleName = options.styleName;
|
||||
if (options.list) {
|
||||
this._listIndex = options.list.levelIndex;
|
||||
this._listIsOrdered = options.list.isOrdered;
|
||||
}
|
||||
}
|
||||
|
||||
Matcher.prototype.matches = function(element) {
|
||||
return element.type === this._elementType &&
|
||||
(this._styleId === undefined || element.styleId === this._styleId) &&
|
||||
(this._styleName === undefined || (element.styleName && this._styleName.operator(this._styleName.operand, element.styleName))) &&
|
||||
(this._listIndex === undefined || isList(element, this._listIndex, this._listIsOrdered)) &&
|
||||
(this._breakType === undefined || this._breakType === element.breakType);
|
||||
};
|
||||
|
||||
function HighlightMatcher(options) {
|
||||
options = options || {};
|
||||
this._color = options.color;
|
||||
}
|
||||
|
||||
HighlightMatcher.prototype.matches = function(element) {
|
||||
return element.type === "highlight" &&
|
||||
(this._color === undefined || element.color === this._color);
|
||||
};
|
||||
|
||||
function BreakMatcher(options) {
|
||||
options = options || {};
|
||||
this._breakType = options.breakType;
|
||||
}
|
||||
|
||||
BreakMatcher.prototype.matches = function(element) {
|
||||
return element.type === "break" &&
|
||||
(this._breakType === undefined || element.breakType === this._breakType);
|
||||
};
|
||||
|
||||
function isList(element, levelIndex, isOrdered) {
|
||||
return element.numbering &&
|
||||
element.numbering.level == levelIndex &&
|
||||
element.numbering.isOrdered == isOrdered;
|
||||
}
|
||||
|
||||
function equalTo(value) {
|
||||
return {
|
||||
operator: operatorEqualTo,
|
||||
operand: value
|
||||
};
|
||||
}
|
||||
|
||||
function startsWith(value) {
|
||||
return {
|
||||
operator: operatorStartsWith,
|
||||
operand: value
|
||||
};
|
||||
}
|
||||
|
||||
function operatorEqualTo(first, second) {
|
||||
return first.toUpperCase() === second.toUpperCase();
|
||||
}
|
||||
|
||||
function operatorStartsWith(first, second) {
|
||||
return second.toUpperCase().indexOf(first.toUpperCase()) === 0;
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
var _ = require("underscore");
|
||||
|
||||
var html = require("../html");
|
||||
|
||||
exports.topLevelElement = topLevelElement;
|
||||
exports.elements = elements;
|
||||
exports.element = element;
|
||||
|
||||
function topLevelElement(tagName, attributes) {
|
||||
return elements([element(tagName, attributes, {fresh: true})]);
|
||||
}
|
||||
|
||||
function elements(elementStyles) {
|
||||
return new HtmlPath(elementStyles.map(function(elementStyle) {
|
||||
if (_.isString(elementStyle)) {
|
||||
return element(elementStyle);
|
||||
} else {
|
||||
return elementStyle;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
function HtmlPath(elements) {
|
||||
this._elements = elements;
|
||||
}
|
||||
|
||||
HtmlPath.prototype.wrap = function wrap(children) {
|
||||
var result = children();
|
||||
for (var index = this._elements.length - 1; index >= 0; index--) {
|
||||
result = this._elements[index].wrapNodes(result);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
function element(tagName, attributes, options) {
|
||||
options = options || {};
|
||||
return new Element(tagName, attributes, options);
|
||||
}
|
||||
|
||||
function Element(tagName, attributes, options) {
|
||||
var tagNames = Object.create(null);
|
||||
if (_.isArray(tagName)) {
|
||||
tagName.forEach(function(tagName) {
|
||||
tagNames[tagName] = true;
|
||||
});
|
||||
tagName = tagName[0];
|
||||
} else {
|
||||
tagNames[tagName] = true;
|
||||
}
|
||||
|
||||
this.tagName = tagName;
|
||||
this.tagNames = tagNames;
|
||||
this.attributes = attributes || {};
|
||||
this.fresh = options.fresh;
|
||||
this.separator = options.separator;
|
||||
}
|
||||
|
||||
Element.prototype.matchesElement = function(element) {
|
||||
return this.tagNames[element.tagName] && _.isEqual(this.attributes || {}, element.attributes || {});
|
||||
};
|
||||
|
||||
Element.prototype.wrap = function wrap(generateNodes) {
|
||||
return this.wrapNodes(generateNodes());
|
||||
};
|
||||
|
||||
Element.prototype.wrapNodes = function wrapNodes(nodes) {
|
||||
return [html.elementWithTag(this, nodes)];
|
||||
};
|
||||
|
||||
exports.empty = elements([]);
|
||||
exports.ignore = {
|
||||
wrap: function() {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
var lop = require("lop");
|
||||
var RegexTokeniser = lop.RegexTokeniser;
|
||||
|
||||
exports.tokenise = tokenise;
|
||||
|
||||
var stringPrefix = "'((?:\\\\(?:.|$)|[^'\\\\])*)";
|
||||
|
||||
function tokenise(string) {
|
||||
var identifierCharacter = "(?:[a-zA-Z\\-_]|\\\\.)";
|
||||
var tokeniser = new RegexTokeniser([
|
||||
{name: "identifier", regex: new RegExp("(" + identifierCharacter + "(?:" + identifierCharacter + "|[0-9])*)")},
|
||||
{name: "dot", regex: /\./},
|
||||
{name: "colon", regex: /:/},
|
||||
{name: "gt", regex: />/},
|
||||
{name: "whitespace", regex: /\s+/},
|
||||
{name: "arrow", regex: /=>/},
|
||||
{name: "equals", regex: /=/},
|
||||
{name: "startsWith", regex: /\^=/},
|
||||
{name: "open-paren", regex: /\(/},
|
||||
{name: "close-paren", regex: /\)/},
|
||||
{name: "open-square-bracket", regex: /\[/},
|
||||
{name: "close-square-bracket", regex: /\]/},
|
||||
{name: "string", regex: new RegExp(stringPrefix + "'")},
|
||||
{name: "unterminated-string", regex: new RegExp(stringPrefix)},
|
||||
{name: "integer", regex: /([0-9]+)/},
|
||||
{name: "choice", regex: /\|/},
|
||||
{name: "bang", regex: /(!)/}
|
||||
]);
|
||||
return tokeniser.tokenise(string);
|
||||
}
|
||||
Reference in new issue
Block a user