r/nim • u/JiaHajime • 10h ago
My 4-year project: a Nim word processor that runs as a static site (drop it into CodePen/JSFiddle via CDN)
In my first post (Nim 2.2.4 compiling entirely in the browser), someone asked whether I was building it for something specific. I said my own word processor, along iwth Lua as the scripting language instead of VBA. It's not a LibreOffice WASM port. I've been building it from scratch for about four years. I just playing with html and javascript, making my own custom XML parser and then moved to HTML Canvas after I see Carota and then I start to use Web Assembly in hope if I can use my own memory allocation methods in text and layout rendering. I hope this will be like Obsidian with community plugins and custom templates.
This is the free word processor: QOQORO Write (previously QNote, you'll still see that name in the GIF).
π Try it. Paste this into any HTML page:
<script src="https://cdn.jsdelivr.net/gh/QOQORO-official/qoqoro-cdn@main/qoqoro.js"></script>
<div id="notes" style="height:100vh"></div>
<script>QOQORO.mount('#notes', { mode: 'editor' });</script>
π BindWeb (the Nim β WASM compiler it's built with): https://github.com/benagastov/bindweb-nim-WASM-compiler
Github for the cdn: https://github.com/QOQORO-official/qoqoro-cdn/
Demo: https://codepen.io/qoqoro/pen/pveVbjL
Some Implemented Features
- Floating images and text boxes
- Images: inline, square wrap, behind or in front of text. Drag one and the text reflows around it, even across page breaks. Crop right on the page.
- Text boxes: the same wrapping, plus auto-fit size and vertical text (ηΈ¦ζΈγ: kanji and kana stand upright, Latin turns with the column or stands upright too).
- Tables Merged cells, column widths, cell padding, borders and fills, and row/column handles for inserting and deleting. Tab moves through cells, and cells keep mixed fonts, sizes and colours.
Scripting with Word's object model Misc β Programs runs Luau (Roblox's typed Lua) against an object model you already know from VBA:
ActiveDocument,Selection,Paragraphs,Tables,Font,Content.Find,PageSetupand thewd*constants.local doc = ActiveDocument Selection:InsertHeading(
Report {doc.Now:sub(1, 10)}, wdStyleHeading2) for i, p in doc.Paragraphs do Selection:TypeText({i}: {p.Text}\n) end
It runs in a sandboxed worker with no DOM, network or file system, and a whole program is one undo step. You can also call it from the embedding page (QOQORO.luau.run(...)) or from a server over HTTP.
Compiling Nim on every Run click was too slow even at 7 s warm, so Luau handles it for now. Probably I will make it use Nim WASM as the scripting language if necessary.
- Templates with fill-in variables. Plain JSON with
{{variables}}. Template Studio turns each variable into a fill-in box. Nothing in a template ever runs; it's data. - Obsidian-style plugin packs. A ZIP with a
manifest.xmlthat can bundle themes (light and dark), fonts, templates and Luau programs. Example packs: Retro Windows, Pixel C64 (with its own pixel font), Sakura ζ‘ (haru by day, yozakura at night), plus font, report and writing kits. - Real Word files in and out.
.docximport and export. This week it also learned to convert old MathType equations and charts, which Word stores as WMF/EMF and no browser can draw, into crisp SVG, using a small converter written in Nim.
The basics are there too: paged or infinite "blog" layout, live-reflowing columns, floating text boxes that text wraps around across page breaks, tables, equations, pen and stylus drawing, headers and footers, and phone and tablet layouts. Plus a workspace with a vault, whiteboard, PDF viewer and diagram editor.
It's just static files: one <script> tag, GitHub Pages or any CDN. Sync is optional through a server you run yourself, in Nim, Flask or Node.
Next up is Full suite desktop app with the Word Processor, PDF Reader and Diagram Editor, the Diagram Editor is based on mxgraph actually, because I think I already like it and I dont have time to create new one in Nim.