aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2014-01-08 17:21:46 +0000
committerMichael Williamson <mike@zwobble.org>2014-01-08 17:21:46 +0000
commit47efcec3be6f5bf84987c73e16fdeee991fd6bba (patch)
tree3a3313bd4702e90f654b209ec94242bf98c10450
parentff6325e5625893502cd211f5a21fe28c716575f4 (diff)
Document transformDocument
-rw-r--r--README.md29
1 files changed, 29 insertions, 0 deletions
diff --git a/README.md b/README.md
index 71c51e8..39a2fc6 100644
--- a/README.md
+++ b/README.md
@@ -92,6 +92,32 @@ var options = {
};
```
+### Document transforms
+
+Mammoth allows a document to be transformed before it is converted.
+For instance,
+suppose that document has not been semantically marked up,
+but you know that any centre-aligned paragraph should be a heading.
+You can use the `transformDocument` argument to modify the document appropriately:
+
+```javascript
+function transformElement(element) {
+ if (element.children) {
+ element.children.forEach(transformElement);
+ }
+ if (element.type === "paragraph") {
+ if (element.alignment === "center" && !element.styleName) {
+ element.styleName = "Heading2";
+ }
+ }
+ return element;
+}
+
+var options = {
+ transformDocument: transformElement
+};
+```
+
### API
#### `mammoth.convertToHtml(input, options)`
@@ -115,6 +141,9 @@ Converts the source document to HTML.
the style map passed in `styleMap` is combined with the default style map.
To stop using the default style map altogether,
set `options.includeDefaultStyleMap` to `false`.
+
+ * `transformDocument`: if set,
+ this function is applied to the document read from the docx file before the conversion to HTML.
* Returns a promise containing a result.
This result has the following properties: