Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Also online at [p10node.github.io/office-engine](https://p10node.github.io/offic
- **Microsoft Visio (view only)**: `.vsdx` drawings (also `.vsdm`, templates and stencils) open read-only, a slide per page: shapes with their geometry (lines, arcs, ellipses, Béziers, NURBS), masters, groups, connectors with line ends, fills, gradients, themes, text, pictures, background pages and layers; *Download as* PowerPoint saves the converted file
- **CSV, text, Markdown, HTML, SVG**: `.csv` / `.tsv` open as a workbook (streamed: a million rows in about 2 s; past 12 million cells the rows are read from the file as they are shown, so there is no row limit), `.txt` / `.md` / `.html` as a document, `.svg` / `.svgz` as a picture (`.gz` files are unpacked first), from any `src` (file, Blob, URL); format from the extension, MIME type or content; UTF-8 / UTF-16 / Windows-1252; editable. Markdown, HTML and SVG are saved back in their own format (CSV and text as `.xlsx` / `.docx`)
- **Diagrams as code**: `.mmd` (Mermaid), `.puml` (PlantUML), `.dot` / `.gv` (Graphviz) open as a document with the drawing; ` ```mermaid ` / ` ```plantuml ` / ` ```dot ` blocks in Markdown and `<pre class="mermaid">` in HTML are drawn too. Drawn by a built-in layout engine in the worker: no server, no network, no dependency
- **Math in Markdown**: `$…$` and `$$…$$` TeX formulas are drawn as equations (the browser's own MathML: selectable, read by screen readers, printed); the document stays editable around them and saves each formula back exactly as it was written. Currency (`$5 and $10`), `\$` and code are left alone; a formula that cannot be read shows its source. *Download as* Word gives real Word equations
- **Code side by side**: Markdown, HTML, SVG and diagram files show their source next to the document (**Code** button); edit it and the document is rebuilt as you type; edit the document and the Markdown / HTML is built again from it
- **File menu**: new, open (also DOC / XLS / PPT / RTF / OpenDocument / Pages / Keynote / Numbers / Visio / CSV / text / Markdown / HTML / SVG / diagrams), import CSV, rename, download as PDF / HTML / text / CSV, document details, print
- **Comments**: threads with replies, resolve, edit / delete, @mentions; on DOCX text, XLSX cells and PPTX slides, stored in the file the way Word, Excel and PowerPoint store them
Expand Down Expand Up @@ -104,7 +105,7 @@ The renderers also ship on their own, to show diagrams and Markdown in any page
| [`@p10node/mermaid`](packages/mermaid) | Mermaid → SVG | 26 KB |
| [`@p10node/plantuml`](packages/plantuml) | PlantUML → SVG (no Java) | 29 KB |
| [`@p10node/graphviz`](packages/graphviz) | Graphviz DOT → SVG (no WebAssembly) | 16 KB |
| [`@p10node/markdown`](packages/markdown) | Markdown → safe HTML, diagram code blocks drawn | 39 KB |
| [`@p10node/markdown`](packages/markdown) | Markdown → safe HTML, diagram code blocks drawn, TeX math as MathML | 53 KB |

```ts
import { render } from '@p10node/mermaid'
Expand Down
2 changes: 1 addition & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ const { svg, width, height } = render('sequenceDiagram\n Ann->>Ben: hi') // lan
renderPage() // <pre class="mermaid">, <code class="language-dot">… of the page become drawings

import { render as markdown } from '@p10node/markdown'
el.innerHTML = markdown(text) // safe HTML; ```mermaid / ```plantuml / ```dot drawn
el.innerHTML = markdown(text) // safe HTML; ```mermaid / ```plantuml / ```dot drawn, $…$ / $$…$$ math as MathML
```

## CSP
Expand Down
1 change: 1 addition & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ src/core parsers, DOM-free (runs in worker / Bun)
legacy .doc / .xls / .ppt (compound file reader + converters), .rtf, OpenDocument → DOCX / XLSX / PPTX
iwork Pages / Keynote / Numbers → DOCX / PPTX / XLSX
visio Visio drawings (.vsdx) → PPTX
math TeX math: `$…$` / `$$…$$` in Markdown, TeX → MathML (views, web pages) and → OMML (Word file)
src/react view components
src/embed.ts mount() + <office-viewer>
src/collab real-time collaboration (hub, session, per-format adapters)
Expand Down
25 changes: 23 additions & 2 deletions docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ A `src` (file, Blob, buffer or URL) that is not an Office package opens too, con
|-------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `.csv`, `.tsv` / `.tab` | workbook, one sheet named after the file; the rows stream in as the file is read (a million rows open like a large workbook; past 12 million cells the rows are read from the file by pages as they are shown); numbers and booleans typed, codes like `007` kept as text |
| `.txt`, `.text`, `.log` | document, one paragraph per line |
| `.md`, `.markdown` | document: headings, lists, bold / italic / strike, links, code, quotes, tables (as tab-separated lines) |
| `.md`, `.markdown` | document: headings, lists, bold / italic / strike, links, code, quotes, tables (as tab-separated lines), TeX math (`$…$`, `$$…$$`) as equations (see [Math in Markdown](#math-in-markdown)) |
| `.html`, `.htm`, `.xhtml` | document: headings, paragraphs, lists, inline formatting and links; scripts and styles are dropped |
| `.svg` | the picture alone (no page), scaled down to fit the view, at its own size (`width` / `height` in any unit, else the `viewBox`) otherwise; the file is kept as it is, given the SVG namespace when it lacks one; *Download as* Word gives a document holding the picture |
| `.svgz`, `.csv.gz`, `.md.gz`… | the file inside: a gzip-compressed plain file is unpacked whole in the worker (native `DecompressionStream`), the name inside telling the format |
Expand All @@ -144,7 +144,28 @@ A `src` (file, Blob, buffer or URL) that is not an Office package opens too, con
- **Encoding**: the `encoding` open parameter when given (a `TextDecoder` label, e.g. `windows-1258`), else the byte order mark (UTF-8, UTF-16), the declared `charset`, UTF-8, else Windows-1258 when the bytes read as Vietnamese in it (tone marks after vowels: Excel's CSV on Vietnamese Windows; the text is put in NFC), else Windows-1252 (Excel's CSV on other Windows)
- **Columns**: a sheet holds 16,384 columns (up to XFD); the columns of a wider CSV after it are not loaded and the viewer says so (a message; `warning` event from the worker)
- The bar shows a `CSV` / `TSV` / `TXT` / `MD` / `HTML` / `SVG` badge
- **Saving**: a Markdown, HTML or SVG file is saved **as itself** (`.md` / `.html` / `.svg`, also what `onSave` receives). Markdown and HTML are built again from the document when it was edited there: headings, lists (nested), bold / italic / underline / strike, links, code, colors, tables, pictures (embedded as data URLs; a diagram block becomes its drawing); the text reads with its tracked changes accepted. An unedited file is saved as it is. CSV / TSV and text are saved as a workbook / document (`.xlsx` / `.docx`); *Download as* Word / CSV / text / Markdown gives the other formats
- **Saving**: a Markdown, HTML or SVG file is saved **as itself** (`.md` / `.html` / `.svg`, also what `onSave` receives). Markdown and HTML are built again from the document when it was edited there: headings, lists (nested), bold / italic / underline / strike, links, code, colors, tables, pictures (embedded as data URLs; a diagram block becomes its drawing), TeX formulas as they were written; the text reads with its tracked changes accepted. An unedited file is saved as it is. CSV / TSV and text are saved as a workbook / document (`.xlsx` / `.docx`); *Download as* Word / CSV / text / Markdown gives the other formats

### Math in Markdown

TeX formulas in a Markdown file are drawn as equations, by the browser from MathML (no font or script is loaded): selectable, read by screen readers, printed and exported like the text around them. The converter is the library's own (TeX → MathML, in the worker and the view), with no dependency.

| Written | Becomes |
|-------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
| `$…$` | an inline formula, when a non-space follows the opening `$` and the closing `$` has a non-space before it and no digit after it (pandoc) |
| `$$…$$` | a display formula (centered, on its own line); it may span lines, but not a blank one |
| `\$` | a dollar sign; `It costs $5 and $10` has no formula either |
| `` `$x$` ``, code block | code: nothing inside a code span, a fenced or an indented code block is math, and a `$` whose formula would end inside a code span is text |
| `\(…\)`, `\[…\]` | not math: in Markdown these are escaped brackets |

- **TeX read**: Greek letters and the usual symbols, operators, relations, arrows and dots; sub / superscripts and primes; big operators (`\sum`, `\prod`, `\int`, `\oint`, `\bigcup`…) with their limits under / over them in display style and beside them inline (`\limits`, `\nolimits`); `\frac`, `\dfrac`, `\tfrac`, `\binom`, `\over`, `\choose`; `\sqrt`, `\sqrt[n]`; `\left … \middle … \right` and `\big` … `\Bigg`; accents (`\hat`, `\bar`, `\vec`, `\tilde`, `\dot`, `\ddot`, `\widehat`, `\overline`, `\underline`, `\overbrace`, `\underbrace`, `\overset`, `\underset`, `\xrightarrow`…); `\text` (with `$…$` inside), `\mathrm`, `\mathbf`, `\mathit`, `\mathbb`, `\mathcal`, `\mathfrak`, `\mathsf`, `\mathtt`, `\boldsymbol` (as the Unicode math alphabets: 𝐱, ℝ, 𝔤…), `\rm`, `\bf`…; `\operatorname`, the named functions (`\sin`, `\log`, `\lim`, `\max`…); spaces (`\,`, `\quad`, `\hspace`…); `\color`, `\textcolor`; `\not`; `\displaystyle`…; `\phantom`, `\boxed`, `\pmod`, `\tag`; the environments `matrix`, `pmatrix`, `bmatrix`, `Bmatrix`, `vmatrix`, `Vmatrix`, `smallmatrix`, `cases`, `dcases`, `aligned`, `align`, `alignat`, `gathered`, `gather`, `split`, `array`, `subarray`, `equation`, `eqnarray`, `\substack`, and `\\` lines at the top of a display formula
- **Falls back**: a command it does not know (`\newcommand`, `\href`, `\ce`…) shows as written, in red monospace, and the rest of the formula is drawn; a formula it cannot read (an unclosed brace, `\left` without `\right`, an unknown environment, a double superscript, more than 20,000 characters or groups nested more than 40 deep) shows its whole source that way, the reason as its tooltip. Nothing else of the page changes, and the source is kept as it was
- **Editing**: a formula is one object of the text, like a picture: the caret steps over it, Delete removes it, Undo brings it back, and copy / paste keeps it a formula (the clipboard gets MathML holding the TeX, and the TeX in the plain text; MathML with a TeX annotation from other pages, KaTeX's for one, is pasted as a formula too). The formula itself is edited in the **Code** pane (no visual equation editor yet)
- **Saving**: the document keeps each formula's TeX and delimiters, so the Markdown written for an edited paragraph has the formula exactly as it was (spaces and line breaks of a `$$` block included); the rest of the file is kept as it is. In text written again, a `$` is escaped only when it would otherwise be read as math
- **Word file** (*Download as* Word document): each formula is a real Office Math equation (OMML: Word shows and edits it; display formulas are equation paragraphs), carrying its TeX in two attributes of the library's own namespace, which the file declares ignorable so Word reads it and drops them on save. Opened here again, the equations come back as the same formulas. A color with a name Word does not know is left out of the Word equation, and a formula that cannot be read is its source as text there
- **Exports**: *Download as* web page and print / PDF show the equations (MathML, the TeX as an annotation); plain text and Markdown give the TeX between its delimiters
- **Not yet**: `\(…\)` / `\[…\]` and GitHub's ` ```math ` blocks and `` $`…`$ `` (shown as written), macros (`\newcommand`, `\def`), `\href`, chemistry (`\ce`); a `$$` block over several lines inside a list item or a quote (put it on one line there); equations of Word files (OMML) are still shown as their linear text, not drawn
- **Browsers**: Chromium, Firefox and Safari draw MathML. Chromium follows MathML Core: table column alignment comes from the viewer's style sheet, `\boxed` / `\cancel` draw no box or line, `\textbf` inside `\text` is not bold. The look of the letters is the system's math font (Cambria Math on Windows, STIX Two Math on macOS)

### Diagrams: Mermaid, PlantUML, Graphviz

Expand Down
Loading