From 5373edd7a5b62476377852da5d826ffb23d73538 Mon Sep 17 00:00:00 2001 From: bludot Date: Sun, 1 Sep 2013 01:21:56 -0400 Subject: [PATCH 1/3] Create README.md --- README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..6eedd2e --- /dev/null +++ b/README.md @@ -0,0 +1,46 @@ +DOCX.js +======= + +DOCX.js is a JavaScript library for converting the data in base64 DOCX files into HTML - and back! Please note that this library is licensed under the Microsoft Office Extensible File License - a license NOT approved by the OSI. While this license is based off of the MS-PL, which is OSI-approved, there are significant differences. + +mceDocx.js +========== + +Docx.js for tinyMCE + +This is a modified version of docx.js from [https://github.com/stephen-hardy/docx.js](https://github.com/stephen-hardy/docx.js). + +## Dependencies + + * JsZip.js + +## How to + + + + + + + + + + + + + + + + + From 2f83800fcf170710ab283fce3674d7b3de6cd0e0 Mon Sep 17 00:00:00 2001 From: bludot Date: Sun, 1 Sep 2013 01:22:31 -0400 Subject: [PATCH 2/3] Update docx.js --- docx.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/docx.js b/docx.js index 3a93746..e194ece 100644 --- a/docx.js +++ b/docx.js @@ -36,7 +36,9 @@ function convertContent(input) { 'use strict'; // Convert HTML to Wordprocessing if (inNodeChild.nodeName === 'r') { val = inNodeChild.textContent; if (inNodeChild.getElementsByTagName('b').length) { val = '' + val + ''; } + if (inNodeChild.getElementsByTagName('strong').length) { val = '' + val + ''; } if (inNodeChild.getElementsByTagName('i').length) { val = '' + val + ''; } + if (inNodeChild.getElementsByTagName('em').length) { val = '' + val + ''; } if (inNodeChild.getElementsByTagName('u').length) { val = '' + val + ''; } if (inNodeChild.getElementsByTagName('strike').length) { val = '' + val + ''; } if (styleAttrNode = inNodeChild.getElementsByTagName('vertAlign')[0]) { @@ -71,7 +73,7 @@ function convertContent(input) { 'use strict'; // Convert HTML to Wordprocessing for (i = 0; inNode = input.childNodes[i]; i++) { outNode = output.appendChild(newXMLnode('p')); pCount++; - if (inNode.style.textAlign) { outNode.appendChild(newXMLnode('pPr')).appendChild(newXMLnode('jc')).setAttribute('val', inNode.style.textAlign); } + if (inNode.style && inNode.style.textAlign) { outNode.appendChild(newXMLnode('pPr')).appendChild(newXMLnode('jc')).setAttribute('val', inNode.style.textAlign); } if (inNode.nodeName === '#text') { outNode.appendChild(newXMLnode('r')).appendChild(newXMLnode('t', inNode.nodeValue)); } else { for (j = 0; inNodeChild = inNode.childNodes[j]; j++) { @@ -80,7 +82,11 @@ function convertContent(input) { 'use strict'; // Convert HTML to Wordprocessing styleAttrNode = outNodeChild.appendChild(newXMLnode('rPr')); tempStr = inNodeChild.outerHTML; if (tempStr.indexOf('') > -1) { styleAttrNode.appendChild(newXMLnode('b')); } + if (tempStr.indexOf('') > -1) { styleAttrNode.appendChild(newXMLnode('b')); } + if (tempStr.indexOf('') > -1) { styleAttrNode.appendChild(newXMLnode('i')); } + if (tempStr.indexOf('') > -1) { styleAttrNode.appendChild(newXMLnode('i')); } if (tempStr.indexOf('') > -1) { styleAttrNode.appendChild(newXMLnode('i')); } + if (tempStr.indexOf(' -1) { styleAttrNode.appendChild(newXMLnode('u')).setAttribute('val', 'single'); } if (tempStr.indexOf('') > -1) { styleAttrNode.appendChild(newXMLnode('u')).setAttribute('val', 'single'); } if (tempStr.indexOf('') > -1) { styleAttrNode.appendChild(newXMLnode('strike')); } if (tempStr.indexOf('') > -1) { styleAttrNode.appendChild(newXMLnode('vertAlign')).setAttribute('val', 'subscript'); } @@ -98,6 +104,7 @@ function convertContent(input) { 'use strict'; // Convert HTML to Wordprocessing output = { string: new XMLSerializer().serializeToString(output).replace(//g, '').replace(/val=/g, 'w:val='), charSpaceCount: input.textContent.length, charCount: input.textContent.replace(/\s/g, '').length, pCount: pCount + //charSpaceCount: 0, charCount: 0, pCount: pCount }; } return output; @@ -106,7 +113,7 @@ function convertContent(input) { 'use strict'; // Convert HTML to Wordprocessing function docx(file) { 'use strict'; // v1.0.1 var result, zip = new JSZip(), zipTime, processTime, docProps, word, content; - if (typeof file === 'string') { // Load + if (typeof file === "string") { // Load zipTime = Date.now(); zip = zip.load(file, { base64: true }); result = { zipTime: Date.now() - zipTime }; @@ -127,9 +134,9 @@ function docx(file) { 'use strict'; // v1.0.1 result.processTime = Date.now() - processTime; } else { // Save - content = convertContent(file.DOM); + content = convertContent(file); processTime = Date.now(); - sharedStrings = [[], 0]; + var sharedStrings = [[], 0]; //{ Fully static zip.file('[Content_Types].xml', ''); zip.folder('_rels').file('.rels', ''); @@ -169,4 +176,4 @@ function docx(file) { 'use strict'; // v1.0.1 } } return result; -} \ No newline at end of file +} From 04aaa60cdfa8bf372df037d2b2653a627ea8f85a Mon Sep 17 00:00:00 2001 From: bludot Date: Sun, 1 Sep 2013 01:27:59 -0400 Subject: [PATCH 3/3] Update README.md --- README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/README.md b/README.md index 6eedd2e..f7e9256 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,6 @@ DOCX.js DOCX.js is a JavaScript library for converting the data in base64 DOCX files into HTML - and back! Please note that this library is licensed under the Microsoft Office Extensible File License - a license NOT approved by the OSI. While this license is based off of the MS-PL, which is OSI-approved, there are significant differences. -mceDocx.js -========== - Docx.js for tinyMCE This is a modified version of docx.js from [https://github.com/stephen-hardy/docx.js](https://github.com/stephen-hardy/docx.js).