ooxast-util-markup-to-style
v0.5.0
Published
Find certain markup in an ooxast tree and turn it into styles.
Downloads
9
Readme
Note This repository is automatically generated from the main parser monorepo. Please submit any issues or pull requests there.
ooxast-util-markup-to-style
Find certain markup in an ooxast tree and turn it into styles.
Contents
- ooxast-util-markup-to-style
What is this?
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.
When should I use this?
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,
Install
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
Use
API
markupToStyle()
Signature
markupToStyle<I>(tree: I, options: Options = ...): I;
Type parameters
I
extendsP
|Root
=Root
Parameters
| Name | Type |
| :-------- | :------------------------------ |
| tree
| I
|
| options
| Options
|
Returns
I
Defined in: ooxast-util-markup-to-style/src/lib/ooxast-util-markup-to-style.ts:87
Option
Properties
ignorePunctuation?
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.
Default
true
Defined in: ooxast-util-markup-to-style/src/lib/ooxast-util-markup-to-style.ts:59
markup
"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"
, {w:color
?:string
;w:frame
?:string
;w:shadow
?:string
;w:space
?:string
;w:sz
?:string
;w:themeColor
?:ThemeColorVal
;w:themeShade
?:string
;w:themeTint
?:string
;w:val
:BorderVal
; } | {w:themeColor
?:ThemeColorVal
;w:themeShade
?:string
;w:themeTint
?:string
;w:val
:string
; } | {w:combine
?:string
;w:combineBrackets
?:CombineBracketsVal
;w:id
?:string
;w:vert
?:string
;w:vertCompress
?:string
; } | {w:val
:EmVal
; } | {w:id
?:string
;w:val
:string
; } | {w:ascii
:string
;w:asciiTheme
:ThemeVal
;w:cs
:string
;w:cstheme
:ThemeVal
;w:eastAsia
:string
;w:eastAsiaTheme
:ThemeVal
;w:hAnsi
:string
;w:hAnsiTheme
:ThemeVal
;w:hint
:HintVal
; } | {w:val
:HighlightColorVal
; } | {w:val
:string
; } | {w:bidi
?:string
;w:eastAsia
?:string
;w:val
?:string
; } | {w:val
:string
; } | {w:color
?:string
;w:fill
?:string
;w:themeColor
?:ThemeColorVal
;w:themeFill
?:ThemeColorVal
;w:themeFillShade
?:string
;w:themeFillTint
?:string
;w:themeShade
?:string
;w:themeTint
?:string
;w:val
:ShdVal
; } | {w:val
:string
; } | {w:val
:string
; } | {w:val
:string
; } | {w:val
:TextEffectVal
; } | {w:val
:string
; } | {w:color
?:string
;w:themeColor
?:ThemeColorVal
;w:themeShade
?:string
;w:themeTint
?:string
;w:val
?:UnderlineVal
; } | {w:val
:VerticalAlignRunVal
; } | {w:val
?:string
; }>>) =>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.
Example
'w:b'
Example
;['w:b', 'w:i']
Example
['m:b']
Match text that is bold and italic, and red:
Example
;(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
matchAll?
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.
Default
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
matchFull?
boolean
Whether the entire paragraph should contain the markup, or the markup can be present in any of the runs.
Default
true
Defined in: ooxast-util-markup-to-style/src/lib/ooxast-util-markup-to-style.ts:50
style
string
The style to apply if the markup is present.
Example
'Heading 1'
Defined in: ooxast-util-markup-to-style/src/lib/ooxast-util-markup-to-style.ts:29
Options
Option
[]
Example
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
Syntax tree
This package uses the ooxast syntax tree.
Types
Compatibility
Security
Related
Contribute
License
GPL-3.0-or-later © Thomas F. K. Jorna