Options
All
  • Public
  • Public/Protected
  • All
Menu

flat-html-helpers

Index

Functions

breakHeaderEms

  • breakHeaderEms(html: string, options?: { noEndTag?: undefined | false | true } & { level?: undefined | number } | { levels?: number[] }): string
  • Inserts <br> tags into <h#> header tags before any <em> tags.

    Parameters

    • html: string

      The html to parse.

    • Default value options: { noEndTag?: undefined | false | true } & { level?: undefined | number } | { levels?: number[] } = {}

      The options for which level(s) for headers to parse.

    Returns string

    The original html but with now <br> tags after headers.

cleanIds

  • cleanIds(html: string, duplicateFormatter?: (id: string, n: number) => string): string
  • Cleans all the ids in a given html string, making sure no duplicate ids are found.

    If duplicates are found a number is appended, e.g. "dup" -> "dup2".

    Parameters

    • html: string

      The html to clean of ids.

    • Default value duplicateFormatter: (id: string, n: number) => string = defaultDuplicateFormatter

      An optional formatter that takes an id and number (>=2) that returns the new id. NOTE: This does not check to ensure you don't return re-duplicate ids. It assumes you take the number and use it.

        • (id: string, n: number): string
        • Parameters

          • id: string
          • n: number

          Returns string

    Returns string

    A new html string with no duplicate ids.

Const defaultContentClass

  • defaultContentClass(level: number): string

Const defaultDuplicateFormatter

  • defaultDuplicateFormatter(id: string, n: number): string

Const defaultSectionClass

  • defaultSectionClass(level: number): string

ensureFunction

  • ensureFunction(val: string | undefined | ((level: number) => string), defaultFunction: (level: number) => string): (level: number) => string
  • Ensures a value is a string formatter function.

    Parameters

    • val: string | undefined | ((level: number) => string)

      The value to ensure.

    • defaultFunction: (level: number) => string

      A default function to use in case of no match.

        • (level: number): string
        • Parameters

          • level: number

          Returns string

    Returns (level: number) => string

    A valid function.

      • (level: number): string
      • Parameters

        • level: number

        Returns string

repeat

  • repeat(str: string, count: number): string
  • Polyfill for String.repeat.

    Parameters

    • str: string

      String to repeat.

    • count: number

      Number of times to repeat.

    Returns string

    The str repeated count times.

sectionize

  • sectionize(html: string, options?: { contentClass?: string | ((level: number) => string); levels?: number[]; pushDownHrs?: undefined | false | true; sectionClass?: string | ((level: number) => string) }): string
  • Wraps a flat HTML structure in sections and divs based on h1, h2, etc levels.

    Parameters

    • html: string

      The already parsed html to parse. Probably from a markdown source.

    • Default value options: { contentClass?: string | ((level: number) => string); levels?: number[]; pushDownHrs?: undefined | false | true; sectionClass?: string | ((level: number) => string) } = {}

      Options for how to format the sections.

      • Optional contentClass?: string | ((level: number) => string)

        Function that returns the class attribute for new content divs.

      • Optional levels?: number[]

        The list of level(s) to sectionize., e.g. [2, 3] for h2, h3.

      • Optional pushDownHrs?: undefined | false | true

        Push down


        tags that are above a tag to after the section.

      • Optional sectionClass?: string | ((level: number) => string)

        Function that returns the class attribute for new sections.

    Returns string

    A new html string from the source, now wrapped in sections.

Generated using TypeDoc