Skip to content

Commit

Permalink
Add support for tables (#1577)
Browse files Browse the repository at this point in the history
* Add page size utilities

- Added page.contentWidth
- Added page.contentHeight

* Add table support

- Tables support cell customization (including colors)
- Tables also support rotatable text (with alignment support)
- Tables have accessibility support

* chore: fix code generation context

- code generation now respects the current document positioning to allow use of page dependent operations

* chore: remove comments from build

* removed unnecessary config optimisations

* Optimize table minification

* Performance improvements to tables

* Improve font handling in tables
  • Loading branch information
hollandjake authored Feb 24, 2025
1 parent ee7208b commit 033ba34
Show file tree
Hide file tree
Showing 31 changed files with 2,493 additions and 47 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Add support for dynamic sizing
- Add support for rotatable text
- Fix page cascade options when text overflows
- Add table generation

### [v0.16.0] - 2024-12-29

Expand Down
17 changes: 17 additions & 0 deletions docs/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ class Node {
({ y } = doc);
doc.x = doc.y = 0;

// Update the page width for those which rely on the width of the document
var docPageWidth = doc.page.width;
var docPageHeight = doc.page.height;
var docPageMargins = doc.page.margins;
doc.page.width = doc.page.width - x - doc.page.margins.right;
doc.page.margins = { top: 0, left: 0, right: 0, bottom: 0 };

// run the example code with the document
vm.runInNewContext(this.code, {
doc,
Expand All @@ -218,6 +225,9 @@ class Node {
doc.restore();
doc.x = x;
doc.y = y + this.height;
doc.page.width = docPageWidth;
doc.page.height = docPageHeight;
doc.page.margins = docPageMargins;
break;
case 'hr':
doc.addPage();
Expand All @@ -226,6 +236,12 @@ class Node {
// loop through subnodes and render them
for (let index = 0; index < this.content.length; index++) {
const fragment = this.content[index];

if (this.type === 'numberlist') {
let node = new Node(['inlinecode', `${index + 1}. `]);
fragment.content.splice(0, 0, node);
}

if (fragment.type === 'text') {
// add a new page for each heading, unless it follows another heading
if (
Expand Down Expand Up @@ -328,5 +344,6 @@ render(doc, 'forms.md');
render(doc, 'destinations.md');
render(doc, 'attachments.md');
render(doc, 'accessibility.md');
render(doc, 'table.md');
render(doc, 'you_made_it.md');
doc.end();
1 change: 1 addition & 0 deletions docs/generate_website.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const files = [
'destinations.md',
'attachments.md',
'accessibility.md',
'table.md',
'you_made_it.md'
];

Expand Down
Loading

0 comments on commit 033ba34

Please sign in to comment.