diff options
| author | Michael Williamson <mike@zwobble.org> | 2014-07-17 19:00:01 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2014-07-17 19:00:01 +0100 |
| commit | 8081ee3564956e1af9ac5d93a25953633f099ef9 (patch) | |
| tree | 4ba5b5b5965b03b1c18b00fe112ef384c11610fb /README.md | |
| parent | 4457936b892dc622030f22d70935a69456aa3eb6 (diff) | |
Add mammoth.transforms.paragraph
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -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. |
