fix(author): store plain text boxes as plain text, though their fields list tags

Merged
AL
10d ago
+162-32

Closes #164

Changes

  • The rule (packages/author/lib/text.mjs): editorWidget(field) is the widget H5P's editor draws a field with: widget ?? type, or for a ShowWhen, the widget inside it. takesMarkup(field) is true only where that widget is html and the field lists tags. Both are exported from ./core, for a tool beside the build.
  • The build (generator.mjs): written text is markup only where takesMarkup says so; everything else is stored as plain text. Its problem messages name the kind the same way.
    • Saved content (checkContent) still goes by tags, as the content check keeps it.
    • Defaults also still go by tags: the editor puts a default in unescaped, and the server filters it by tags (translate.mjs, comment only).
  • Apostrophes (plainText(value, note, { filtered })): in a plain box whose field lists tags, ' is stored as typed. The editor's box would write ', which H5P.Components 1.0.101 (upstream's newest) shows as written; the content check's filter keeps a bare apostrophe.
    • " stays ": ns.createText puts a stored value back into value="…" unescaped, so a bare quote would cut the text short in the editor.
    • &, < and > stay escaped, as the filter would escape them, with a note saying to write "and" and “ ” instead.
  • The type file: H5P.QuestionSet.md, regenerated by sync:skill. introPage.title, endGame.message and the two old greetings are now text, not html: …; the other type files came out unchanged.
  • design/author.md: the text rule now names the widget, plus a new point with the census and the apostrophe rule.

Testing

  • pnpm --filter @missing-elements/h5p-author test: 153 passed, browser tests included. New tests:
    • takesMarkup and editorWidget against Question Set's and Speak the Words Set's field shapes;
    • plainText with filtered;
    • a Question Set build: the title and results heading stored plain, the introduction still <p>, markup noted, and a German title with umlauts, „“, & and ".
  • pnpm --filter @missing-elements/h5p-skills test: 77 passed: the type files are current, and every example builds and plays untrusted.
  • pnpm --filter @missing-elements/h5p-author typecheck: clean.
  • The same Question Set source, played by the verifier:
    • 0.5.0's cover shows <div>World War II: Five Historic Events</div>; this branch shows the title alone.
    • A German title with umlauts and ß, and "Germany's Surrender", show correctly, played trusted and untrusted, with no warnings.
  • Umlauts are stored as typed throughout. Neither the editor nor the platforms escape them, and the test above covers them.

Not verified: the results page in a browser (the stored value is tested, and ResultScreen draws it with textContent, as the cover does), and a Moodle upload of a fixed package.

Release

A fix, so author 0.5.1. It also adds takesMarkup and editorWidget to ./core and an option to plainText, none of them breaking. After publishing:

  • embed-my.github.io's build page needs the bump, still on 0.5.0 and showing the <div>. Its branch fix/build-page-file-names is ready, with download names that keep umlauts.
  • Run npx skills update -g for the regenerated type file.

Summary by cubic

Fixes text fields that list tags but are plain text boxes in H5P's editor being stored as markup, which showed <div>World War II: Five Historic Events</div> on Question Set's cover.

Bug Fixes

  • New takesMarkup and editorWidget decide from the editor's widget whether a field holds markup; the build, its problem messages, and the type files use them.
  • Saved content and defaults still go by tags, as the content check and server keep them.
  • In a plain box whose field lists tags, an apostrophe is stored as typed; ", &, <, and > stay escaped and are noted.
  • Regenerated H5P.QuestionSet.md: the intro title, results heading, and two old greetings are now text, not html.
  • A census in design/author.md counts the pack's 1,252 text fields whatever widget draws them, and names these five as the only ones stored otherwise than their widgets store them.