Skip to content

Preview: checkbox and text on separate lines, and checkboxes cannot be ticked #212

Description

@rustyqt

Title: Preview: checkbox and text on separate lines, and checkboxes cannot be ticked

Problem

Two things about checklists in the preview, on 27.0.0 (main, 9b693b2):

1. Every checkbox sits on its own line. HTMLFormatter wraps the text of a
list item in a paragraph and emits a bare <input type="checkbox"> without the
task-list-item class that the bundled GitHub stylesheet styles, so neither its
alignment rules nor its marker suppression apply. A note like

- [ ] Bread
- [x] Milk

renders with the box above its text and the list bullet still in front of it.

2. Checkboxes cannot be ticked in the preview. They are rendered disabled,
so a checklist can only be changed in the editor. The Android client allows
ticking them in its preview.

What I would like to contribute

I have both fixed and would open a PR if you are interested. The branch is
ready, based on current main:

The first one is a stylesheet change only.

For the second one, the preview deliberately forbids scripts from note content
(script-src 'none', covered by NotesPreviewSecurityTests), so a checkbox
cannot report a tap by itself. Rather than relax that policy, each checkbox is
wrapped in a link; the tap arrives as a navigation that PreviewWebView
cancels and turns into toggling the source line. The link carries its line
number and the state it was rendered with, and a toggle that no longer matches
the note is ignored instead of applied to the wrong line. The CSP stays as it
is.

Updating the page replaces the body of the live document from the app's own
WKContentWorld instead of reloading, so the reader keeps their position in a
long list. A test asserts that this still works while note content cannot run
scripts. Links are announced as checkboxes to VoiceOver (role, aria-checked,
aria-label from the entry text), and read only notes do not react to a tap.

New files go to iOCNotes/ as the repository structure suggests for new code,
which also means project.pbxproj is untouched. No new user facing strings, so
nothing changes for Transifex. 11 new tests, suite green.

Questions

  1. Would you prefer one PR or two, with the stylesheet fix separate?
  2. The preview currently receives only the note text. To write a toggle back I
    added a closure the editor passes in. If you would rather have the Note
    itself passed to the preview, I will do it that way instead.

Side finding

.swiftlint.yml pins the copyright year in file_header to 2025, so any file
written in 2026 fails the check and the SwiftLint workflow with it. I have a
one line commit relaxing it to 20\d{2}, which I can leave out if you prefer
to handle that separately.

Disclosure

The implementation was written with AI assistance (Claude Code); the commits
carry Co-Authored-By trailers accordingly. I have reviewed and tested
everything I am proposing.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions