UNPKG

npf2html

Version:

Converts Tumblr's Neue Post Format to plain HTML

87 lines (86 loc) 3.61 kB
import { Options } from './options'; import { AskLayout } from './ask-layout'; import { Attribution } from './attribution'; import { AudioBlock } from './audio-block'; import { ImageBlock } from './image-block'; import { UnknownBlock } from './index'; import { InlineFormat } from './inline-format'; import { LinkBlock } from './link-block'; import { VisualMedia } from './media'; import { PaywallBlock } from './paywall-block'; import { PollBlock } from './poll-block'; import { RowsDisplay } from './rows-layout'; import { TextBlockIndented, TextBlockNoIndent } from './text-block'; import { VideoBlock } from './video-block'; /** * A class that stores materialized options for rendering NPF to HTML. * * Callers may extend this class and override any of its `render*()` methods to * change the way particular NPF components are rendered. * * @category Main */ export declare class Renderer { /** @see Options.prefix */ readonly prefix: string; /** @see Options.askingAvatar */ readonly askingAvatar: VisualMedia[]; constructor(options?: Options); /** * Escapes all characters in {@link text} that aren't safe to use literally in * HTML text or attributes. */ escape(text: string): string; /** HTML-escapes {@link text} and formats it according to {@link formatting}. */ formatText(text: string, formatting: InlineFormat[] | undefined): string; /** Wraps {@link html} as an ask. */ renderAskLayout(layout: AskLayout, html: string): string; /** Converts {@link attribution} to HTML. */ renderAttribution(attribution: Attribution): string; /** Converts {@link block} to HTML. */ renderAudio(block: AudioBlock): string; /** Converts {@link block} to HTML. */ renderImage(block: ImageBlock): string; /** * Applies the formatting specified by {@link format} to {@link html}, which may * already include nested formatting. * * The {@link html} has already been trimmed to only the section to which * {@link format} applies. */ renderInlineFormat(html: string, format: InlineFormat): string; /** * Converts {@link media} to HTML. * * @param options.alt - The alt text for the media. */ renderImageMedia(media: VisualMedia[], options?: { alt?: string; }): string; /** Converts {@link block} to HTML. */ renderLink(block: LinkBlock): string; /** Converts {@link block} to HTML. */ renderPaywall(block: PaywallBlock): string; /** Converts {@link block} to HTML. */ renderPoll(block: PollBlock): string; /** Wraps {@link html} as single row. */ renderRowLayout(display: RowsDisplay, html: string): string; /** Converts {@link block} to HTML. */ renderTextNoIndent(block: TextBlockNoIndent): string; /** * Converts {@link blocksAndNested} to HTML. * * The first element of {@link blocksAndNested} determines the subtype of the * entire thing; any other blocks are guaranteed to have the same subtype. The * string elements of {@link blocksAndNested} ar {@link TextBlockIndented} * objects which are more deeply nested and have already been converted to * HTML. */ renderTextIndented(blocksAndNested: [TextBlockIndented, ...Array<TextBlockIndented | string>]): string; /** Renders {@link html} as a "below the fold" read more. */ renderTruncateLayout(html: string): string; /** Renders {@link block} as HTML. */ renderUnknown(block: UnknownBlock): string; /** Converts {@link block} to HTML. */ renderVideo(block: VideoBlock): string; }