You can add more HTML tags in the generated HTML code and check the rendering.
Word Into HTML is designed to convert .docx documents, such as those created by Microsoft Word, Google Docs and LibreOffice, and convert them to HTML. Word Into HTML aims to produce simple and clean HTML by using semantic information in the document, and ignoring other details. For instance, Word Into HTML converts any paragraph with the style Heading 1 to h1 elements, rather than attempting to exactly copy the styling (font, text size, colour, etc.) of the heading.
There's a large mismatch between the structure used by .docx and the structure of HTML, meaning that the conversion is unlikely to be perfect for more complicated documents. Word Into HTML works best if you only use styles to semantically mark up your document.
The following features are currently supported:
You can convert docx files by passing the path to the docx file and the output file.
If no output file is specified, output is written to stdout instead.
The output is an HTML fragment, rather than a full HTML document, encoded with UTF-8. Since the encoding is not explicitly set in the fragment, opening the output file in a web browser may cause Unicode characters to be rendered incorrectly if the browser doesn't default to UTF-8.
By default, images are included inline in the output HTML.
A custom style map can be read from a file. For instance:
Markdown support is deprecated.
To convert an existing .docx file to HTML be sure that your file is an authentic docx and not corrupted
By default, this tool maps some common .docx styles to HTML elements. For instance, a paragraph with the style name Heading 1 is converted to a h1 element. For instance, paragraphs with the style name Section Title should be converted to h1 elements, and paragraphs with the style name Subsection Title should be converted to h2 elements.
By default, images are converted to <img> elements with the source included inline in the src attribute.
By default, bold text is wrapped in <strong> tags.
By default, italic text is wrapped in <em> tags.
By default, the underlining of any text is ignored since underlining can be confused with links in HTML documents.
By default, strikethrough text is wrapped in <s> tags.
By default, comments are ignored. To include comments in the generated HTML.
Comments will be appended to the end of the document, with links to the comments wrapped using the specified style mapping.
A style map is made up of a number of style mappings separated by new lines. Blank lines and lines starting with # are ignored.
A style mapping has two parts:
When converting each paragraph, this tool finds the first style mapping where the document element matcher matches the current paragraph. Word Into HTML then ensures the HTML path is satisfied.
When writing style mappings, it's helpful to understand Word Into HTML's notion of freshness. When generating, Word Into HTML will only close an HTML element when necessary. Otherwise, elements are reused.
For instance, suppose one of the specified style mappings is p[style-name='Heading 1'] => h1. If Word Into HTML encounters a .docx paragraph with the style name Heading 1, the .docx paragraph is converted to a h1 element with the same text. If the next .docx paragraph also has the style name Heading 1, then the text of that paragraph will be appended to the existing h1 element, rather than creating a new h1 element.
In most cases, you'll probably want to generate a new h1 element instead. You can specify this by using the :fresh modifier:
p[style-name='Heading 1'] => h1:fresh
The two consecutive Heading 1 .docx paragraphs will then be converted to two separate h1 elements.
Reusing elements is useful in generating more complicated HTML structures. For instance, suppose your .docx contains asides. Each aside might have a heading and some body text, which should be contained within a single div.aside element. In this case, style mappings similar to p[style-name='Aside Heading'] => div.aside > h2:fresh and p[style-name='Aside Text'] => div.aside > p:fresh might be helpful.
Match any paragraph:
Match any run:
Match any table:
To match a paragraph, run or table with a specific style, you can reference the style by name. This is the style name that is displayed in Microsoft Word or LibreOffice. For instance, to match a paragraph with the style name Heading 1:
You can also match a style name by prefix. For instance, to match a paragraph where the style name starts with Heading:
Styles can also be referenced by style ID. This is the ID used internally in the .docx file. To match a paragraph or run with a specific style ID, append a dot followed by the style ID. For instance, to match a paragraph with the style ID Heading1:
Match explicitly bold text:
Note that this matches text that has had bold explicitly applied to it. It will not match any text that is bold because of its paragraph or run style.
Match explicitly italic text:
Note that this matches text that has had italic explicitly applied to it. It will not match any text that is italic because of its paragraph or run style.
Match explicitly underlined text:
Note that this matches text that has had underline explicitly applied to it. It will not match any text that is underlined because of its paragraph or run style.
Match explicitly struckthrough text:
Note that this matches text that has had strikethrough explicitly applied to it. It will not match any text that is struckthrough because of its paragraph or run style.
Match explicitly all caps text:
Note that this matches text that has had all caps explicitly applied to it. It will not match any text that is all caps because of its paragraph or run style.
Match explicitly small caps text:
Note that this matches text that has had small caps explicitly applied to it. It will not match any text that is small caps because of its paragraph or run style.
Use ! to ignore a document element. For instance, to ignore any paragraph with the style Comment:
p[style-name='Comment'] => !
The simplest HTML path is to specify a single element. For instance, to specify an h1 element:
To give an element a CSS class, append a dot followed by the name of the class:
To require that an element is fresh, use :fresh:
Modifiers must be used in the correct order:
To specify a separator to place between the contents of paragraphs that are collapsed together, use :separator('SEPARATOR STRING').
For instance, suppose a document contains a block of code where each line of code is a paragraph with the style Code Block. We can write a style mapping to map such paragraphs to <pre> elements:
p[style-name='Code Block'] => pre
Since pre isn't marked as :fresh, consecutive pre elements will be collapsed together. However, this results in the code all being on one line. We can use :separator to insert a newline between each line of code:
p[style-name='Code Block'] => pre:separator('\n')
Use > to specify nested elements. For instance, to specify h2 within div.aside:
div.aside > h2
You can nest elements to any depth.