From 1197d5ed95e244e88dfa4cd6f15f662707707147 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Mon, 19 Oct 2026 14:32:03 -0500 Subject: feat(reveal): fit dense slides to the canvas instead of clipping them reveal.js lays each slide out on a fixed canvas and clips whatever runs past the bottom. At the stock 42px font a slide held about six lines. Anything past that vanished with no sign it was missing. I made three changes in org-reveal-config.el. The canvas is now 16:9 (1280x720), so lines wrap later. The head preamble sets a 30px base font and smaller headings through the theme's CSS variables, so any reveal 4+ theme picks them up. A script spliced in after Reveal.initialize measures every slide once reveal is ready and shrinks any that still overflows, down to a floor of half size. A slide that overflows even there gets a console warning. A slide that fits stays at full size. The script stays out of overview and print view, where reveal lays slides out differently and a measurement means nothing. The header template now emits the same init options as the global default and turns off ^ markup, so snake_case identifiers in slide text stop exporting as subscripts. A file that already carries its own #+REVEAL_INIT_OPTIONS keeps them. The preamble and the fit script apply to every export. --- tests/test-org-reveal-config-header-template.el | 6 + tests/test-org-reveal-config-sizing.el | 239 ++++++++++++++++++++++++ 2 files changed, 245 insertions(+) create mode 100644 tests/test-org-reveal-config-sizing.el (limited to 'tests') diff --git a/tests/test-org-reveal-config-header-template.el b/tests/test-org-reveal-config-header-template.el index 9bda10db..b7ceff53 100644 --- a/tests/test-org-reveal-config-header-template.el +++ b/tests/test-org-reveal-config-header-template.el @@ -144,5 +144,11 @@ "Nil title should signal an error rather than silently producing garbage." (should-error (test-reveal--header nil) :type 'user-error)) +(ert-deftest test-org-reveal-config-header-template-normal-keeps-underscores-literal () + "Normal: #+OPTIONS: turns off ^ markup so snake_case identifiers in slide text stay literal. +Without it a heading like event_payloads_ais exports as event with a subscript." + (let ((result (cj/--reveal-header-template "My Talk"))) + (should (string-match-p "^#\\+OPTIONS:.*\\^:nil" result)))) + (provide 'test-org-reveal-config-header-template) ;;; test-org-reveal-config-header-template.el ends here diff --git a/tests/test-org-reveal-config-sizing.el b/tests/test-org-reveal-config-sizing.el new file mode 100644 index 00000000..ea27b718 --- /dev/null +++ b/tests/test-org-reveal-config-sizing.el @@ -0,0 +1,239 @@ +;;; test-org-reveal-config-sizing.el --- Tests for reveal.js slide sizing and auto-fit -*- lexical-binding: t; -*- + +;;; Commentary: +;; Dense slides overflowed reveal.js's 960x700 canvas at the theme's 42px +;; base font and were clipped with no way to scroll. The module now ships +;; a 16:9 canvas with a smaller base font (via the head preamble) and a +;; script, spliced in after Reveal.initialize, that shrinks any slide whose +;; content still overflows. These tests pin the three builders and run the +;; fit algorithm under node against a stub Reveal API. + +;;; Code: + +(require 'ert) +(require 'cl-lib) +(require 'json) + +(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) +(require 'keybindings) +(require 'org-reveal-config) + +(defun test-org-reveal-config--count (regexp string) + "Return how many times REGEXP matches in STRING." + (let ((n 0) (start 0)) + (while (string-match regexp string start) + (setq n (1+ n) + start (match-end 0))) + n)) + +;; ------------------------------ Init options ------------------------------- + +(ert-deftest test-org-reveal-config-init-options-normal-has-behaviour-and-canvas () + "Normal: the shared init options carry slide numbers, hash, transition and the canvas size." + (let ((opts (cj/--reveal-init-options))) + (should (string-match-p "slideNumber:true" opts)) + (should (string-match-p "hash:true" opts)) + (should (string-match-p (format "transition:'%s'" cj/reveal-default-transition) opts)) + (should (string-match-p (format "width:%d" cj/reveal-canvas-width) opts)) + (should (string-match-p (format "height:%d" cj/reveal-canvas-height) opts)))) + +(ert-deftest test-org-reveal-config-init-options-boundary-splices-into-initialize () + "Boundary: one line, no trailing comma, so it splices into Reveal.initialize({...})." + (let ((opts (cj/--reveal-init-options))) + (should-not (string-match-p "\n" opts)) + (should-not (string-suffix-p "," (string-trim opts))))) + +(ert-deftest test-org-reveal-config-init-options-normal-canvas-is-16-9 () + "Normal: the canvas is a 16:9 frame, the shape of every projector and monitor the slides land on." + (should (= (* 9 cj/reveal-canvas-width) (* 16 cj/reveal-canvas-height)))) + +(ert-deftest test-org-reveal-config-header-template-normal-uses-shared-init-options () + "Normal: the header template emits the same init options as the global default, so a file never drifts from the module." + (let ((result (cj/--reveal-header-template "Sizing"))) + (should (string-match-p + (format "^#\\+REVEAL_INIT_OPTIONS: %s$" + (regexp-quote (cj/--reveal-init-options))) + result)))) + +;; ------------------------------ Head preamble ------------------------------ + +(ert-deftest test-org-reveal-config-head-preamble-normal-sets-font-sizes () + "Normal: the preamble lowers the theme's base font and heading sizes through the theme variables." + (let ((css (cj/--reveal-head-preamble))) + (should (string-match-p (format "--r-main-font-size: *%s" + (regexp-quote cj/reveal-base-font-size)) + css)) + (should (string-match-p "--r-heading1-size" css)) + (should (string-match-p "--r-heading2-size" css)))) + +(ert-deftest test-org-reveal-config-head-preamble-normal-keeps-no-caps-rule () + "Normal: the rule that stops the theme upper-casing headings survives the rewrite." + (should (string-match-p "text-transform: *none" (cj/--reveal-head-preamble)))) + +(ert-deftest test-org-reveal-config-head-preamble-boundary-one-style-element () + "Boundary: exactly one " css))))) + +;; -------------------------------- Fit script ------------------------------- + +(ert-deftest test-org-reveal-config-fit-script-normal-hooks-reveal-events () + "Normal: the script fits every slide once reveal is ready and refits on each slide change." + (let ((js (cj/--reveal-fit-script))) + (should (string-match-p "Reveal\\.on('ready'" js)) + (should (string-match-p "Reveal\\.on('slidechanged'" js)) + (should (string-match-p "Reveal\\.on('overviewhidden'" js)) + (should (string-match-p "isOverview" js)) + (should (string-match-p "scrollHeight" js)) + (should (string-match-p "getConfig()\\.height" js)))) + +(ert-deftest test-org-reveal-config-fit-script-boundary-no-script-tags () + "Boundary: ox-reveal splices the text inside its own