From 8081ee3564956e1af9ac5d93a25953633f099ef9 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 17 Jul 2014 19:00:01 +0100 Subject: Add mammoth.transforms.paragraph --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'README.md') 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. -- cgit v1.2.3