From 15d8ac59dda313937cda0f0d069c7dd10fc63c9d Mon Sep 17 00:00:00 2001 From: noumantahir Date: Fri, 29 Apr 2022 05:26:45 +0500 Subject: [PATCH] method rearrange --- .../postHtmlRenderer/postHtmlRenderer.tsx | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/components/postHtmlRenderer/postHtmlRenderer.tsx b/src/components/postHtmlRenderer/postHtmlRenderer.tsx index e3b25c670..a7da786d4 100644 --- a/src/components/postHtmlRenderer/postHtmlRenderer.tsx +++ b/src/components/postHtmlRenderer/postHtmlRenderer.tsx @@ -121,6 +121,27 @@ export const PostHtmlRenderer = memo( } catch (error) { } }; + + //this method checks if image is a child of table column + //and calculates img width accordingly, + //returns full width if img is not part of table + const getMaxImageWidth = (tnode: TNode) => { + //return full width if not parent exist + if (!tnode.parent || tnode.parent.tagName === 'body') { + return contentWidth; + } + + //return divided width based on number td tags + if (tnode.parent.tagName === 'td' || tnode.parent.tagName === 'th') { + const cols = tnode.parent.parent.children.length; + return contentWidth / cols; + } + + //check next parent + return getMaxImageWidth(tnode.parent); + }; + + const _onElement = (element: Element) => { if (element.tagName === 'img' && element.attribs.src) { const imgUrl = element.attribs.src; @@ -129,6 +150,9 @@ export const PostHtmlRenderer = memo( } }; + + + const _anchorRenderer = ({ InternalRenderer, tnode, ...props }: CustomRendererProps) => { const parsedTnode = parseLinkData(tnode); const _onPress = () => { @@ -178,24 +202,8 @@ export const PostHtmlRenderer = memo( }; - //this method checks if image is a child of table column - //and calculates img width accordingly, - //returns full width if img is not part of table - const getMaxImageWidth = (tnode: TNode) => { - //return full width if not parent exist - if (!tnode.parent || tnode.parent.tagName === 'body') { - return contentWidth; - } - //return divided width based on number td tags - if (tnode.parent.tagName === 'td' || tnode.parent.tagName === 'th') { - const cols = tnode.parent.parent.children.length; - return contentWidth / cols; - } - //check next parent - return getMaxImageWidth(tnode.parent); - }; const _imageRenderer = ({ tnode }: CustomRendererProps) => { const imgUrl = tnode.attributes.src;