diff options
| author | Michael Williamson <mike@zwobble.org> | 2017-04-03 18:53:38 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2017-04-03 18:53:38 +0100 |
| commit | 589c2ae52d4ffda75731b0c63fcd9ba3349ab4c2 (patch) | |
| tree | 22540233b929ffb2189d28b08471f5228a482a09 | |
| parent | ff3dfe86e69ea8f3c8f308339ee5114003a530bf (diff) | |
Add monospace paragraph to code example
| -rw-r--r-- | README.md | 27 |
1 files changed, 27 insertions, 0 deletions
@@ -538,6 +538,33 @@ var options = { }; ``` +Or if you want paragraphs that have been explicitly set to use monospace fonts to represent code: + +```javascript +function transformParagraph(paragraph) { + var runs = mammoth.transforms.getDescendantsOfType(paragraph, "run"); + var isMatch = runs.length > 0 && runs.every(function(run) { + return run.font && fonts.indexOf(run.font.toLowerCase()) !== -1; + }); + if (isMatch) { + return { + ...paragraph, + styleId: "code", + styleName: "Code" + }; + } else { + return paragraph; + } +} + +var options = { + transformDocument: mammoth.transforms.paragraph(transformParagraph), + styleMap: [ + "p[style-name='Code'] => pre:separator('\n')" + ] +}; +``` + #### `mammoth.transforms.paragraph(transformParagraph)` Returns a function that can be used as the `transformDocument` option. |
