Repository navigation
Turn markdown on by default - #13
Open
sanjaydotpro wants to merge 48 commits into
Open
sanjaydotpro wants to merge 48 commits into
sanjaydotpro wants to merge 48 commits into
Conversation
The field works out its semantics information, an entry for every run of the note's text, each time its semantics are marked dirty, and it marks them for every widget it takes in. Opening a note walked the whole of it once for each picture in it, whenever the semantics tree is on, and in the macOS app it always is: AccessibilityTree.swift switches it on at launch so that dictation tools can write into the editor. The span the controller builds now works the information out once and keeps it. Formulas, drawn as widgets in the text by the commits that follow, are where it shows: in a debug build, a 5,000-line note with 350 of them opened in 16.1 s without this and in 4.8 s with it.
A note pasted from ChatGPT, Gemini or Wikipedia writes its maths as $…$ among words and $$…$$ set apart. Both are now read as formulas, by the rules pandoc reads them by, so that a note about money keeps its prices: the opening $ of $…$ has no space after it, and the closing one no space before it and no digit after it, which keeps "$5 and $10" two prices rather than one formula. A $$ starting a line opens a block that runs to the $$ ending one, with no blank line between, so the lines of an aligned equation stay TeX rather than becoming a list. A formula is literal, the way code is: its TeX is shown in code's face with its dollar signs quiet, the calculator reads none of it, and spelling leaves it alone. In a table's cell it stays its TeX. dart_markdown reads plain words in runs until it is given an inline syntax of its own, and then a word at a time, in case that syntax starts at a space or a letter. The dollar sign's never does, so a syntax for runs of words keeps the reading of a long note as quick as it was: otherwise every word becomes a text node of its own, and the parse of a 5,000-line note takes more than twice as long.
A formula outside a table is now drawn by flutter_math_fork where its TeX was, a tenth bigger than the words around it and in their colour: among words on their baseline, and set apart in the middle of a line of its own, centred across the writing column. With the caret in it, it shows its TeX again. TeX it cannot read stays written out in code's face, never an error box, and a formula wider than the column is drawn smaller rather than cut off. A text engine has to be told how big every placeholder is before it breaks lines, and everything that measures the note apart from the field has only the numbers, so each formula is laid out once in a widget tree of its own that is never shown, and its size kept. Its widget is kept too, one for every formula in the note: flutter_math_fork keys what it builds with a GlobalKey held in the parsed TeX, so one widget in two places would take its lines from the first. What pandoc and Wikipedia write that flutter_math_fork does not read is read as what it has: align, alignat and split become aligned and alignedat, an equation's environment goes, \sgn is the sign function, and a phantom of a sized delimiter written without braces gets them. A formula's glyphs stay out of the semantics tree, where the note's text already gives its TeX. A note with a formula gives up the forced one-line strut, as one with a picture or a table does, so that moving the caret onto a formula never moves every line. flutter_math_fork is Apache-2.0. The KaTeX fonts it bundles, about 660 KB, are MIT, and their notice now ships with the app.
A fenced code block whose info string names one of 35 languages, or one of highlight.js's names for them (py, ts, sh, yml and the like), is coloured by re_highlight, highlight.js's grammars ported to Dart. Its keywords, strings, numbers, comments, titles, types and punctuation take their colours from the note's own palette, so code reads the same in light and dark rather than in some editor's theme. A block is coloured once for as long as its language and its code stay the same, so typing in one block leaves the rest alone. A block with no language, or one it does not know, stays plain code.
A <u> or <ins> closed among the same words underlines them, and <sup> and <sub> raise and lower them. The tags hide like any inline marker, showing again with the caret against them, and the calculator reads the words without them. A tag that is never closed, or that crosses another, stays the HTML it is written as, and other inline HTML looks as it did. A text engine cannot move words off their baseline, so a superscript uses the face's own raised glyphs where it has one for every character: digits in Shantell Sans, and digits, small letters and +=() in the system face on Apple's platforms. Anything else is drawn smaller on the baseline. Either way the line keeps its height. A table's grid draws them too, so its run style is now told the words it styles.
<br>, <br/> and <br /> in a GFM table's cell start a new line of it, whether the grid fits its columns to the page or keeps their natural widths, and the room the note keeps for each row is measured from the same lines, so the two agree. At natural widths, where a cell is otherwise cut to one line, each of its lines is cut short with an ellipsis of its own, since a painter only shortens the last line it may draw. Outside a table a <br> is shown as written, as before. A random test now checks that a note mixing formulas, HTML, tables and fenced code is read the same in pieces as whole.
One note with formulas among words and set apart, TeX that does not parse, prices, <u>, <sup> and <sub>, a Python block, and a table with a <br> and a formula in its cells: drawn in dark, in light, and in dark with the caret in the display formula, which then shows its TeX.
benchmark/markdown_rendering.dart opens a 5,000-line note with 350 formulas and 30 fenced code blocks three times, then types into it a key every 33 ms in prose, in a code block and after a formula, and prints how long each opening took to its first frame and how long the typing frames took to build and to draw. It is an app rather than a test, because only profile mode says anything about frame times, and its header says how to run it under a bundle id of its own. On an M3 Pro, with the semantics tree on as it always is in the app, main opened the note in 1.6 to 1.8 s after its first opening and this branch in 2.0 to 2.2 s, and a key in it took about 2 s to draw on both.
Real headless-Chrome captures (Wikipedia, ChatGPT, Gemini, Perplexity, GitHub, Google Docs/Sheets, MDN, Ask Ubuntu, emoji), synthesized native-app payloads (Word, Outlook, Excel, Numbers, Apple Notes, Pages, Safari, Slack, Gmail, VS Code, Finder, images), and the scripts that produced them, including a read-only macOS pasteboard capture script.
Reads the clipboard's richest useful representation (an editor's code, HTML, rich text, markdown text, plain text) and writes it as markdown for a markdown note or as words plus heading, bold and italic ranges for a plain one. Covers AI chats' math (KaTeX annotations, MathML, data-math), Word lists, Google Docs code, GitHub task lists, Apple's sized headings, emoji pictures and SVG badges.
The first pasted line joins the line at the caret and takes its kind, list items continue the list, quotes stay quoted, and code and table cells only take words.
A pasted picture from the web is held by a ref that remembers its address (NoteImageRef.src). It is fetched at paste time, at most four at once, and a failed download keeps its place with a Retry button.
Paste reads the whole clipboard at once, converts it off the UI isolate when it is large, and inserts it as one undoable edit with picture placeholders. Pasting into a table cell keeps line breaks as <br>, and Cmd/Ctrl+Shift+V pastes the words only.
The rich clipboard channel gets a read method returning text, HTML, the source URL, Safari's web archive, RTF and RTFD converted to HTML with their pictures, VS Code's metadata, Kapy's own fragment, file URLs and an image. Write also publishes Kapy's fragment type and can target a named pasteboard, which the new tests use.
HTML Format with its header, Unicode text, dropped files, Kapy's registered fragment format, and a picture: the PNG format when an app published one, else the bitmap encoded as PNG with WIC. Write also publishes Kapy's fragment as UTF-8.
The same snapshot as macOS, fetched with one items call so iOS asks for permission to paste at most once. Write also publishes Kapy's fragment type and can target a named pasteboard.
The first item's HTML and text, its content URI's bytes when that is a picture (up to 25 MB), and the clip's MIME types.
Electron pickles DataTransfer's custom types into org.chromium.web-custom-data, which is the only place a real VS Code copy carries vscode-editor-data.
Each fixture goes onto a private pasteboard as recorded and is read the way the channel reads. Snapshots with derived data are compared with macos-snapshot.json; update_macos_snapshots.sh regenerates them.
Apple Notes, Pages and TextEdit write public.html with the Cocoa HTML writer, which shows each picture by a file:/// URL of its name that no reader can open. The RTFD beside it holds the bytes, so they are read into resources under that URL even when the HTML itself is used.
Each fixture now carries expected.md and expected.plain.txt, the note a paste from it produces in a markdown note and in a plain one, and a test runs the whole corpus through the pipeline against them.
Undo and redo restore attachments from the refs the editor remembers each edit took out, and it kept only the latest 20. Undoing a paste of more pictures than that, or deleting a selection holding them, lost the rest on the way back. The newest edit's removals are now kept whole.
A picture moved onto a line of its own left the space before it at the end of the line above and the space after it at the start of the line below.
Unit tests for what each part of the paste pipeline promises, beside the fixture corpus that checks them together: the HTML reader's rules for each source, both writers, markdown text, the converter's choice of representation, MathML to TeX, and the downloader's limits.
A one-column table in a script position is what KaTeX draws \substack as. It was written back as a matrix, which typesets at full size under the operator.
Measured in a debug test run, a 32 KB markdown paste into a plain note took about 60 ms to convert, which is several frames. At 16 KB the worst path takes about 30 ms in debug, and less in a release build.
A rich paste lands in the note's own format with its carried picture in place, and a web picture that can't be fetched keeps its place, its address and a Retry button.
A note already waits to sync until every picture in it is uploaded, and a picture still at its address has nothing to upload. So NoteImageRef.src stays on the device and the sync contract is unchanged. The field's comment said otherwise; a sync test now holds the real behaviour in place.
Beside Retry, Open link takes the address to the browser, for a picture whose link has expired or needs a sign-in the app doesn't have.
KaTeX's MathML spells the spaces inside \text{} as U+00A0. Written back into TeX they were invisible characters a renderer may not draw as spaces.
Gemini sizes its file-chip icons in rem, so they read as having no size and came in as full-width pictures instead of being dropped with the other icons.
A selection of a Stack Exchange answer brought its posters' 32 px avatars in as pictures. A small picture whose alt text or class says avatar, or one from Gravatar, says who wrote something rather than what they wrote.
A dash or two under a line of words is a bullet or a divider on its way, so the line above no longer flashes into a heading while it is typed. An escape's backslash is no longer read by the calculator, so \- 5 is the minus five it shows.
[x] makes a ticked task, a fence and Return writes its closing fence, and --- under words gets a blank line so it stays a divider. Backspace or Undo straight after a shortcut gives back what was typed, escaped so it stays text. Nothing converts while an input method is composing.
The gutter's line positions came from laying the whole note out a second time on every keystroke, as costly as the field's own layout. A hard line break means no line's wrapping depends on another, so each line is laid out on its own and kept until it changes. Typing in a 5,000-line markdown note in profile mode goes from about 3.1 s to 1.6 s a keystroke.
Runs in profile mode under flutter run; never run by CI.
writeHtml says what HtmlPasteReader reads, in the HTML Google Docs, Word, Gmail and Notion paste: a to-do is the ☐ or ☑ it looks like, code keeps its language class, tables keep their header row and alignment, and math is its TeX between dollars, marked with the TeX in data-latex. Embedded characters stand in for a note's pictures, which hold their place as one character.
noteHtml renders a note for copying out: a markdown note through the markdown reader, read the way the editor reads it (math only between dollars, a star between operands is multiplication), and a plain note through its own format, with the bold, italic, heading and subtitle it keeps beside the text. convertNote rewrites a note's text for a note of the other kind through the paste writers, keeping every attachment's place.
A fragment copied out of a note now writes the kapy type beside its HTML and text: versioned JSON with the body, its format ranges, whether it came from a markdown note, and each attachment's ref with the bytes a paste stores. Where the source note keeps an attachment, and the key that seals it, stay out of it; reading it back recomputes the hash and refuses anything malformed or past the copy caps. The HTML is now the note as noteHtml renders it, each picture a data URI at the width the note shows it, and it still opens with the v1 marker so an older build pastes the pictures back. The plain text is a markdown note's own markdown with ![image] for each picture, or a plain note's own text. fromSnapshot prefers the kapy type to the marker, and a fragment of 32 KB or more is written and read on another isolate.
Ctrl-C and Ctrl-X, the menu's Copy and Cut, and the selection toolbar's Copy now write the whole fragment for any selection rather than only one holding a picture; Copy plain text is unchanged. Files, voice notes and videos travel with their bytes while the selection keeps to the fragment caps, and past them each is copied as its label, with a toast saying so. Pasting a fragment rebuilds it as one edit, and so one undo step: its styles come back, pictures are stored again at their width, files and videos go in as dropped ones do and voice notes as recordings do. A fragment from a note of the other kind is converted on the way in. A keyboard copy now leaves the formatting toolbar up, as the field's own copy does.
A device that never stored the setting gets markdown. The setter only ever stored a real change, so a stored false means the writer switched it off, and it stays off. No note text changes either way.
sanjaydotpro
force-pushed
the
capy/faithful-paste
branch
from
November 17, 2026 06:45
d85aef8 to
a0df289
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hold: merge only after the per-line editor (HIS-14). Typing in long markdown notes is still slow, so markdown stays off by default until that lands. Stacked on #12.
A device that never stored the markdown setting now gets markdown. The setter only ever stored a real change, so a stored
falsemeans the writer switched markdown off, and it stays off. No note's text changes either way.What changes for the calculator
With markdown on, the calculator reads a note the way it's shown. The release notes need to say so:
-is a bullet, not a minus sign.- 5used to show −5, and now shows no result.-5still works, and Backspace straight after typing-keeps the minus.~~5~~ 7only the 7 is read.*between numbers still multiplies, so2*3*4andprice * 3work as before.Testing
Flutter 3.47.4 (
~/dev/flutter) afterflutter pub get --enforce-lockfile. The pinned 3.47.2 is damaged on this Mac.flutter analyzeis clean. The full suite passes 2,300 tests, and the only failures are the 45 goldens that also fail on main under 3.47.4.