From f452c54bf04c0a8091eac900e78ac5d78863a095 Mon Sep 17 00:00:00 2001 From: David Baum Date: Thu, 5 Aug 2021 15:52:45 +0300 Subject: [PATCH] Added parsing the hyperlink style of the TextNode --- custom.d.ts | 1 + src/helpers/parseTextStyle.ts | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/custom.d.ts b/custom.d.ts index d695ccc..5a4dc4e 100644 --- a/custom.d.ts +++ b/custom.d.ts @@ -32,3 +32,4 @@ type FontStyleNames = | 'fills' | 'textStyleId' | 'fillStyleId' + | 'hyperlink' diff --git a/src/helpers/parseTextStyle.ts b/src/helpers/parseTextStyle.ts index a400cbf..3e3ab40 100644 --- a/src/helpers/parseTextStyle.ts +++ b/src/helpers/parseTextStyle.ts @@ -11,7 +11,8 @@ const styleFonts: FontStyleNames[] = [ 'lineHeight', 'fills', 'textStyleId', - 'fillStyleId' + 'fillStyleId', + 'hyperlink' ] /* @@ -25,7 +26,7 @@ const styleFonts: FontStyleNames[] = [ Returns styles for the entire text: parseTextStyle(textNode) - + Returns text styles from the 100th to the last character: parseTextStyle(textNode, 100) @@ -65,7 +66,13 @@ function parseTextStyle( // collection of styles names.forEach((n, i) => { - letter[styleName[i]] = node['getRange' + n](startIndex, endIndex) + const rangeStyleValue = node['getRange' + n](startIndex, endIndex) + if ( + n.toLowerCase() !== 'hyperlink' || + (rangeStyleValue && rangeStyleValue.constructor === Object) + ) { + letter[styleName[i]] = rangeStyleValue + } }) if (textStyle) { @@ -310,7 +317,7 @@ function changeCharactersTextStyle(textStyle: LetterStyle[], characters: string) } /* - Function for changing properties of TextStyle. + Function for changing properties of TextStyle. The beforeValue parameter allows you to specify the value in which the property to be changed should be. */