RichText is not transforming type "paragraph"

I have a node process that is looping through the JSON of a document, and calling the method PrismicDOM.RichText.asHtml to transform the content to HTML.

      .forEach(item => {
        console.log('TRANSFORMING ', item)
        PrismicDOM.RichText.asHtml([item], linkResolver)
      })

This is working properly for the header types, but is not working for paragraph. There is no error, it simply returns the paragraph in the JSON format.

Using “prismic-dom”: “^2.1.0”

Here we are comparing the node before and after calling the RichText method. You can see paragraph unchanged.

Just in case, here is my linkResolver, which doesn’t really do anything…

const linkResolver = function(doc) {
  if (doc.type === 'page') return '/page/' + doc.uid
  return '/'
}

If I change the content in the original document to a type of header, it is then working.

Hi @doug, thanks for reaching out with your question here. This is very strange, and I’m not sure right off the bat what the issue is, I’ll need to take a closer look. I’ll DM you now so that I can gather more information.

Sounds good thanks @levi - looking forward to hearing from you.

I’m having a similar problem. prismicDom.RichText.asHtml is not calling linkResolver. I’m using a StructuredText in the repeating part of a slice.
I have a paragraph that contains a link. The HTML seems to be formatted correctly, except the link is output as

<a href>Click here</a>

I dropped a console.log into the linkResolver, and nothing is being called. Not sure what might be going wrong.

As a bandaid, I created a function that creates a TextChunck array by splitting text returned from prismicDom.RichText.asHTML by each instance of the following substring:

<a href="">

Then created an array of PrismicNode[‘non-repeat’].StructuredTextItem.value[i].spans that were type “hyperlink”. Looped through the hyperlink spans to get and resolve links and pre-pended the following “string” to each member of the TextChunck array.

`<a href="${resolvedUrl}">`

joining the TextChunk array back together will give you back your links.

Hi @ecalvo, this is very strange. I’m not sure what the issue might be, so I’d like to take a closer look at your project code to see if I can reproduce the issue.

Can you share your project with me by either sending a zip file of the code or a link to Github? If you don’t want to share it publicly here, you can send me a private message.

@ecalvo So if I understand you correctly the following code that you sent me doesn’t work for you:

prismicDom.RichText.asHtml(this.textNode,this.linkResolver)

Is that correct?

Correct.

If I have links within a paragraph, an “a” tag with a blank “href” attribute is returned regardless of whether a link resolver is supplied or not. Also regardless of whether the link is a web link or a document link.

Just to debug, I was returning the google url. I still got an “a” tag with a blank “href”

@ecalvo This is strange. I’m not sure what the issue might be, so I’ll have to pass it over to the @team-tech-support. Someone there will look into this as soon as they are able.

To help troubleshoot can you provide the following?

  • The url for your Prismic repository (you can send in private message if you wish)
  • The version of the prismic-dom kit that you’re using

Hey @doug, you probably know that but forEach does not modify the array it’s called on. Is there any chance that would be the reason why it doesn’t work for you? Probably not as you mention headings being properly formatted but who knows :blush:

Hey @ecalvo, I tried to reproduce the error with a simple piece of code but could not. Do you happen to have a repro link I could check?

This issue has been closed due to inactivity.