diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-04-02 17:45:12 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-04-02 17:46:47 +0100 |
| commit | 38a1958cfda5083fe9d7548a278b62a820ea2303 (patch) | |
| tree | d6917bc87f41e28c43af4fdb51048ad7cb4d4fa5 /README.md | |
| parent | 6a4cc9231f219c0047272c56081f881eab800d74 (diff) | |
Mark document transform API as unstable
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 104 |
1 files changed, 56 insertions, 48 deletions
@@ -291,51 +291,6 @@ var options = { mammoth.convertToHtml({path: "path/to/document.docx"}, 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.styleId) { - element.styleId = "Heading2"; - } - } - return element; -} - -var options = { - transformDocument: transformElement -}; -``` - -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)` @@ -367,9 +322,6 @@ 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. * `convertImage`: by default, images are converted to `<img>` elements with the source included inline in the `src` attribute. Set this option to an [image converter](#image-converters) to override the default behaviour. @@ -381,6 +333,11 @@ Converts the source document to HTML. a string to prepend to any generated IDs, such as those used by bookmarks, footnotes and endnotes. Defaults to an empty string. + + * `transformDocument`: if set, + this function is applied to the document read from the docx file before the conversion to HTML. + The API for document transforms should be considered unstable. + See [document transforms](#document-transforms). * Returns a promise containing a result. This result has the following properties: @@ -487,6 +444,57 @@ mammoth.images.imgElement(function(image) { }) ``` +### Document transforms + +**The API for document transforms should be considered unstable, +and may change between any versions. +If you rely on this behaviour, +you should pin to a specific version of mammoth.js, +and test carefully before updating.** + +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.styleId) { + element.styleId = "Heading2"; + } + } + return element; +} + +var options = { + transformDocument: transformElement +}; +``` + +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) +}; +``` + #### `mammoth.transforms.paragraph(transformParagraph)` Returns a function that can be used as the `transformDocument` option. |
