Skip to content

Instantly share code, notes, and snippets.

@prismicdeveloper
Last active August 29, 2015 14:18
Show Gist options
  • Save prismicdeveloper/ad67f185eefe842e4a12 to your computer and use it in GitHub Desktop.
Save prismicdeveloper/ad67f185eefe842e4a12 to your computer and use it in GitHub Desktop.
var htmlSerializer = function (element, content) {
// Don't wrap images in a <p> tag
if (element.type == "image") {
return '<img src="' + element.url + '" alt="' + element.alt + '">';
}
// Add a class to hyperlinks
if (element.type == "hyperlink") {
return '<a class="some-link" href="' + element.url + '">' + content + '</a>';
}
// Return null to stick with the default behavior
return null;
};
var html = doc.getStructuredText('blog-post.body').asHtml(getLinkResolver(), htmlSerializer);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment