Implement many more nodes
All checks were successful
CI Pipeline / build (pull_request) Successful in 12s

Adds these new styling and formatting nodes
* strike
* highlight
* linebreaks
* pagebreaks
* Hyperlinks
This commit is contained in:
2025-12-02 14:43:53 +01:00
parent 243b06d8f8
commit 597bc91c40
19 changed files with 788 additions and 24 deletions

103
README.md
View File

@@ -58,6 +58,8 @@ Notare::Document.create("output.docx") do |doc|
doc.i { doc.text "italic" }
doc.text " and "
doc.u { doc.text "underlined" }
doc.text " and "
doc.s { doc.text "strikethrough" }
end
# Nested formatting (bold + italic)
@@ -66,6 +68,13 @@ Notare::Document.create("output.docx") do |doc|
doc.i { doc.text "bold and italic" }
end
end
# Show edits (strikethrough old, bold new)
doc.p do
doc.s { doc.text "old text" }
doc.text " "
doc.b { doc.text "new text" }
end
end
```
@@ -146,10 +155,14 @@ end
- `bold: true/false`
- `italic: true/false`
- `underline: true/false`
- `strike: true/false` - strikethrough
- `highlight: "yellow"` - text highlight (see colors below)
- `color: "FF0000"` (hex RGB)
- `size: 14` (points)
- `font: "Arial"` (font family)
**Highlight colors:** `black`, `blue`, `cyan`, `darkBlue`, `darkCyan`, `darkGray`, `darkGreen`, `darkMagenta`, `darkRed`, `darkYellow`, `green`, `lightGray`, `magenta`, `red`, `white`, `yellow`
**Paragraph properties:**
- `align: :left / :center / :right / :justify`
- `indent: 720` (twips, 1 inch = 1440 twips)
@@ -246,6 +259,91 @@ Notare::Document.create("output.docx") do |doc|
end
```
### Line Breaks
Use `br` for soft line breaks within a paragraph (text continues in the same paragraph but on a new line):
```ruby
Notare::Document.create("output.docx") do |doc|
doc.p do
doc.text "Line one"
doc.br
doc.text "Line two (same paragraph)"
doc.br
doc.text "Line three"
end
# Useful for addresses
doc.p do
doc.b { doc.text "Address:" }
doc.br
doc.text "123 Main Street"
doc.br
doc.text "Anytown, ST 12345"
end
end
```
### Page Breaks
Use `page_break` to force content to start on a new page:
```ruby
Notare::Document.create("output.docx") do |doc|
doc.h1 "Chapter 1"
doc.p "Content of chapter 1..."
doc.page_break
doc.h1 "Chapter 2"
doc.p "This starts on a new page."
end
```
### Hyperlinks
Add clickable links with `link`:
```ruby
Notare::Document.create("output.docx") do |doc|
# Link with custom text
doc.p do
doc.text "Visit "
doc.link "https://example.com", "our website"
doc.text " for more info."
end
# Link showing the URL as text
doc.p do
doc.text "URL: "
doc.link "https://example.com"
end
# Link with formatted content
doc.p do
doc.link "https://github.com" do
doc.b { doc.text "GitHub" }
end
end
# Links in lists
doc.ul do
doc.li do
doc.link "https://ruby-lang.org", "Ruby"
end
doc.li do
doc.link "https://rubyonrails.org", "Rails"
end
end
# Email links
doc.p do
doc.text "Contact: "
doc.link "mailto:hello@example.com", "hello@example.com"
end
end
```
### Complete Example
```ruby
@@ -296,6 +394,11 @@ end
| `b { }` | Bold formatting |
| `i { }` | Italic formatting |
| `u { }` | Underline formatting |
| `s { }` | Strikethrough formatting |
| `br` | Line break (soft break within paragraph) |
| `page_break` | Page break (force new page) |
| `link(url, text)` | Hyperlink with custom text |
| `link(url) { }` | Hyperlink with block content |
| `define_style(name, **props)` | Define a custom style |
| `ul { }` | Bullet list |
| `ol { }` | Numbered list |