npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

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

npm version npm downloads

Find certain markup in an ooxast tree and turn it into styles.

Contents

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 extends P | 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