From c1a3e929b7268f14619daf3eff0085a747703f7e Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 8 Apr 2013 20:34:34 +0100 Subject: Remove properties attribute from Run --- lib/document-to-html.js | 8 ++++---- lib/documents.js | 13 +++++++++++-- tests/document-xml-reader.tests.js | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/document-to-html.js b/lib/document-to-html.js index a2d7030..1fce576 100644 --- a/lib/document-to-html.js +++ b/lib/document-to-html.js @@ -51,16 +51,16 @@ function DocumentConverter(options) { function convertRun(run, html) { var runHtml = new HtmlGenerator(); - if (run.properties.styleName) { - var style = runStyleMap[run.properties.styleName]; + if (run.styleName) { + var style = runStyleMap[run.styleName]; if (style) { runHtml.style(style); } } - if (run.properties.isBold) { + if (run.isBold) { runHtml.push(styles.element("strong")); } - if (run.properties.isItalic) { + if (run.isItalic) { runHtml.push(styles.element("em")); } return convertElements(run.children, runHtml) diff --git a/lib/documents.js b/lib/documents.js index e4f0ef7..f1ce08b 100644 --- a/lib/documents.js +++ b/lib/documents.js @@ -5,8 +5,6 @@ function Document(children) { }; } -Run = ElementWithChildren("run"); - function Paragraph(children, properties) { properties = properties || {}; return { @@ -16,6 +14,17 @@ function Paragraph(children, properties) { }; } +function Run(children, properties) { + properties = properties || {}; + return { + type: "run", + children: children, + styleName: properties.styleName, + isBold: properties.isBold, + isItalic: properties.isItalic + }; +} + function Text(value) { return { type: "text", diff --git a/tests/document-xml-reader.tests.js b/tests/document-xml-reader.tests.js index d71f76c..cde4cf4 100644 --- a/tests/document-xml-reader.tests.js +++ b/tests/document-xml-reader.tests.js @@ -71,7 +71,7 @@ describe("readXmlElement: ", function() { var runPropertiesXml = new XmlElement("w:rPr", {}, [runStyleXml]); var runXml = new XmlElement("w:r", {}, [runPropertiesXml]); var result = readXmlElement(runXml); - assert.equal(result.value.properties.styleName, "Emphasis"); + assert.equal(result.value.styleName, "Emphasis"); }); test("run properties not included as child of run", function() { -- cgit v1.2.3