mwilliamson / python-mammoth

Convert Word documents (.docx files) to HTML
BSD 2-Clause "Simplified" License
811 stars 121 forks source link

Map to custom CSS? #85

Closed navarretedaniel closed 4 years ago

navarretedaniel commented 4 years ago

I have many custom Word styles that I would like to map to a custom CSS file.

For example:

My INDENT_2_TEXT CSS style is as follows:

p.WD_INDENT_2_TEXT{
    margin-top: 0in;
    margin-right: 0in;
    margin-bottom: 12.0pt;
    margin-left: 1.25in;
    text-indent: -.5in;
    font-size: 11.0pt;
    font-family: "Times New Roman", serif;
    font-weight: bold;
    text-decoration: underline;
}

I'm unclear whether this is possible? If it is, how do I link my CSS stylesheet?

Thank you.

mwilliamson commented 4 years ago

You'll need to include the HTML generated by Mammoth within a document that includes a stylesheet with that class defined.

navarretedaniel commented 4 years ago

Appreciate the quick response; I just wasn't sure whether this was an option when using the CLI functionality mammoth document.docx output.html --style-map=custom-style-map as it automatically creates the HTML document with <html>, <head>, and <body> tags.

Easy enough to do outside the CLI.

Thank you for clarifying.

mwilliamson commented 4 years ago

Mammoth doesn't create the <html>, <head> and <body> tags, just the HTML fragment for the document. If you're opening the fragment in a browser, the browser will automatically add in those elements to the DOM, but they shouldn't be in the actual HTML file.