Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@prairielearn/html

Package Overview
Dependencies
Maintainers
2
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@prairielearn/html

Utilities for easily rendering HTML from within JavaScript.

Source
npmnpm
Version
4.0.24
Version published
Maintainers
2
Created
Source

@prairielearn/html

Utilities for easily rendering HTML from within JavaScript.

Usage

The html tagged template literal can be used to render HTML while ensuring that any interpolated values are properly escaped.

By convention, HTML templates are located in *.html.ts files.

// Hello.html.ts
import { html } from '@prairielearn/html';

export function Hello({ name }: { name: string }) {
  return html`<div>Hello, ${name}!</div>`;
}

This can then be used to render a string:

import { Hello } from './Hello.html.ts';

console.log(Hello({ name: 'Anjali' }).toString());
// Prints "<div>Hello, Anjali!</div>"

Using escaped HTML

If you want to pre-escape some HTML, you can wrap it in escapeHtml to avoid escaping it twice. This is useful if you want to inline some HTML into an attribute, for instance with a Bootstrap popover.

import { html, escapeHtml } from '@prairielearn/html';

console.log(html`
  <button data-bs-toggle="popover" data-bs-content="${escapeHtml(html`<div>Content here</div>`)}">
    Open popover
  </button>
`);

Why not EJS?

In the past, PrairieLearn used EJS to render most views. However, using a tagged template literal and pure JavaScript to render views has a number of advantages:

  • Prettier will automatically format the content of any html tagged template literal; EJS does not have any automatic formatters.
  • Authoring views in pure JavaScript allows for easier and more explicit composition of components.
  • It's possible to use ESLint and TypeScript to type-check JavaScript views; EJS does not offer support for either.

If you want to use existing EJS partials inside of an html tagged template literal, check out the @prairielearn/html-ejs package. EJS-related functionality is deliberately located in a separate package so that @prairielearn/html can be used in the browser, since the ejs package makes use of Node-only features. Note, though, that this package is no longer used in PrairieLearn itself, and as such will no longer be actively maintained.

FAQs

Package last updated on 15 Jan 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts