prismicio / prismic-dom

Set of helpers to manage Prismic data
https://prismic.io/docs/technologies/prismic-dom-technical-reference
44 stars 16 forks source link

Link.web in RichText is not handled correctly. #59

Closed rokerkony closed 2 years ago

rokerkony commented 2 years ago

Hey, I created a document on Prismic.io and in the rich text field I added link to external website. The result though is rendered with an empty href as follows:

<a  href="">my link</a>

I was investigating more on this topic and found out that this code to serialize the link block is not respecting the block I get from Prismic API (v2).

See the object I get for my RichText:

[
    {
        "type": "paragraph",
        "text": "Hey my link bam",
        "spans": [
            {
                "start": 4,
                "end": 11,
                "type": "hyperlink",
                "data": {
                    "type": "Link.web",
                    "value": {
                        "url": "https://www.erento.com",
                        "target": "_blank"
                    }
                }
            }
        ]
    }
]

The method mentioned above works with element.data.target instead of element.data.value.target. Same as LinkHelper.url(element.data, linkResolver)) should be LinkHelper.url(element.data.value, linkResolver)).

My thoughts are based on the response I get from the API.

Can you please check it?

p.s.: For transformation of RichText to HTML I use

return PrismicDom.RichText.asHtml(data.value, function (doc) {
    return doc;
});

The element in the custom type is defined as:

"content" : {
  "type" : "StructuredText",
  "config" : {
    "multi" : "paragraph,preformatted,heading2,heading3,heading4,strong,em,hyperlink,image,embed,list-item,o-list-item",
    "allowTargetBlank" : true,
    "label" : "Content"
  }
},
rokerkony commented 2 years ago

it was problem that I was still fetching the api v1, with v2 it works

angeloashmore commented 2 years ago

Hi @rokerkony, thanks for letting us know you found a fix! Sorry you didn't get a response quickly, but feel free to reach out again if you run into other issues.