Note This repository is automatically generated from the main parser monorepo. Please submit any issues or pull requests there.
Find certain markup in an ooxast tree and turn it into styles.
- ooxast-util-markup-to-style
This is a small utility function that finds certain markup for text (runs) in an ooxast
syntax tree and turns it into styles that belong to the parent paragraph.
If you want to turn certain markup in an ooxast
syntax tree into styles, e.g. bolded lines into headings, or all red text into a quote,
This package is ESM only. In Node.js (version 12.20+, 14.14+, 16.0+, 18.0+), install as
pnpm add ooxast-util-markup-to-style
# or with yarn
# yarn add ooxast-util-markup-to-style
# or with npm
# npm install ooxast-util-markup-to-style
markupToStyle<I>(tree: I, options: Options = ...): I;
I
extendsP
|Root
=Root
Name | Type |
---|---|
tree |
I |
options |
Options |
I
Defined in: ooxast-util-markup-to-style/src/lib/ooxast-util-markup-to-style.ts:87
boolean
If punctuation or whitespace should be ignored when matching.
E.g. if markup: 'w:b'
is specified and only an empty space at the beginning of the paragraph is bold, the style not be applied.
Likewise, if markup: 'w:b'
is specified and only a period at the end of the paragraph is not bold, the style not be applied.
true
Defined in: ooxast-util-markup-to-style/src/lib/ooxast-util-markup-to-style.ts:59
"w:rPrChange"
|"w:bdr"
|"w:color"
|"w:eastAsianLayout"
|"w:em"
|"w:fitText"
|"w:rFonts"
|"w:highlight"
|"w:lang"
|"w:shd"
|"w:position"
|"w:spacing"
|"w:effect"
|"w:w"
|"w:u"
|"w:vertAlign"
|"w:shadow"
|"w:sz"
|"w:snapToGrid"
|"w:cs"
|"w:oMath"
|"w:b"
|"w:i"
|"w:rtl"
|"w:bCs"
|"w:caps"
|"w:dstrike"
|"w:emboss"
|"w:iCs"
|"w:imprint"
|"w:kern"
|"w:noProof"
|"w:outline"
|"w:rStyle"
|"w:smallCaps"
|"w:specVanish"
|"w:strike"
|"w:szCs"
|"w:vanish"
|"w:webHidden"
| ("w:rPrChange"
|"w:bdr"
|"w:color"
|"w:eastAsianLayout"
|"w:em"
|"w:fitText"
|"w:rFonts"
|"w:highlight"
|"w:lang"
|"w:shd"
|"w:position"
|"w:spacing"
|"w:effect"
|"w:w"
|"w:u"
|"w:vertAlign"
|"w:shadow"
|"w:sz"
|"w:snapToGrid"
|"w:cs"
|"w:oMath"
|"w:b"
|"w:i"
|"w:rtl"
|"w:bCs"
|"w:caps"
|"w:dstrike"
|"w:emboss"
|"w:iCs"
|"w:imprint"
|"w:kern"
|"w:noProof"
|"w:outline"
|"w:rStyle"
|"w:smallCaps"
|"w:specVanish"
|"w:strike"
|"w:szCs"
|"w:vanish"
|"w:webHidden"
)[] | (rPr
:Partial
<Record
<"w:rPrChange"
|"w:bdr"
|"w:color"
|"w:eastAsianLayout"
|"w:em"
|"w:fitText"
|"w:rFonts"
|"w:highlight"
|"w:lang"
|"w:shd"
|"w:position"
|"w:spacing"
|"w:effect"
|"w:w"
|"w:u"
|"w:vertAlign"
|"w:shadow"
|"w:sz"
|"w:snapToGrid"
|"w:cs"
|"w:oMath"
|"w:b"
|"w:i"
|"w:rtl"
|"w:bCs"
|"w:caps"
|"w:dstrike"
|"w:emboss"
|"w:iCs"
|"w:imprint"
|"w:kern"
|"w:noProof"
|"w:outline"
|"w:rStyle"
|"w:smallCaps"
|"w:specVanish"
|"w:strike"
|"w:szCs"
|"w:vanish"
|"w:webHidden"
,undefined
|never
|Border
[] |OnOff
<"oMath"
>[] |OnOff
<"b"
>[] |OnOff
<"i"
>[] |TextEffect
[] |OnOff
<"cs"
>[] |Highlight
[] |OnOff
<"rtl"
>[] |HpsMeasure
<"sz"
>[] |Color
[] |TextScale
[] |Shd
[] |OnOff
<"snapToGrid"
>[] |SignedTwipsMeasure
[] |OnOff
<"bCs"
>[] |OnOff
<"caps"
>[] |OnOff
<"dstrike"
>[] |EastAsianLayout
[] |Em
[] |OnOff
<"emboss"
>[] |FitText
[] |OnOff
<"iCs"
>[] |OnOff
<"imprint"
>[] |HpsMeasure
<"kern"
>[] |Language
[] |OnOff
<"noProof"
>[] |OnOff
<"outline"
>[] |SignedHpsMeasure
[] |Fonts
[] |StringTag
<"rStyle"
>[] |OnOff
<"shadow"
>[] |OnOff
<"smallCaps"
>[] |OnOff
<"specVanish"
>[] |OnOff
<"strike"
>[] |HpsMeasure
<"szCs"
>[] |Underline
[] |OnOff
<"vanish"
>[] |VerticalAlignRun
[] |OnOff
<"webHidden"
>[] | {w:val
?:boolean
; }>>) =>boolean
The markup to look for.
If no namespace is specified, the default namespace (w:
) is assumed.
You can also specify a matcher function which takes a JSON representation of the RPr element and returns true if the style should be applied.
'w:b'
['w:b', 'w:i']
['m:b']
Match text that is bold and italic, and red:
(rPr) => rPr['w:b'] && rPr['w:i'] && rPr['w:color']?.['w:val'] === 'FF0000'
Defined in: ooxast-util-markup-to-style/src/lib/ooxast-util-markup-to-style.ts:23
boolean
If true (default), the style is applied if all of the markup elements are present.
If false, the style is applied if any of the markup elements are present.
Example
If ['b', 'i']
is specified with matchAll: true
, the style will only be applied if the text is bold and italic.
If ['b', 'i']
is specified with matchAll: false
, the style will be applied if the text is bold or italic.
true
Does not apply if markup
is a function.
Defined in: ooxast-util-markup-to-style/src/lib/ooxast-util-markup-to-style.ts:44
boolean
Whether the entire paragraph should contain the markup, or the markup can be present in any of the runs.
true
Defined in: ooxast-util-markup-to-style/src/lib/ooxast-util-markup-to-style.ts:50
string
The style to apply if the markup is present.
'Heading 1'
Defined in: ooxast-util-markup-to-style/src/lib/ooxast-util-markup-to-style.ts:29
Option
[]
const options: Options = [
// find all paragraphs that are bold and larger than 24pt and make it a Title
{
markup: (rPr) => rPr['w:b'] && rPr['w:sz'] && rPr['w:sz']['w:val'] > 24,
style: 'Title',
},
// find all paragraphs that are strikethrough text and make it a Comment
{
markup: 'w:strike',
style: 'Comment',
},
]
Defined in: ooxast-util-markup-to-style/src/lib/ooxast-util-markup-to-style.ts:80
This package uses the ooxast syntax tree.
GPL-3.0-or-later © Thomas F. K. Jorna