Skip to content

Collect all text items, not just the last item#2

Merged
wenga86 merged 2 commits intomasterfrom
bugfix/metadata-text
Mar 22, 2023
Merged

Collect all text items, not just the last item#2
wenga86 merged 2 commits intomasterfrom
bugfix/metadata-text

Conversation

@wenga86
Copy link
Copy Markdown

@wenga86 wenga86 commented Mar 22, 2023

Problem

RTE JSON links may have more than one child within them. In cases such as these the text attribute should return all child text, not just the last child's value.

Solution

Collect all text nodes and stitch their values together

Real world Examples

{
    "uid": "27a303b40d2f4e85874c15bea3a906f5",
    "type": "reference",
    "attrs": {
        "display-type": "link",
        "type": "entry",
        "class-name": "embedded-entry redactor-component block-entry",
        "entry-uid": "blt513d896103aab8a4",
        "locale": "en-us",
        "content-type-uid": "product_listing",
        "target": "_self",
        "href": "/go/l/blt513d896103aab8a4"
    },
    "children": [
        {
            "text": ""
        },
        {
            "uid": "c3b9a54551464998a64c3b4f510f61e8",
            "type": "span",
            "attrs": {},
            "children": [
                {
                    "text": "L'Oreal Paris Telescopic Lift Washable Mascara"
                }
            ]
        },
        {
            "text": ""
        }
    ]
}

Expected

"L'Oreal Paris Telescopic Lift Washable Mascara"

Received

""
{
    "uid": "2643192bee9445ee9a84c637a9d8d185",
    "type": "reference",
    "attrs": {
        "href": "/go/l/bltb4a1874571d07893",
        "data-slate-node": "element",
        "data-slate-inline": "true",
        "display-type": "link",
        "type": "entry",
        "class-name": "embedded-entry redactor-component block-entry",
        "entry-uid": "bltb4a1874571d07893",
        "locale": "en-us",
        "content-type-uid": "product_listing",
        "target": "_self",
        "data-editor-type": "scrte",
        "class": "style-module_linkRef__c1tvp",
        "data-type": "link",
        "data-testid": "embed-hyperlink"
    },
    "children": [
        {
            "text": "L'Oreal Paris Telescopic Lift "
        },
        {
            "text": "Washable",
            "italic": true
        },
        {
            "text": " Mascara"
        }
    ]
}

Expected

"L'Oreal Paris Telescopic Lift Washable Mascara"

Received

" Mascara"

@wenga86 wenga86 merged commit d318693 into master Mar 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants