aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2014-07-17 19:00:01 +0100
committerMichael Williamson <mike@zwobble.org>2014-07-17 19:00:01 +0100
commit8081ee3564956e1af9ac5d93a25953633f099ef9 (patch)
tree4ba5b5b5965b03b1c18b00fe112ef384c11610fb /README.md
parent4457936b892dc622030f22d70935a69456aa3eb6 (diff)
Add mammoth.transforms.paragraph
Diffstat (limited to 'README.md')
-rw-r--r--README.md23
1 files changed, 23 insertions, 0 deletions
diff --git a/README.md b/README.md
index c5fbb84..b583843 100644
--- a/README.md
+++ b/README.md
@@ -220,6 +220,22 @@ var options = {
The return value of `transformDocument` is used during HTML generation.
The original document (and any child elements) can be safely modified.
+The above can be written more succinctly using the helper `mammoth.transforms.paragraph`:
+
+```javascript
+
+function transformParagraph(element) {
+ if (element.alignment === "center" && !element.styleId) {
+ element.styleId = "Heading2";
+ }
+ return element;
+}
+
+var options = {
+ transformDocument: mammoth.transforms.paragraph(transformParagraph)
+};
+```
+
### API
#### `mammoth.convertToHtml(input, options)`
@@ -315,6 +331,13 @@ mammoth.images.inline(function(element) {
})
```
+#### `mammoth.transforms.paragraph(transformParagraph)`
+
+Returns a function that can be used as the `transformDocument` option.
+This will apply the function `transformParagraph` to each paragraph element.
+`transformParagraph` should return the new paragraph,
+and is allowed to mutate the original paragraph.
+
## Writing style maps
A style map is made up of a number of style mappings separated by new lines.