Signal and noise in recipe markup

Structured data is the part of a food site that earns its traffic. Here is the shape of it.

<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "Recipe",
  "name": "Cacio e pepe",
  "recipeYield": "2 servings"
}
</script>

And the PHP that emits it:

<?php
if ( $a < $b && $b > 0 ) {
    echo '<span class="qty">' . esc_html( $qty ) . '</span>';
}
?>

A JavaScript template literal containing markup, which is where most escaping bugs finally surface:

const row = `<li>${qty} &times; ${item}</li>`;
if (a && b) render(row);

Every angle bracket above is stored as &lt; or &gt;. A converter that HTML-unescapes one step too eagerly turns these samples into markup and destroys them silently.

By Tomás Lindqvist

Baker. Writes about fermentation and patience.

Leave a comment

Your email address will not be published. Required fields are marked *