diff options
| author | Michael Williamson <mike@zwobble.org> | 2017-11-04 11:06:59 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2017-11-04 11:06:59 +0000 |
| commit | 1ae8ec5852c9ad94f1773d0014da2bb18887ce9e (patch) | |
| tree | be6a8045ed7ab6e40d54d7d7fcf4695e711ce30c /lib | |
| parent | eae1dd0b509fbe201ba5f7ed530fd1bf8329904a (diff) | |
Parse style mappings for tables
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/style-reader.js | 46 |
1 files changed, 33 insertions, 13 deletions
diff --git a/lib/style-reader.js b/lib/style-reader.js index 692672e..f686b28 100644 --- a/lib/style-reader.js +++ b/lib/style-reader.js @@ -52,7 +52,7 @@ function documentMatcherRule() { var paragraphRule = identifierToConstant("p", documentMatchers.paragraph); var runRule = identifierToConstant("r", documentMatchers.run); - var elementTypeRule = lop.rules.firstOf("p or r", + var elementTypeRule = lop.rules.firstOf("p or r or table", paragraphRule, runRule ); @@ -115,24 +115,43 @@ function documentMatcherRule() { } }; }); - var matcherSuffix = lop.rules.firstOf("matcher suffix", - styleIdRule, - styleNameRule, - listRule - ); - var matcherSuffixes = lop.rules.zeroOrMore(matcherSuffix); + + function createMatcherSuffixesRule(rules) { + var matcherSuffix = lop.rules.firstOf.apply( + lop.rules.firstOf, + ["matcher suffix"].concat(rules) + ); + var matcherSuffixes = lop.rules.zeroOrMore(matcherSuffix); + return lop.rules.then(matcherSuffixes, function(suffixes) { + var matcherOptions = {}; + suffixes.forEach(function(suffix) { + _.extend(matcherOptions, suffix); + }); + return matcherOptions; + }); + } var paragraphOrRun = sequence( sequence.capture(elementTypeRule), - sequence.capture(matcherSuffixes) - ).map(function(createMatcher, suffixes) { - var matcherOptions = {}; - suffixes.forEach(function(suffix) { - _.extend(matcherOptions, suffix); - }); + sequence.capture(createMatcherSuffixesRule([ + styleIdRule, + styleNameRule, + listRule + ])) + ).map(function(createMatcher, matcherOptions) { return createMatcher(matcherOptions); }); + var table = sequence( + lop.rules.token("identifier", "table"), + sequence.capture(createMatcherSuffixesRule([ + styleIdRule, + styleNameRule + ])) + ).map(function(options) { + return documentMatchers.table(options); + }); + var bold = identifierToConstant("b", documentMatchers.bold); var italic = identifierToConstant("i", documentMatchers.italic); var underline = identifierToConstant("u", documentMatchers.underline); @@ -163,6 +182,7 @@ function documentMatcherRule() { return lop.rules.firstOf("element type", paragraphOrRun, + table, bold, italic, underline, |
