-
-
Notifications
You must be signed in to change notification settings - Fork 212
Inside live preview
Quarkdown's webserver allows direct communication between the compiler's CLI and the browser, making live previewing possible.
In particular, it exposes the following endpoints:
-
/:file
: Serves static files, relative to the target file (-f
option ofquarkdown start
). -
/live/:file
: Similar to the previous one, but wraps HTML files in a wrapper, suitable for live reloading. -
/reload
: WebSocket endpoint for live reloading.- Browsers connected to the
/live
endpoint start listening, and reload the page when it receives a reload message. - The CLI connects to this endpoint and sends a message every time a compilation is performed. When it does so, the server broadcasts a reload message to all connected browsers.
- Browsers connected to the
When serving a file through the /live/:file
endpoint, the server wraps HTML files in a simple HTML wrapper that displays the content of /:file
in an iframe.
Additionally, a small script establishes a persistent WebSocket connection to the /reload
endpoint. This script listens for reload messages and triggers a reload of the iframe content when a message is received.
sequenceDiagram
participant Browser
participant Server
participant CLI
Browser->>Server: GET /live/:file
Server-->>Browser: Live preview HTML wrapper
Browser->>Server: WebSocket connect /reload
CLI->>Server: WebSocket message /reload
Server->>Browser: WebSocket broadcast /reload
Browser->>Browser: Reload iframe content
When an iframe is reloaded, an unpleasant flickering effect can occur. In order to grant a smooth user experience, Quarkdown employs a technique called double buffering.
For context, you are constantly exposed to double buffering: your GPU renders the next frame to an off-screen buffer while displaying the current frame. Once the next frame is ready, the buffers are swapped, resulting in a smooth transition without flickering.
The same way, Quarkdown holds two iframes, A
and B
.
Let's say A
is currently being displayed. When a change is detected, Quarkdown renders the updated content into B
while A
is still visible. Once the rendering is complete, the displayed iframe is switched from A
to B
, providing a seamless update.
Also, before swapping the buffers, the scroll position from the previous frame is preserved and restored in the new frame, so the user doesn't lose their place.
- Figures
- Image size
- TeX formulae
- Table caption
- Code caption
- Decorative headings
- Alerts (quote types)
- Quotation source
- Cross-references
- Page breaks
- Text symbols (text replacement)
- Document metadata
- Theme
- CSS
- Fonts
- Page format
- Page margin content
- Page counter
- Automatic page break
- Numbering
- Paragraph style
- Caption position
- Table of contents
- Bibliography
- Footnotes
- Stacks (row, column, grid)
- Container
- Align
- Float
- Figure
- Clip
- Box
- Collapsible
- Landscape
- Whitespace
- Variables
- Optionality
- Math
- Conditional statements
- Loops
- Let
- Destructuring
- String manipulation
- Table manipulation: sorting, computing, and more
- Generators
- String
- Number
- Markdown content
- Boolean
- None
- Enumeration entry
- Iterable
- Dictionary
- Range
- Lambda
- Size(s)
- Color
- Dynamic
- Paper: abstract, definitions, theorems, and more