Skip to content

Instantly share code, notes, and snippets.

@ethancalvo
Created August 6, 2020 17:02
Show Gist options
  • Save ethancalvo/3d94076fbbe43ea4c91b6eaab9e4eddd to your computer and use it in GitHub Desktop.
Save ethancalvo/3d94076fbbe43ea4c91b6eaab9e4eddd to your computer and use it in GitHub Desktop.
Prismic-Dom RichText.asHtml on a SliceZone creates html that lacks urls in anchor tags.
/*
prismic-dom ^2.2.3
the json was produced using
prismic-javascript ^2.7.1
*/
const prismicDom = require('prismic-dom');
const simplePage = {
"uid": "test-index",
"type": "pages",
"lang": "en-us",
"data": {
"pages": {
"page_title": {
"type": "Text",
"value": "New Test Page"
},
"body": {
"type": "SliceZone",
"value": [
{
"type": "Slice",
"slice_type": "hero_text",
"non-repeat": {
"text": {
"type": "StructuredText",
"value": [
{
"type": "paragraph",
"text": "Check out my child page. Or this other one.",
"spans": [
{
"start": 13,
"end": 23,
"type": "hyperlink",
"data": {
"type": "Link.document",
"value": {
"document": {
"id": "XvZQ_RBADCEAZzSG",
"type": "pages",
"tags": [
"test"
],
"lang": "en-us",
"slug": "test-child-page",
"uid": "test-child-page"
},
"isBroken": false
}
}
},
{
"start": 25,
"end": 43,
"type": "label",
"data": {
"label": "no-wrap"
}
},
{
"start": 39,
"end": 42,
"type": "hyperlink",
"data": {
"type": "Link.document",
"value": {
"document": {
"id": "XXcdDhMRFCEAU3rT",
"type": "pages",
"tags": [
"test"
],
"lang": "en-us",
"slug": "test-skills",
"uid": "test-skills"
},
"isBroken": false
}
}
}
]
}
]
}
}
}
]
}
}
}
}
const lr = (doc) => {
//return `https://www.google.com`;
return `/${doc.uid}`;
}
let prismicHtml = prismicDom.RichText.asHtml(simplePage.data.pages.body.value[0]['non-repeat'].text.value,lr);
console.log(prismicHtml);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment