diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index f1690eae1..2bbe2581b 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -79,6 +79,17 @@ jobs: if [ -f "$PLUGIN" ]; then yq -i '.project.plugins = [env(PLUGIN)]' myst.yml fi + # The lecture sources still carry Sphinx `{raw}` blocks, whose source + # mystmd shows to the reader as escaped text under the page title. They + # are rewritten out of the sources at cutover, so the preview runs the + # same script and shows post-cutover content. It exits non-zero on a + # block it does not recognise, which fails the preview rather than + # publishing a page with literal markup on it. + - name: Rewrite `{raw}` blocks out of the lecture sources + if: github.event.action != 'closed' + working-directory: preview-content/${{ env.CONTENT_DIR }} + run: node ${{ github.workspace }}/scripts/rewrite-raw-blocks.mjs . + - name: Build static site if: github.event.action != 'closed' working-directory: preview-content/${{ env.CONTENT_DIR }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d5e00b8e..142d4fc2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 that declares the part replaces the whole default, credit included, which is how a site states other terms ([#203](https://github.com/QuantEcon/quantecon-theme.mystmd/issues/203)). +- `scripts/rewrite-raw-blocks.mjs`, which rewrites Sphinx `{raw}` directives + out of lecture sources: it deletes the notebook logo header in both its + `{raw} jupyter` and `{raw} html` forms, turns an Our World in Data chart into + the native `{iframe}` directive, and unfences a `colspan`/`rowspan` table so + mystmd's HTML transform renders it. Any other `{raw}` block is reported with + its file and line and nothing is written. mystmd renders no `raw` node, so + until now a block's own source reached the reader as escaped text under the + page title. The PR preview runs the script over the lecture content it + builds, so previews show post-cutover sources and every theme PR exercises it + ([#204](https://github.com/QuantEcon/quantecon-theme.mystmd/issues/204)) ([#222](https://github.com/QuantEcon/quantecon-theme.mystmd/pull/222)). ## [2.7.0] - 2026-09-11 diff --git a/scripts/rewrite-raw-blocks.mjs b/scripts/rewrite-raw-blocks.mjs new file mode 100644 index 000000000..d675f5d9e --- /dev/null +++ b/scripts/rewrite-raw-blocks.mjs @@ -0,0 +1,247 @@ +#!/usr/bin/env node +// +// Rewrites `{raw}` directives out of QuantEcon lecture sources. +// +// `{raw}` is a Sphinx construct. mystmd parses the directive but renders no +// `raw` node, so a block's own source reaches the reader as escaped text under +// the page title, and the ipynb export drops it. Three shapes appear across the +// lecture repositories, and each has a mystmd-native equivalent or no reason to +// exist: +// +// * the notebook logo header (`