Open mdorazio opened 9 years ago
The best way of dealing with this in Mammoth is to use document transforms, which allow you to add styles to paragraphs and runs based on their properties. I think the only thing stopping you from doing so is that the docx reader ignores some of the properties you want to use, such as colour and size, so taking a look at how document.xml
is parsed is probably a good place to start.
One potential solution is to give access to the rest of the xml properties that are currently ignored by the docx reader, and use them to apply custom styles as needed. This opens up a lot of possibilities like auto-detecting style types in documents without style names in the xml. see pull request #75
@mwilliamson Hi Michael, do you think you will work on including size and color in the docx reader? I'd love to be able to convert headings based on file size.
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).
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.