From 92aa7ed024e2b3dfaad755d2a1fe4298530dbbb7 Mon Sep 17 00:00:00 2001 From: "Chris. Webster" Date: Tue, 9 Jun 2020 13:30:28 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#45375=20html-to-te?= =?UTF-8?q?xt:=20Add=20format:=20blockquote=20support=20by=20@webstech?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add blockquote as a possible format attribute. Add all possible formatters to test case. Signed-off-by: Chris. Webster --- types/html-to-text/html-to-text-tests.ts | 50 ++++++++++++++++++++++++ types/html-to-text/index.d.ts | 1 + types/html-to-text/lib/formatter.d.ts | 1 + 3 files changed, 52 insertions(+) diff --git a/types/html-to-text/html-to-text-tests.ts b/types/html-to-text/html-to-text-tests.ts index 39ccf97358..6af52550e1 100644 --- a/types/html-to-text/html-to-text-tests.ts +++ b/types/html-to-text/html-to-text-tests.ts @@ -22,3 +22,53 @@ console.log(fromString(htmlString)); console.log('Processing string with custom options'); console.log(fromString(htmlString, htmlOptions)); + +const allElements = 'a\ +
b
\ +

h

\ +
\ +\ +
\ +
    \ +

    p

    \ +
    \ +
      '; + +const fmtOptions: HtmlToTextOptions = { + format: { + anchor: (_el, _walk, _options) => { + return "--anchor--\n"; + }, + blockquote: (_el, _walk, _options) => { + return "--blockquote--\n"; + }, + heading: (_el, _walk, _options) => { + return "--heading--\n"; + }, + horizontalLine: (_el, _walk, _options) => { + return "--horizontalLine--\n"; + }, + image: (_el, _options) => { + return "--image--\n"; + }, + lineBreak: (_el, _walk, _options) => { + return "--lineBreak--\n"; + }, + orderedList: (_el, _walk, _options) => { + return "--orderedList--\n"; + }, + paragraph: (_el, _walk, _options) => { + return "--paragraph--\n"; + }, + table: (_el, _walk, _options) => { + return "--table--\n"; + }, + text: (_el, _options) => { + return "--text--\n"; + }, + unorderedList: (_el, _walk, _options) => { + return "--unorderedList--\n"; + }, + }, +}; +console.log(fromString(allElements, fmtOptions)); diff --git a/types/html-to-text/index.d.ts b/types/html-to-text/index.d.ts index 527ad1c8bc..edb2d275d4 100644 --- a/types/html-to-text/index.d.ts +++ b/types/html-to-text/index.d.ts @@ -137,6 +137,7 @@ export interface Formatters { lineBreak?: Formatter; paragraph?: Formatter; anchor?: Formatter; + blockquote?: Formatter; heading?: Formatter; table?: Formatter; orderedList?: Formatter; diff --git a/types/html-to-text/lib/formatter.d.ts b/types/html-to-text/lib/formatter.d.ts index 75824eba5d..597a80523c 100644 --- a/types/html-to-text/lib/formatter.d.ts +++ b/types/html-to-text/lib/formatter.d.ts @@ -5,6 +5,7 @@ export const image: LeafFormatter; export const lineBreak: Formatter; export const paragraph: Formatter; export const anchor: Formatter; +export const blockquote: Formatter; export const heading: Formatter; export const table: Formatter; export const orderedList: Formatter;