mwilliamson / mammoth.js Goto Github PK
View Code? Open in Web Editor NEWConvert Word documents (.docx files) to HTML
License: BSD 2-Clause "Simplified" License
Convert Word documents (.docx files) to HTML
License: BSD 2-Clause "Simplified" License
I have a docx that has additional white space between line 1 and 2. These spaces are lost during import.. Analysis of the document shows..
Line number 0
{ type: 'paragraph',
children:
[ { type: 'run',
children: [Object],
styleId: null,
styleName: null,
isBold: false,
isUnderline: false,
isItalic: false,
verticalAlignment: 'baseline' } ],
styleId: 'NormalWeb',
styleName: 'Normal (Web)',
numbering: null,
alignment: 'both' }
{ type: 'run',
children:
[ { type: 'text',
value: 'Lorem ipr id.' } ],
styleId: null,
styleName: null,
isBold: false,
isUnderline: false,
isItalic: false,
verticalAlignment: 'baseline' }
==========================
Line number 1
{ type: 'paragraph',
children: [],
styleId: 'NormalWeb',
styleName: 'Normal (Web)',
numbering: null,
alignment: 'both' }
undefined
==========================
Line number 2
{ type: 'paragraph',
children:
[ { type: 'run',
children: [Object],
styleId: null,
styleName: null,
isBold: false,
isUnderline: false,
isItalic: false,
verticalAlignment: 'baseline' } ],
styleId: 'NormalWeb',
styleName: 'Normal (Web)',
numbering: null,
alignment: 'both' }
{ type: 'run', children:
[ { type: 'text',
value: 'Vestibulum nec iaculis sapien. Nunc malesuada convallis hendrerit. Maecenas et rutrum risus. Fusce ac tem
pus massa. Phasellus et quam feugiat, ultricies turpis et, accumsan odio. Class aptent taciti sociosqu ad litora torquen
t per conubia nostra, per inceptos himenaeos. Vivamus euismod vitae turpis eu auctor. Nam interdum nunc a purus pretium,
vel maximus sapien volutpat. Aliquam nec metus quis nibh vulputate placerat sit amet a tellus. Ut luctus et nibh eu tin
cidunt. Aliquam ut nibh facilisis, vestibulum nisi sagittis, scelerisque erat. Nunc blandit purus neque, sit amet ornare
sapien aliquet non. Vestibulum sapien turpis, tincidunt nec suscipit ut, dapibus nec eros.' } ],
styleId: null,
styleName: null,
isBold: false,
isUnderline: false,
isItalic: false,
verticalAlignment: 'baseline' }
==========================
Line number 3
{ type: 'paragraph',
children: [],
styleId: 'NormalWeb',
styleName: 'Normal (Web)',
numbering: null,
alignment: 'both' }
undefined
==========================
Line number 4
{ type: 'paragraph',
children:
[ { type: 'run',
children: [Object],
styleId: null,
styleName: null,
isBold: false,
isUnderline: false,
isItalic: false,
verticalAlignment: 'baseline' } ],
styleId: 'NormalWeb',
styleName: 'Normal (Web)',
numbering: null,
alignment: 'both' }
{ type: 'run',
children:
[ { type: 'text',
value: 'Nulla blandit
Note the "undefined", something doesn't look right ;)
At the moment, strike-through is entirely supported, while underline is supported through an API option. Supporting both using the style map would allow conversion with either without users having to write code.
Is there a way to run mammoth and maintain all the styles from the word doc? So in case the header h1 is set in Comic Sans 22px in Cyan, the html would be
<h1 style="font-family: 'Comic Sans'; font-size: 22px;">
Always getting this error, no idea what I am doing wrong.
Installed it via "npm install mammoth -g"
Running it like "mammoth myWord.docx myHtml.html"
[2015-04-20 15:03:06.562] [ERROR] console - Error: Non-whitespace before first tag.
at error (/home/etherpad-lite/node_modules/ep_mammoth/node_modules/mammoth/node_modules/sax/lib/sax.js:642:8)
at strictFail (/home/etherpad-lite/node_modules/ep_mammoth/node_modules/mammoth/node_modules/sax/lib/sax.js:662:22)
at Object.write (/home/etherpad-lite/node_modules/ep_mammoth/node_modules/mammoth/node_modules/sax/lib/sax.js:934:11)
at Object.read (/home/etherpad-lite/node_modules/ep_mammoth/node_modules/mammoth/lib/xmlreader.js:75:12)
at read (/home/etherpad-lite/node_modules/ep_mammoth/node_modules/mammoth/lib/office-xml-reader.js:19:22)
at _fulfilled (/home/etherpad-lite/node_modules/ep_mammoth/node_modules/mammoth/node_modules/q/q.js:798:54)
at self.promiseDispatch.done (/home/etherpad-lite/node_modules/ep_mammoth/node_modules/mammoth/node_modules/q/q.js:827:30)
at Promise.promise.promiseDispatch (/home/etherpad-lite/node_modules/ep_mammoth/node_modules/mammoth/node_modules/q/q.js:760:13)
at /home/etherpad-lite/node_modules/ep_mammoth/node_modules/mammoth/node_modules/q/q.js:574:44
at flush (/home/etherpad-lite/node_modules/ep_mammoth/node_modules/mammoth/node_modules/q/q.js:108:17)
Not sure on STR, just spotted this issue and thought right place to report is here.
I would like to use this project as a dependency, but do not see a license.
What is the license for this project?
Already supported in python-mammoth. Both relative and absolute URIs should be supported. If run in a browser rather locally, we should raise an exception (since we won't be able to read local files). Based on the test file created by LibreOffice, it seems we also need to support missing content types. (Whether or not that's because they're linked images or because of LibreOffice isn't clear, but is also somewhat irrelevant.)
Heya,
Trying to use Mammoth in a Wordpress plugin by calling Mammoth from outside the context of the JS file you've provided in your Wordpress plugin.
Since I need to call the mammoth convert to HTML function in JS manually rather than attaching it to an event listener like you are I need the "mammoth" variable exposed outside the scope you have it in. I'm a bit stuch as to how to expose the scope, are you able to lend a hand at all or any advice?
docx looks good, I see w:val=center
But this config doesn't seem to be work
styleMap: [
"p[style-name='center'] => p:fresh > p:center",
...
Any idea what I'm doing wrong?
Hello. I tried installing mammoth, but I didn't succeeded. I tried typing
var mammoth = require("mammoth");
mammoth.convertToHtml({path: "E:\\Smartly.docx"})
.then(function(result){
var html = result.value; // The generated HTML
var messages = result.messages; // Any messages, such as warnings during conversion
console.log(html, message);
})
.fail(function(){
console.log('asdsad');
})
.done(function(){
console.log('please');
});
in a test.js file, but when I run it, it instantly closes and no error or message are returned. I'm sure file exists and it's a valid docx.
OS: NodeJs 32bit on Windows 7
Any ideas, why I cannot run it @mwilliamson?
Thanks.
If I wanted to pass mammoth.js a URL like "https://www.filepicker.io/api/file/ZE0lWtiRRmOHiiFs3EKd", can I do that directly? Or do I have to open the file then stream it to mammoth via:
function handleFileSelect(event) {
readFileInputEventAsArrayBuffer(event, function(arrayBuffer) {
mammoth.convertToHtml({arrayBuffer: arrayBuffer})
.then(displayResult)
.done();
});
}
var options = {
styleMap: "p[style-name='Section Title'] => h1:fresh\n" +
"p[style-name='Subsection Title'] => h2:fresh"
};
Will crash Mammoth
[2014-05-06 17:46:21.835] [ERROR] console - Error: Failed to parse: Line number: 1
Character number: 2:
Expected whitespace
but got unrecognisedCharacter "["
Note this is copy/pasted from docs
Hi Michael,
There is an error message showing up when I try to convert word 2013 doc to html :
TypeError: Cannot read property 'attributes' of undefined
on line var name = styleElement.first("w:name").attributes["w:val"]
inside the function readStyleElement( ), of lib/style-reader.js, [line-number: 39].
As the return of the statement styleElement.first("w:name") is undefined.
I guess the reason is the doc contains quite a lot of custom defined styles without naming. (The doc I used contains lots of images, custom styles and comments and so on.)
The way I fixed it is to make the style to 'Normal' if the element style is undefined:
var name;
try {
name = styleElement.first("w:name").attributes["w:val"];
}
catch(err){
name = 'Normal';
}
Not sure whether this is the ideal solution.
Any docs for how to support page breaks?
Right now we don't have any linkify/table of contents support, it'd be nice to have :)
Can only convert.Docx file,.Doc will make an error
This file can't be imported by mammoth, current .doc? I get nothing in value or messages ;\
var mammoth = require("mammoth");
console.log("foo");
mammoth.convertToHtml({path: "/home/jose/Downloads/testydoc.doc"})
.then(function(result){
var html = result.value; // The generated HTML
var messages = result.messages; // Any messages, such as warnings during conversion
console.log(result);
});
Hi, my npm i
is throwing an error
esprima-six has been deleted, but I didn't figure out which npm package depends on it
node v4.2.1
npm v3.3.12
Registry returned 404 for GET on https://registry.npmjs.org/esprima-six
Not working at all for me.. I hit up node test.js
var mammoth = require("mammoth");
mammoth.convertToHtml({path: "/home/jose/document.docx"})
.then(function(result){
console.log("HERE");
var html = result.value; // The generated HTML
var messages = result.messages; // Any messages, such as warnings during conversion
});
Node 0.10.4
jose@mint ~ $ node -v
v0.10.4
I get nothing back at all..
This is the file (ironically) https://www.wetransfer.com/downloads/6222de9055170a5099e48f0486d4d81e20131125205321/6854a035b1ce22a641b996840716ed8820131125205321/fb058b
Dear M. Williamson,
converting a text including some Soft Returns (Shift-Return)
the whole text between is not converted.
Do you have any idea?
Thank you.
Regards
Gerhard
I have the following in a text file:
p[style-name='Test Style'] => div.aside > h2:fresh
p[style-name='Test Style2'] => div.aside > p:fresh
p[style-name='Emphasis'] => div.aside > p:fresh
I'm running this from the command line using the '--style-map' flag pointed at the above file. The first two style rules take affect as expected. The third rule does nothing. The same goes for any of the built-in (pre-defined) Quick Styles in Word.
Hi. I've a question. I try do this:
function transformElement(element) {
if (element.children) {
element.children.forEach(transformElement);
}
if (element.type === "paragraph") {
if (element.alignment === "center" && !element.styleName) {
element.styleName = "Heading2";
} else if (element.alignment === "right" && !element.styleName) {
// how create a <p align="right">some text</p>
}
}
return element;
}
I have not tested all options, but it seems if you have a document that was originally a .doc file, or possibly you've created a docx file using the compatibility pack on an older version of word and saved as .docx, the hyperlink shows up in the xml in a strange and unsupported format.
Here is an example of such a case:
<w:r w:rsidR="00B47673" w:rsidRPr="00B47673">
<w:rPr>
<w:rFonts w:ascii="Calibri" w:hAnsi="Calibri"/>
<w:color w:val="0563C1"/>
<w:sz w:val="22"/>
<w:szCs w:val="22"/>
<w:u w:val="single"/>
<w:lang w:val="de-DE" w:eastAsia="en-US"/>
<w:rPrChange w:id="11" w:author="author, awesome" w:date="2015-07-16T18:31:00Z">
<w:rPr>
<w:rFonts w:ascii="Calibri" w:hAnsi="Calibri"/>
<w:color w:val="0563C1"/>
<w:sz w:val="22"/>
<w:szCs w:val="22"/>
<w:u w:val="single"/>
<w:lang w:eastAsia="en-US"/>
</w:rPr>
</w:rPrChange>
</w:rPr>
<w:instrText xml:space="preserve"> HYPERLINK "http://someawesomelink.com" </w:instrText>
</w:r>
<w:r w:rsidR="00B47673" w:rsidRPr="00B47673">
<w:rPr>
<w:rFonts w:ascii="Calibri" w:hAnsi="Calibri"/>
<w:color w:val="0563C1"/>
<w:sz w:val="22"/>
<w:szCs w:val="22"/>
<w:u w:val="single"/>
<w:lang w:eastAsia="en-US"/>
</w:rPr>
<w:fldChar w:fldCharType="separate"/>
</w:r>
<w:r w:rsidR="00B47673" w:rsidRPr="00B47673">
<w:rPr>
<w:rFonts w:ascii="Calibri" w:hAnsi="Calibri"/>
<w:color w:val="0563C1"/>
<w:sz w:val="22"/>
<w:szCs w:val="22"/>
<w:u w:val="single"/>
<w:lang w:val="de-DE" w:eastAsia="en-US"/>
<w:rPrChange w:id="12" w:author="author, awesome" w:date="2015-07-16T18:31:00Z">
<w:rPr>
<w:rFonts w:ascii="Calibri" w:hAnsi="Calibri"/>
<w:color w:val="0563C1"/>
<w:sz w:val="22"/>
<w:szCs w:val="22"/>
<w:u w:val="single"/>
<w:lang w:eastAsia="en-US"/>
</w:rPr>
</w:rPrChange>
</w:rPr>
<w:t>http://someawesomelink.com</w:t>
</w:r>
As you can see, this format greatly differs from the current hyperlink tag structure and becomes somewhat more difficult to parse. Our current solution is to have document creators copy and paste document data from these broken documents into a brand new Word 2010+ docx file and use that (which works great).
I just wanted to raise awareness of this issue so that others could find a solution instead of potential "hyperlinks don't work!!!" issues being raised - when they definitely do.
Originally raised on the WordPress plugin: https://wordpress.org/support/topic/some-images-dont-uploadimport-correctly
Adding EMF support in JavaScript may be tricky, but at the very least we can spit out a message explaining why the image won't display properly.
Hi!
I'm trying to make this lib work with a .doc file. I'm not sure if it does at all since it never throws any kind of error, or warning or any message.
I'm intrigued since this could solve and save me a lot of issues in a project I'm currently working at.
I've had to place some console.log
s around, and it seems to reach to this point... But I can't make the README.md
's example to work or return anything at all.
Any idea why?
Hi again. I realized another question I had: some of the data for identifying what information pertains to the content in my DOCX files is included in its alignment.
That is, per my previous issue, I have subsection titles that appear in bold.. but I actually have supersections that group subsections, that appear in bold, all-caps, and centered. The "centered" part is really the key, here.
Is it possible to target center-aligned content with a specific style somehow? Is there a way that I can target other non-class styles (bold, italic) when mapping? I know Mammoth by default correctly maps those to the appropriate HTML tags (<strong>
, for instance), but it's unclear by what mechanism this is achieved and whether we can write our own styles to do this.
Thanks so much!
Hi, thanks again for all the help last month.
Recently I've found that Mammoth is failing silently on a handful of my documents seemingly when it encounters images.
I've got my mammoth.convertToHtml({path: fileName}, options).then(function(result) { ... }
going on, but I never get to the .then portion.
Digging into the code, everything is hunky-dory; the documentConverter is running elementToHtml (document-to-html.js, line 34) on all the elements. At some point it finds an image and sends it to handler defaultConvertImage
(line 98), which does element.read("base64").then(function(imagebuffer) { ... }
but this is the first place I find where "then" never comes.
Any ideas?
I am using mammoth in a nodejs/expressjs app, and this is what i have:
app.post "/upload", (req, res, next) ->
docfile = req.files.files[0]
result = mammoth.convertToHtml({path: docfile.path})
html = result.value
console.log html
console.log result.messages
I get both html and messages as undefined, i also tried writing the file using 'fs' , with its name, and then tried to do this, still undefined. Any idea what could be wrong?
Thanks!
To replicate:
Expected output: <h1>Test</h1>
Actual output.. Not above...
I'm gonna assume this is a libreoffice issue.. The docuemt XML looks like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"><w:body><w:p><w:pPr><w:pStyle w:val="style1"/><w:numPr><w:ilvl w:val="0"/><w:numId w:val="1"/></w:numPr><w:spacing w:after="120" w:before="240"/></w:pPr><w:r><w:rPr></w:rPr><w:t>Blah</w:t></w:r></w:p><w:p><w:pPr><w:pStyle w:val="style0"/></w:pPr><w:r><w:rPr><w:sz w:val="32"/><w:szCs w:val="32"/></w:rPr><w:t>Test</w:t></w:r></w:p><w:p><w:pPr><w:pStyle w:val="style0"/></w:pPr><w:r><w:rPr></w:rPr></w:r></w:p><w:sectPr><w:type w:val="nextPage"/><w:pgSz w:h="16838" w:w="11906"/><w:pgMar w:bottom="1134" w:footer="0" w:gutter="0" w:header="0" w:left="1134" w:right="1134" w:top="1134"/><w:pgNumType w:fmt="decimal"/><w:formProt w:val="false"/><w:textDirection w:val="lrTb"/></w:sectPr></w:body></w:document>
styles like this:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:styles xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:style w:styleId="style0" w:type="paragraph"><w:name w:val="Normal"/><w:next w:val="style0"/><w:pPr><w:widowControl w:val="false"/><w:tabs><w:tab w:leader="none" w:pos="709" w:val="left"/></w:tabs><w:suppressAutoHyphens w:val="true"/><w:kinsoku w:val="true"/><w:overflowPunct w:val="true"/><w:autoSpaceDE w:val="true"/></w:pPr><w:rPr><w:rFonts w:ascii="Times New Roman" w:cs="Lohit Hindi" w:eastAsia="Droid Sans" w:hAnsi="Times New Roman"/><w:color w:val="auto"/><w:sz w:val="24"/><w:szCs w:val="24"/><w:lang w:bidi="hi-IN" w:eastAsia="zh-CN" w:val="en-GB"/></w:rPr></w:style><w:style w:styleId="style1" w:type="paragraph"><w:name w:val="Heading 1"/><w:basedOn w:val="style15"/><w:next w:val="style16"/><w:pPr><w:numPr><w:ilvl w:val="0"/><w:numId w:val="1"/></w:numPr><w:outlineLvl w:val="0"/></w:pPr><w:rPr><w:b/><w:bCs/><w:sz w:val="32"/><w:szCs w:val="32"/></w:rPr></w:style><w:style w:styleId="style15" w:type="paragraph"><w:name w:val="Heading"/><w:basedOn w:val="style0"/><w:next w:val="style16"/><w:pPr><w:keepNext/><w:spacing w:after="120" w:before="240"/></w:pPr><w:rPr><w:rFonts w:ascii="Arial" w:cs="Lohit Hindi" w:eastAsia="Droid Sans" w:hAnsi="Arial"/><w:sz w:val="28"/><w:szCs w:val="28"/></w:rPr></w:style><w:style w:styleId="style16" w:type="paragraph"><w:name w:val="Text body"/><w:basedOn w:val="style0"/><w:next w:val="style16"/><w:pPr><w:spacing w:after="120" w:before="0"/></w:pPr><w:rPr></w:rPr></w:style><w:style w:styleId="style17" w:type="paragraph"><w:name w:val="List"/><w:basedOn w:val="style16"/><w:next w:val="style17"/><w:pPr></w:pPr><w:rPr><w:rFonts w:cs="Lohit Hindi"/></w:rPr></w:style><w:style w:styleId="style18" w:type="paragraph"><w:name w:val="Caption"/><w:basedOn w:val="style0"/><w:next w:val="style18"/><w:pPr><w:suppressLineNumbers/><w:spacing w:after="120" w:before="120"/></w:pPr><w:rPr><w:rFonts w:cs="Lohit Hindi"/><w:i/><w:iCs/><w:sz w:val="24"/><w:szCs w:val="24"/></w:rPr></w:style><w:style w:styleId="style19" w:type="paragraph"><w:name w:val="Index"/><w:basedOn w:val="style0"/><w:next w:val="style19"/><w:pPr><w:suppressLineNumbers/></w:pPr><w:rPr><w:rFonts w:cs="Lohit Hindi"/></w:rPr></w:style></w:styles>
Trying...
var options = {
styleMap: [
styleMapping("p.Heading1 => h1:fresh"),
styleMapping("Heading 1 => h1:fresh")
]
};
Returns
[2014-03-14 00:43:11.007] [ERROR] console - Error: Failed to parse: Line number: 1
Character number: 1:
Expected p or r
but got identifier "Heading"
at parseString (/home/jose/2dots/node_modules/ep_mammoth/node_modules/mammoth/lib/style-reader.js:163:15)
So maybe this is actually an issue that style types with "spaces" can't be parsed?
Hi,
I'm trying to get a custom image converter working, but it does not seem to get called. I'm trying to write the image out to a file. If I also change the return src to be "dataxxxxxxxx", the resulting output still just shows "data:"
Here is my code. Any thoughts would be appreciated.
var options = {
path: dir + "/sig.docx",
convertImage: mammoth.images.inline(function(element) {
return element.read("base64").then(function(imageBuffer) {
fs.writeFile(dir + "/image.jpg", imageBuffer, function(err) {
if(err) {
console.log(err);
} else {
console.log("The file was saved!");
}
});
return {
src: "dataxxxxxxx:" + element.contentType + ";base64," + imageBuffer
};
});
})
};
mammoth.convertToHtml(options).....
Thanks
Gary.
Mammoth reads out normal links just fine:
<w:hyperlink r:id="rId8" w:history="1">
<w:r w:rsidRPr="00F36DC1">
<w:rPr>
<w:rStyle w:val="Hyperlink"/>
</w:rPr>
<w:t>www.someurl.com</w:t>
</w:r>
</w:hyperlink>
becomes
<a href="www.someurl.com">www.someurl.com</a>
But if the document links to an anchor ("places in this in document" from the link tab) instead, it gets ignored entirely:
<w:hyperlink w:anchor="_Main_Heading" w:history="1">
<w:r w:rsidRPr="00C57019">
<w:rPr>
<w:rStyle w:val="Hyperlink"/>
</w:rPr>
<w:t>Click Me</w:t>
</w:r>
</w:hyperlink>
...
<w:bookmarkStart w:id="1" w:name="_Main_Heading"/>
<w:bookmarkEnd w:id="1"/>
becomes
<p>Click me</p>
Instead, you would probably want
<p><a href="#_Main_Heading">Click Me</a></p>
...
<span id="_Main_Heading"></span>
Is this something you have on your roadmap/how can I help to get this feature in? :)
After converting a few documents I found that the tables that are present in the word are not recognised. So I looked at the document.xml of a sample docx file but couldn't make out any patterns as to how does it represent the data. Here is 3*3 table in docx.
So is there any way of figuring out what data does it convey and converting them into normal html tables.
P.S. Thank you so much for the creating mammoth.js.
First off... this is an awesome project! You've all done an amazing job with this!
The biggest hurdle I am facing right now is that the files I am provided have "Chart Areas". Is there any way to convert these areas to images?
Thanks again!
Hi Michael, would be it possible to wrap the result to the real HTML document, with doctype
, html
, body
? Also it would be nice to have <meta charset="UTF-8">
in head
element.
Thanks
Thanks for this module, I am finding it very useful.
Right now w:tab is not handled and shows up as an error when parsing.
Add a w:tab property to xmlElementReaders in document-xml-reader.js.
I'm trying to use Mammoth.js in a web worker by importing it using "importScripts". The error I get, when doing this is: "Uncaught TypeError: Cannot read property 'MutationObserver' of undefined". When I load mammoth.browser.min.js in the browser I get no such error. The error is thrown immediately after importScripts is run. Any ideas? Thank you.
As a first pass, always using the fallback elment seems like the simplest option.
Latest npm version, I'm really confused 📦
I get mammoth.styleMapping is undefined using example code.
{ Converter: [Function: Converter],
convertToHtml: [Function: convertToHtml],
read: [Function: read],
convertDocumentToHtml: [Function: convertDocumentToHtml],
htmlPaths:
{ topLevelElement: [Function: topLevelElement],
elements: [Function: elements],
element: [Function: element] },
style: [Function: readStyle],
standardOptions:
{ styleMap:
[ [Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object],
[Object] ] } }
I know this goes somewhat against the philosophy of mammoth, but in my testing with users I've had many complaints about the loss of font color, typeface, and size when importing documents. It seems the way to address this while preserving compliant HTML would be to add classes for these attributes that correspond to the underlying Word markup.
For example, this block of XML from Word is size 16 red font (standard typeface).
<w:p w:rsidR="00A0306C" w:rsidRDefault="001545AB">
<w:pPr>
<w:rPr>
<w:color w:val="FF0000"/>
<w:sz w:val="32"/>
<w:szCs w:val="32"/>
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:color w:val="FF0000"/>
<w:sz w:val="32"/>
<w:szCs w:val="32"/>
</w:rPr>
<w:t>Size 16 red!</w:t>
</w:r>
</w:p>
It would be great if it could be converted to classes, perhaps by concatenating the parameter and value, like
<p class="sz32 colorFF0000">Size 16 red!</p>
Then it's up to the developer/designer to decide how to handle the classes in the HTML (if at all).
I could attempt this myself if someone could point me in the right direction, but unfortunately large segments of mammoth's codebase are beyond my current level of understanding.
Hi again! I'm opening this issue to reiterate my compliments what I understand as yor on your line of thinking (which you seemed to confirm in concept in response to my comment on another issue.
I like the concept of converting .docx to HTML with a focus on the styles used in the .docx file. I see some real utility in that, and your comments seem to confirm that as an objective in this project.
As noted, I'm on the learning curve (for a lot things). But at some point, I'll look at your work more closely and probably even try and dig in.
Until then, I'll observe from a distance but with interest. I just openned an issue to establish communication, and extend compliments ... hopefully a contribution in spirit. Cheers.
Works fine with node 0.11.4
Broken in node 0.11.5+
No errors etc..
Also CLI documentation a little sketchy, I don't get a CLI command at all so not sure what's going on, prolly needs a sep issue for this..
Hi,
I think Mammoth is great, but I've got some very odd issues.
My need is to convert a .DOCX file with lines of bold text acting as headers separating paragraphs of plaintext. It might look like this:
A Section
Here is a piece of text about France's President, a man admired by many.
Another Section
This section is about an insurrection taking place in Bolivia.
The Last Section
I love Mammoth. I want to use it.
When I pass this docx through Mammoth's convertToHtml method (via a node.js script),
I find that the results are oddly unreliable. It might look like this:
<bold>A Section</bold>
<p>Here is a piece of text about 's President, a man admired by many.</p>
<p>This section is about an insurrection taking place in .</p>
<bold>The Last Section</bold>
I love Mammoth. I want to use it.
As you can see, some words from the paragraph texts are just missing, and (in this example) one of the headings is missing. The missing words are frequently proper nouns and things, which leads me to believe that the original authors of the docx file may have pasted them from somewhere else, and perhaps this has created hidden markup that results in its disappearance from the end result?
The other thing to note is that these files were originally .DOC files which I saved-as to .DOCX files. In the future my organization will be using only .DOCX files, but this is all I have to test on.
It's unclear how I might be able to debug this. The documentation unfortunately isn't clear on how to target plain, but bold, paragraph text. I extracted the .docx file as if it was a .zip file and examined the document.xml file within, and was able to see all the content that ends up disappearing in the output, but the XML is so obtuse it's unclear what could be going wrong.
Any ideas?
If you copy the following text into a .docx file and try to convert it, there is a "Maximum Call Stack Exceeded" error.
૱ Ă ă 0 1 2 3 4 5 6 7 8 9 Ǖ ǖ ¤ Ð ¢ ℥ Ω ℧ K ℶ ℷ ℸ ⅇ ⅊ ᶀ ᶁ ᶂ ᶃ ᶄ ᶆ ᶇ ᶈ ᶉ ᶊ ᶋ ᶌ ᶍ ᶎ ᶏ ᶐ ᶑ ᶒ ᶓ ᶔ ᶕ ᶖ ᶗ ᶘ ᶙ ᶚ ᶸ ᵯ ᵰ ᵴ ᵶ ᵹ ᵼ ᵽ ᵾ ᵿ ¥ £ ⅕ ⅙ ⅛ ⅔ ⅖ ⅗ ⅘ ⅜ ⅚ ⅝ ⅓ ⅞⍳ ⍴ ⍵ ⍶ ⍷ ⍸ ⍹ ⍺ » ‹ › ‘ ’ “ ” „ ‚ ❝ ❞ £ ¥ € $ ¢ ¬ ¶ @ § ® © ™ ° × π ± √ ‰ Ω ∞ ≈ ÷ ~ ≠ ¹ ² ³ ½ ¼ ¾ ‐ – — | ⁄ \ [ ] { } † ‡ … • • ● ⌃ ⇧↩ ¡ ¿ ‽α ß Á á À à Å å Ä ä Æ æ Ç ç É é È è Ê ê Í í Ì ì Î î Ñ ñ Ó ó Ò ò Ô ô Ö ö Ø ø Ú ú Ù ù Ü ü Ž ž ₳ ฿ ¢ € ₡ ¢ ₢ ₵ ₫ £ £ ₤ ₣ ƒ ₲ ₭ ₥ ₦ ₱ $ $ ₮ ₩ ₩ ¥ ¥ ₴ ₰ ¤ ៛ ₪ ₯ ₠ ₧ ₨ ௹ ﷼ ㍐ ৲ ৳ ~ ƻ Ƽ ƽ ¹ ¸ ¬ ¨ ɂ ǁ ¯ Ɂ ǂ ¡ ´ ° ¦ } { | . , • ] ) [ / _ \ ¿ º § " * - + ( ! & % $ ¼ ¾ ½ ¶ © ® @ ` ^ ꜠ ꜡ ' = : ; < ꞌ Ꞌ ꞊ ꞈ ꞉ > ? ÷ ℾ ℿ ℔ ℩ ℉ ⅀ ℈ þ ð Þ µ ª ⱷ ⱶ Ⱶ ⱴ ⱱ ⱦ ȶ ȴ ȣ Ȣ ȡ ȝ Ȝ ț ȋ Ȋ ȉ Ȉ ǯ Ǯ ǃ ǀ ƿ ƾ ƺ ƹ Ƹ Ʒ Ʋ ư ƪ ƣ Ƣ Ɵ ƛ Ɩ ƕ ƍ ſ ₯ ἀ ἁ ἂ ἃ ἄ ἅ ἆ ἇ Ἀ Ἁ Ἂ Ἃ Ἄ Ἅ Ἆ Ἇ ἐ ἑ ἒ ἓ ἔ ἕ Ἐ Ἑ Ἒ Ἓ Ἔ Ἕ ἠ ἡ ἢ ἣ ἤ ἥ ἦ ἧ Ἠ Ἡ Ἢ Ἣ Ἤ Ἥ Ἦ Ἧ ἰ ἱ ἲ ἳ ἴ ἵ ἶ ἷ Ἰ Ἱ Ἲ Ἳ Ἴ Ἵ Ἶ Ἷ ὀ ὁ ὂ ὃ ὄ ὅ Ὀ Ὁ Ὂ Ὃ Ὄ Ὅ ὐ ὑ ὒ ὓ ὔ ὕ ὖ ὗ Ὑ Ὓ Ὕ Ὗ ὠ ὡ ὢ ὣ ὤ ὥ ὦ ὧ Ὠ Ὡ Ὢ Ὣ Ὤ Ὥ Ὦ Ὧ ὰ ά ὲ έ ὴ ή ὶ ί ὸ ό ὺ ύ ὼ ώ ᾀ ᾁ ᾂ ᾃ ᾄ ᾅ ᾆ ᾇ ᾈ ᾉ ᾊ ᾋ ᾌ ᾍ ᾎ ᾏ ᾐ ᾑ ᾒ ᾓ ᾔ ᾕ ᾖ ᾗ ᾘ ᾙ ᾚ ᾛ ᾜ ᾝ ᾞ ᾟ ᾠ ᾡ ᾢ ᾣ ᾤ ᾥ ᾦ ᾧ ᾨ ᾩ ᾪ ᾫ ᾬ ᾭ ᾮ ᾯ ᾰ ᾱ ᾲ ᾳ ᾴ ᾶ ᾷ Ᾰ Ᾱ Ὰ Ά ᾼ ᾽ ι ᾿ ῀ ῁ ῂ ῃ ῄ ῆ ῇ Ὲ Έ Ὴ Ή ῌ ῍ ῎ ῏ ῐ ῑ ῒ ΐ ῖ ῗ Ῐ Ῑ Ὶ Ί ῝ ῞ ῟ ῠ ῡ ῢ ΰ ῤ ῥ ῦ ῧ Ῠ Ῡ Ὺ Ύ Ῥ ῭ ΅ ` ῲ ῳ ῴ ῶ ῷ Ὸ Ό Ὼ Ώ ῼ ´ ῾ ʹ ͵ ͺ ͻ ͼ ͽ ; ΄ ΅ Ά · Έ Ή Ί Ό Ύ Ώ ΐ Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο Π Ρ Σ Τ Υ Φ Χ Ψ Ω Ϊ Ϋ ά έ ή ί ΰ α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ ς σ τ υ φ χ ψ ω ϊ ϋ ό ύ ώ ϐ ϑ ϒ ϓ ϔ ϕ ϖ ϗ Ϙ ϙ Ϛ ϛ Ϝ ϝ Ϟ ϟ Ϡ ϡ Ϣ ϣ Ϥ ϥ Ϧ ϧ Ϩ ϩ Ϫ ϫ Ϭ ϭ Ϯ ϯ ϰ ϱ ϲ ϳ ϴ ϵ ϶ Ϸ ϸ Ϲ Ϻ ϻ ϼ Ͻ Ͼ Ͽ A a Ạ ạ Ả ả Ḁ ḁ  à Ǎ ǎ Ấ ấ Ầ ầ Ẩ ẩ Ȃ ȃ Ẫ ẫ Ậ ậ À Á Ắ ắ Ằ ằ Ẳ ẳ Ẵ ẵ Ặ ặ Ā ā Ą ą Ǟ Ȁ ȁ Å Ǻ ǻ Ä ä ǟ Ǡ ǡ â á å ã à ẚ Ȧ ȧ Ⱥ Å ⱥ Æ æ Ǽ Ǣ ǣ Ɑ ª ℀ ⅍ ℁ B b Ḃ ḃ Ḅ ḅ Ḇ ḇ Ɓ Ƀ ƀ ƃ Ƃ Ƅ ƅ ℬ C c Ḉ ḉ Ć ć Ĉ ĉ Ċ ċ Č č Ç ç Ƈ ƈ Ȼ ȼ ℂ ℃ ℭ Ɔ ℅ ℆ ℄ D d Ḋ ḋ Ḍ ḍ Ḏ ḏ Ḑ ḑ Ḓ ḓ Ď ď Ɗ Ƌ ƌ Ɖ Đ đ ȡ DZ Dz dz DŽ Dž dž ȸ E e Ḕ ḕ Ḗ ḗ Ḙ ḙ Ḛ ḛ Ḝ ḝ Ẹ ẹ Ẻ ẻ Ế ế Ẽ ẽ Ề ề Ể ể Ễ ễ Ệ ệ Ē ē Ĕ ĕ Ė ė Ę ę Ě ě È è É é Ê ê Ë ë Ȅ ȅ Ȩ ȩ Ȇ ȇ Ǝ Ɇ ℇ ℯ ℮ Ɛ ℰ Ə ǝ ɇ F f Ḟ ḟ Ƒ ƒ Ⅎ ⅎ ℱ G g Ɠ Ḡ ḡ Ĝ ĝ Ğ ğ Ġ ġ Ģ ģ Ǥ ǥ Ǧ ǧ Ǵ ℊ ⅁ ǵ H h Ḣ ḣ Ḥ ḥ Ḧ ḧ Ḩ ḩ Ḫ ḫ ẖ Ĥ ĥ Ȟ ȟ Ħ ħ Ⱨ ⱨ Ƕ ℏ ℎ ℋ ℌ I i Ḭ ḭ Ḯ ḯ IJ ij ì í î ï Ì Í Î Ï Ĩ ĩ Ī ī Ĭ ĭ Į į ı Ɨ ƚ Ǐ ǐ ℹ ℑ ℐ J j Ĵ ĵ ȷ Ɉ ɉ ǰ K k Ḱ ḱ Ḳ ḳ Ḵ ḵ Ķ ķ Ƙ ƙ Ǩ ǩ Ⱪ ⱪ ĸ L l Ḷ ḷ Ḹ ḹ Ḻ ḻ Ḽ ḽ Ĺ ĺ Ļ ļ Ľ İ ľ Ŀ ŀ Ł ł Ỉ ỉ Ị ị Ƚ Ⱡ ⱡ Ɫ ℒ LJ Lj lj ⅃ ⅂ ℓ ȉ Ȉ Ȋ ȋ M m Ḿ ḿ Ṁ ṁ Ṃ ṃ Ʃ Ɯ ℳ N n Ṅ ṅ Ṇ ṇ Ṉ ṉ Ṋ ṋ Ń ń Ņ ņ Ň ň Ǹ ǹ Ŋ Ɲ ñ ʼn Ñ Ƞ ƞ ŋ NJ Nj nj ȵ № O o Ṍ ṍ Ṏ ṏ Ṑ ṑ Ṓ ṓ Ȫ ȫ Ȭ ȭ Ȯ ȯ Ȱ ȱ Ǫ ǫ Ǭ ǭ Ọ ọ Ỏ ỏ Ố ố Ồ ồ Ổ ổ Ỗ ỗ Ộ ộ Ớ ớ Ờ ờ Ở ở Ỡ ỡ Ợ ợ Ơ ơ Ō ō Ŏ ŏ Ő ő Ò Ó Ô Õ Ö Ǒ Ȍ ȍ Ȏ ȏ Œ œ Ø Ǿ ǽ ǿ ℴ ⍥ ⍤ ò ó ô õ ö ǒ ø P p Ṕ ṕ Ṗ ṗ Ƥ ƥ Ᵽ ℙ Ƿ ℘ Q q Ɋ ɋ ℚ ℺ ȹ R r Ŕ ŕ Ŗ ŗ Ř ř Ṙ ṙ Ṛ ṛ Ṝ ṝ Ṟ ṟ Ȑ ȑ Ȓ ȓ ɍ Ɍ Ʀ Ɽ ℞ ℜ ℛ ℟ S s Ṡ ṡ Ṣ ṣ Ṥ ṥ Ṧ ṧ Ṩ ṩ Ś ś Ŝ ŝ Ş ş Š š Ș ș ȿ Ƨ ƨ ẞ ß ẛ ℠ T t Ṫ ṫ Ṭ ṭ Ṯ ṯ Ṱ ṱ Ţ ţ Ť ť Ŧ ŧ Ƭ Ʈ ẗ Ț Ⱦ ƫ ƭ ț ⱦ ȶ ™ U u Ṳ ṳ Ṵ ṵ Ṷ ṷ Ṹ ṹ Ṻ ṻ Ụ Ủ ủ Ứ Ừ ụ ứ Ử ử ừ ữ Ữ Ự ự Ũ ũ Ū ū Ŭ ŭ Ů ů Ű ű Ǚ ǚ Ǘ ǘ Ǜ ǜ Ų ų Ǔ ǔ Ȕ ȕ Û û Ȗ ȗ Ù ù Ü ü Ư ú Ʉ ư Ʋ Ʊ V v Ṽ ṽ Ṿ ṿ Ʌ ℣ ⱱ ⱴ W w Ẁ ẁ Ẃ ẃ Ẅ ẅ Ẇ ẇ Ẉ ẉ Ŵ ŵ ẘ Ⱳ ⱳ X x Ẋ ẋ Ẍ ẍ ℵ × y Y Ẏẏ ẙ Ỳ ỳ Ỵ ỵ Ỷ ỷ Ỹ ỹ Ŷ ŷ Ƴ ƴ Ÿ ÿ Ý ý Ɏ ɏ Ȳ Ɣ ⅄ ȳ Z z Ẑ ẑ Ẓ ẓ Ẕ ẕ Ź ź Ż ż Ž ž Ȥ ȥ Ⱬ ⱬ Ƶ ƶ ɀ ℨ ℤ ∀ ∁ ∂ ∃ ∄ ∅ ∆ ∇ ∈ ∉ ∊ ∋ ∌ ∍ ∏ ∐ ∑ ⋲ ⋳ ⋴ ⋵ ⋶ ⋷ ⋸ ⋹ ⋺ ⋻ ⋼ ⋽ ⋾ ⋿ € ₤ $ Ω β Φ Σ Ξᶛ ᶜ ᶝ ᶞ ᶟ ᶠ ᶡ ᶢ ᶣ ᶤ ᶥ ᶦ ᶧ ᶨ ᶩ ᶪ ᶫ ᶬ ᶭ ᶮ ᶯ ᶰ ᶱ ᶲ ᶳ ᶴ ᶵ ᶶ ᶷ ᶹ ᶺ ᶻ ᶼ ᶽ ᶾ ᶿ ᴀ ᴁ ᴂ ᴃ ᴄ ᴅ ᴆ ᴇ ᴈ ᴉ ᴊ ᴋ ᴌ ᴍ ᴎ ᴏ ᴐ ᴑ ᴒ ᴓ ᴔ ᴕ ᴖ ᴗ ᴘ ᴙ ᴚ ᴛ ᴜ ᴝ ᴞ ᴟ ᴠ ᴡ ᴢ ᴣ ᴤ ᴥ ᴦ ᴧ ᴨ ᴩ ᴪ ᴫ ᴬ ᴭ ᴮ ᴯ ᴰ ᴱ ᴲ ᴳ ᴴ ᴵ ᴶ ᴷ ᴸ ᴹ ᴺ ᴻ ᴼ ᴽ ᴾ ᴿ ᵀ ᵁ ᵂ ᵃ ᵄ ᵅ ᵆ ᵇ ᵈ ᵉ ᵊ ᵋ ᵌ ᵍ ᵎ ᵏ ᵐ ᵑ ᵒ ᵓ ᵔ ᵕ ᵖ ᵗ ᵘ ᵙ ᵚ ᵛ ᵜ ᵝ ᵞ ᵟ ᵠ ᵡ ᵢ ᵣ ᵤ ᵥ ᵦ ᵧ ᵨ ᵩ ᵪ ᵫ ᵬ ᵭ ᵮ ᵱ ᵲ ᵳ ᵵ ᵷ ᵸ ᵺ ᵻ ‘ ’ ‛ ‚ “ ” „ ‟ « » ‹ › Ꞌ " ❛ ❜ ❝ ❞ < > @ ‧ ¨ ․ ꞉ : ⁞ ‥ … ; ― _ ¬ / \ ⁄ \ ⁄ | ⎜ ¦ ‖ ‗ † ‡ • • ° ‣ % ‰ ‱ & ⅋ § ÷ + ± = ꞊ ′ ″ ‴ ⁗ ‵ ‶ ‷ ‸ * ⁑ ! ‼ ¡ ? ¿ ⁇ ⁉ ⁈ ‽ ¼ ½ ¾ ² ³ © ® ™ ℠ ℅ ℁ ⅍ ℄
Not sure how difficult that is, but i think it might make a good addition.
There are a few huge Errors. For once, it does not keep up the document structure.
Second, it can not display textboxes.
Third, if a picture-type like emf or svg is present in the word document, there should be something like a conversion so that browsers can show it as well.
A sample file would be here: https://www.dropbox.com/s/pqux3oqq3z7lw8m/Dok1.docx?dl=0
Tested on the actual version of mammoth, Windows 7 64-Bit, actual NodeJS Version
Dear,
I always get an error message like this
npm ERR! fetch failed http://registry.npmjs.org/jszip/-/jszip-2.2.2.tgz
if I try to do an npm install with
[...]
"mammoth": "^0.3.14",
[...]
Can you please investigate and fix?
Regards,
Christian
As per title
Hi I've been really enjoying using Mammoth (I even sent an email with words to that effect a few months ago), but I'm having an issue with the run styles. See below:
With this XML:
<w:r w:rsidRPr="00B803E3">
<w:rPr>
<w:rStyle w:val="X-reference"/>
</w:rPr>
<w:t xml:space="preserve">Figure </w:t>
</w:r>
<w:r w:rsidR="00BA54E2">
<w:rPr>
<w:rStyle w:val="X-reference"/>
</w:rPr>
<w:t>3.1</w:t>
</w:r>
This style map (I've tried :fresh too): r[style-name='X-reference'] => span.X-reference
I'm getting this HTML
<span class="X-reference">Figure </span>
<span class="X-reference">3.1</span>
Ideally it would just be
<span class="X-reference">Figure 3.1</span>
I can see why I am getting the two <span>
elements as there are two XML <w:r>
elements. Having one <span>
element instead of two would be ideal though.
Is this a bug with Mammoth, or am I using it incorrectly?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.