### Display BASIC Code Source: https://github.com/solworktech/md2pdf/blob/master/cmd/md2pdf/test.md This snippet displays a simple BASIC code example. It is intended for documentation purposes and does not require external dependencies. ```basic 10 REM Old huh? 20 REM Yup, way old! ``` -------------------------------- ### Install md2pdf CLI Utility Source: https://context7.com/solworktech/md2pdf/llms.txt Installs the md2pdf command-line interface binary using either 'go install' or Homebrew. This provides a quick way to convert Markdown files to PDF from the terminal. ```bash # Install via go install go install github.com/solworktech/md2pdf/v2/cmd/md2pdf@latest # Or install via Homebrew brew install md2pdf ``` -------------------------------- ### Install md2pdf CLI using Go Source: https://github.com/solworktech/md2pdf/blob/master/README.md This command installs the md2pdf CLI binary directly into your Go binary directory. Ensure your GOBIN environment variable is set correctly. This method requires Go to be installed on your system. ```sh go install github.com/solworktech/md2pdf/v2/cmd/md2pdf@latest ``` -------------------------------- ### Setting up Pre-commit Hooks in Go Project Source: https://github.com/solworktech/md2pdf/blob/master/README.md Instructions for setting up pre-commit hooks in a Go project, including installing necessary Go tools and the `pre-commit` utility. This helps maintain code quality and consistency. ```sh # Install the needed GO packages: go install github.com/go-critic/go-critic/cmd/gocritic@latest go install golang.org/x/tools/cmd/goimports@latest go install golang.org/x/lint/golint@latest go install github.com/gordonklaus/ineffassign@latest # Install the `pre-commit` util: pip install pre-commit ``` -------------------------------- ### Example md2pdf Command Execution Source: https://github.com/solworktech/md2pdf/blob/master/README.md Demonstrates a practical example of using the md2pdf command-line tool with several options to customize the output PDF. This includes setting the title, author, theme, and enabling new pages on HR elements. ```sh $ go run md2pdf.go -i /path/to/md \ -o /path/to/pdf --title "My Grand Title" --author "Random Bloke" \ --theme dark --new-page-on-hr --with-footer ``` -------------------------------- ### Install Pre-commit Hook for md2pdf Source: https://github.com/solworktech/md2pdf/blob/master/README.md This command installs the pre-commit hook for the md2pdf project. Once installed, the specified Go tests will automatically run before each git commit. ```shell pre-commit install ``` -------------------------------- ### Ping Command Output Example Source: https://github.com/solworktech/md2pdf/blob/master/testdata/syntax_highlighting.md This snippet shows the typical output of the 'ping' command, including statistics about packet transmission, reception, loss, and round-trip times. ```ping PING jessex (127.0.1.1) 56(84) bytes of data. 64 bytes from jessex (127.0.1.1): icmp_seq=1 ttl=64 time=0.031 ms 64 bytes from jessex (127.0.1.1): icmp_seq=2 ttl=64 time=0.033 ms --- jessex ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3033ms rtt min/avg/max/mdev = 0.031/0.036/0.041/0.004 ms ``` -------------------------------- ### Display Go Code Snippets in Blockquote Source: https://github.com/solworktech/md2pdf/blob/master/cmd/md2pdf/test.md This snippet shows two variations of a Go function within a blockquote. It demonstrates how code can be embedded and formatted within documentation. ```go sub status { print "working"; } ``` ```go sub status { return "working"; } ``` -------------------------------- ### Install md2pdf CLI using Homebrew Source: https://github.com/solworktech/md2pdf/blob/master/README.md This command installs the md2pdf CLI using the Homebrew package manager. Homebrew simplifies the installation and management of command-line tools on macOS and Linux. This is a convenient alternative to direct Go installation. ```sh brew install md2pdf ``` -------------------------------- ### Disk Usage (df) Command Output Example Source: https://github.com/solworktech/md2pdf/blob/master/testdata/syntax_highlighting.md This snippet displays the output of the 'df' command, showing disk space usage for various file systems, including size, used space, available space, percentage used, and mount points. ```df Filesystem Size Used Avail Use% Mounted on udev 7.7G 0 7.7G 0% /dev tmpfs 1.6G 2.9M 1.6G 1% /run /dev/nvme0n1p2 23G 20G 1.8G 92% / tmpfs 7.7G 56M 7.7G 1% /dev/shm tmpfs 5.0M 4.0K 5.0M 1% /run/lock /dev/nvme0n1p6 434G 227G 185G 56% /home ``` -------------------------------- ### Example Command for Non-ASCII Font Usage Source: https://github.com/solworktech/md2pdf/blob/master/README.md Provides a command-line example for generating a PDF with non-ASCII characters, specifically demonstrating the use of a custom font file and font name for Russian language support. ```sh $ go run md2pdf.go -i russian.md -o russian.pdf \ --unicode-encoding cp1251 --font-file helvetica_1251.json --font-name Helvetica_1251 ``` -------------------------------- ### Golang Program to Get Executable Directory Source: https://github.com/solworktech/md2pdf/blob/master/testdata/syntax_highlighting.md A simple Golang program that retrieves the directory path of the currently executing binary. It uses the `os` and `path/filepath` packages and prints the directory to standard output. ```go package main import ( "fmt" "os" "path/filepath" ) func main() { ex, err := os.Executable() if err != nil { panic(err) } exPath := filepath.Dir(ex) fmt.Println(exPath) } ``` -------------------------------- ### Rendering Backticks in Markdown Code Spans Source: https://github.com/solworktech/md2pdf/blob/master/testdata/Code Spans.html Illustrates the correct method for including literal backticks within a Markdown code span. This is useful for displaying code examples or commands that contain backticks. ```markdown Here's how you put `` `backticks` `` in a code span. ``` -------------------------------- ### Go Hello World Program Source: https://github.com/solworktech/md2pdf/blob/master/cmd/test_syntax_highlighting.md A basic 'Hello World' program written in Go. It defines the main package and the main function, which prints 'Hello World' to the console. No external dependencies are required. ```go package main func main() { println("Hello World") } ``` -------------------------------- ### C Program to Print Hello World Source: https://github.com/solworktech/md2pdf/blob/master/testdata/syntax_highlighting.md A basic C program that prints the string "Hello world!" to the console. It includes the standard input/output library and a main function. ```c #include int main(int argc, char *argv[]) { printf("%s\n", "Hello world!"); } ``` -------------------------------- ### Create PDF Renderer Instance in Go Source: https://context7.com/solworktech/md2pdf/llms.txt Demonstrates how to create and configure a PdfRenderer object in Go, which is the primary entry point for programmatic PDF generation. It sets parameters like orientation, paper size, output file, theme, and extensions for the Markdown parser. ```go package main import ( "log" "os" "github.com/gomarkdown/markdown/parser" "github.com/solworktech/md2pdf/v2" ) func main() { params := mdtopdf.PdfRendererParams{ Orientation: "portrait", // "portrait" or "landscape" Papersz: "A4", // "A3", "A4", "A5", or "Letter" PdfFile: "output.pdf", TracerFile: "trace.log", // Optional debug log Theme: mdtopdf.LIGHT, // LIGHT, DARK, or CUSTOM CustomThemeFile: "", // Path to custom theme JSON if Theme is CUSTOM } renderer := mdtopdf.NewPdfRenderer(params) renderer.Extensions = parser.CommonExtensions | parser.AutoHeadingIDs content, err := os.ReadFile("document.md") if err != nil { log.Fatal(err) } if err := renderer.Process(content); err != nil { log.Fatal(err) } // Output: output.pdf created successfully } ``` -------------------------------- ### Enable Code Syntax Highlighting in Go Source: https://context7.com/solworktech/md2pdf/llms.txt Enables syntax highlighting for code blocks in the generated PDF by configuring the base directory for syntax definition files. This uses the 'SetSyntaxHighlightBaseDir' render option. ```go package main import ( "log" "github.com/solworktech/md2pdf/v2" ) func main() { opts := []mdtopdf.RenderOption{ mdtopdf.SetSyntaxHighlightBaseDir("/path/to/gohighlight/syntax_files"), } params := mdtopdf.PdfRendererParams{ PdfFile: "code_doc.pdf", Theme: mdtopdf.DARK, Opts: opts, } renderer := mdtopdf.NewPdfRenderer(params) content := []byte("# Code Example\n\n```go\npackage main\n\nimport \"fmt\"\n\nfunc main() {\n fmt.Println(\"Hello, World!\")\n}\n```\n") if err := renderer.Process(content); err != nil { log.Fatal(err) } // Output: code_doc.pdf with syntax-highlighted Go code } ``` -------------------------------- ### Markdown to PDF with Custom Theme File (CLI) Source: https://context7.com/solworktech/md2pdf/llms.txt Illustrates how to use a custom theme file for Markdown to PDF conversion via the command line. The `--theme` option is followed by the path to the JSON file containing the custom styling. ```bash # With custom theme md2pdf -i document.md -o output.pdf --theme /path/to/custom_theme.json ``` -------------------------------- ### Markdown Headers, Paragraphs, and Blockquotes Source: https://github.com/solworktech/md2pdf/blob/master/testdata/Markdown Documentation - Basics.html Demonstrates the creation of Setext and Atx-style headers, regular paragraphs, and blockquotes in Markdown. Setext headers use '=' for H1 and '-' for H2, while Atx headers use '#' for levels 1-6. Blockquotes are created using '>'. ```markdown A First Level Header ==================== A Second Level Header --------------------- Now is the time for all good men to come to the aid of their country. This is just a regular paragraph. The quick brown fox jumped over the lazy dog's back. ### Header 3 > This is a blockquote. > > This is the second paragraph in the blockquote. > > ## This is an H2 in a blockquote ``` ```html

A First Level Header

A Second Level Header

Now is the time for all good men to come to the aid of their country. This is just a regular paragraph.

The quick brown fox jumped over the lazy dog's back.

Header 3

This is a blockquote.

This is the second paragraph in the blockquote.

This is an H2 in a blockquote

``` -------------------------------- ### Run md2pdf CLI for basic conversion Source: https://github.com/solworktech/md2pdf/blob/master/README.md This command demonstrates the basic usage of the md2pdf CLI tool. It takes an input Markdown file (`-i`) and specifies an output PDF file (`-o`). This is the simplest way to convert a Markdown file to PDF. ```sh go run md2pdf.go -i test.md -o test.pdf ``` -------------------------------- ### Markdown Reference-Style Links Source: https://github.com/solworktech/md2pdf/blob/master/testdata/syntax.md Demonstrates creating links using reference-style syntax in Markdown. This method improves document readability by separating link definitions from the main text. It supports both explicit and implicit link naming. ```markdown I get 10 times more traffic from [Google] [1] than from [Yahoo] [2] or [MSN] [3]. [1]: http://google.com/ "Google" [2]: http://search.yahoo.com/ "Yahoo Search" [3]: http://search.msn.com/ "MSN Search" Using the implicit link name shortcut, you could instead write: I get 10 times more traffic from [Google][] than from [Yahoo][] or [MSN][]. [google]: http://google.com/ "Google" [yahoo]: http://search.yahoo.com/ "Yahoo Search" [msn]: http://search.msn.com/ "MSN Search" ``` -------------------------------- ### Markdown Lists (Unordered and Ordered) Source: https://github.com/solworktech/md2pdf/blob/master/testdata/Markdown Documentation - Basics.html Shows how to create unordered (bulleted) lists using asterisks, pluses, or hyphens, and ordered (numbered) lists using numbers followed by periods. Demonstrates multi-paragraph list items by indenting subsequent paragraphs. ```markdown * Candy. * Gum. * Booze. + Candy. + Gum. + Booze. - Candy. - Gum. - Booze. 1. Red 2. Green 3. Blue * A list item. With multiple paragraphs. * Another item in the list. ``` ```html
  1. Red
  2. Green
  3. Blue
``` -------------------------------- ### Load Custom Theme from JSON File (Go) Source: https://context7.com/solworktech/md2pdf/llms.txt Applies a custom theme to the PDF output by loading styling configurations from a specified JSON file. This allows for complete control over fonts, colors, spacing, and element styling. The `Theme` is set to `mdtopdf.CUSTOM` and `CustomThemeFile` points to the JSON configuration. ```go package main import ( "log" "github.com/solworktech/md2pdf/v2" ) func main() { params := mdtopdf.PdfRendererParams{ PdfFile: "custom_styled.pdf", Theme: mdtopdf.CUSTOM, CustomThemeFile: "./custom_themes/light_theme.json", } renderer := mdtopdf.NewPdfRenderer(params) content := []byte(`# Custom Styled Document This document uses custom fonts, colors, and spacing. `) if err := renderer.Process(content); err != nil { log.Fatal(err) } // Output: custom_styled.pdf with custom styling applied } // Example custom_theme.json structure: /* { "Normal": {"Font": "Arial", "Style": "", "Size": 12, "Spacing": 2, "TextColor": {"Red": 0, "Green": 0, "Blue": 0}, "FillColor": {"Red": 255, "Green": 255, "Blue": 255}}, "H1": {"Font": "Arial", "Style": "b", "Size": 24, "Spacing": 5, "TextColor": {"Red": 0, "Green": 0, "Blue": 0}, "FillColor": {"Red": 255, "Green": 255, "Blue": 255}}, "Code": {"Font": "Times", "Style": "", "Size": 12, "Spacing": 2, "TextColor": {"Red": 37, "Green": 27, "Blue": 14}, "FillColor": {"Red": 200, "Green": 200, "Blue": 200}}, "BackgroundColor": {"Red": 255, "Green": 255, "Blue": 255}, "Theme": 3 } */ ``` -------------------------------- ### Run md2pdf CLI with Syntax Highlighting Source: https://github.com/solworktech/md2pdf/blob/master/README.md This command shows how to use the md2pdf CLI with syntax highlighting enabled. It requires specifying the input Markdown file (`-i`), the path to the syntax highlighting files (`-s`), and the output PDF file (`-o`). ```sh go run md2pdf.go -i syn_test.md -s /path/to/syntax_files -o test.pdf ``` -------------------------------- ### Markdown to PDF with Dark Theme (CLI) Source: https://context7.com/solworktech/md2pdf/llms.txt Shows how to apply a predefined dark theme during Markdown to PDF conversion using the `md2pdf` CLI. The `--theme dark` option selects the dark theme for the output PDF. ```bash # With dark theme md2pdf -i document.md -o output.pdf --theme dark ``` -------------------------------- ### Markdown Inline Links Source: https://github.com/solworktech/md2pdf/blob/master/testdata/Markdown Documentation - Basics.html Demonstrates creating inline links in Markdown with optional titles. The syntax uses square brackets for the link text and parentheses for the URL and optional title. ```markdown This is an [example link](http://example.com/). This is an [example link](http://example.com/ "With a Title") ``` -------------------------------- ### Update Git Submodules Source: https://github.com/solworktech/md2pdf/blob/master/README.md This command updates the Git submodules for the project, specifically ensuring that the gohighlight module is up-to-date. This is necessary if you cloned the repository without the --recursive flag or if the submodule has been updated. ```sh git submodule update --remote --init ``` -------------------------------- ### Markdown to PDF with Syntax Highlighting Files (CLI) Source: https://context7.com/solworktech/md2pdf/llms.txt Explains how to enable syntax highlighting for code blocks in the generated PDF using the `md2pdf` CLI. The `-s` flag specifies the directory containing the syntax highlighting definition files. ```bash # With syntax highlighting md2pdf -i document.md -o output.pdf -s /path/to/syntax_files ``` -------------------------------- ### Basic md2pdf CLI Usage Source: https://context7.com/solworktech/md2pdf/llms.txt Demonstrates fundamental command-line operations for md2pdf, including basic conversion, adding footers, generating tables of contents, and handling non-ASCII characters. ```bash md2pdf -i document.md -o output.pdf --with-footer --author "John Doe" --title "My Document" md2pdf -i document.md -o output.pdf --generate-toc md2pdf -i russian.md -o russian.pdf --unicode-encoding cp1251 --font-file helvetica_1251.json --font-name Helvetica_1251 md2pdf -i /path/to/markdown/directory -o combined.pdf md2pdf -i https://raw.githubusercontent.com/user/repo/main/README.md -o readme.pdf md2pdf -version ``` -------------------------------- ### Markdown Code Blocks Source: https://github.com/solworktech/md2pdf/blob/master/testdata/Markdown Documentation - Basics.html Demonstrates how to format entire blocks of pre-formatted code in Markdown by indenting each line with 4 spaces or 1 tab. This preserves whitespace and escapes special characters. ```markdown If you want your page to validate under XHTML 1.0 Strict, you've got to put paragraph tags in your blockquotes:

For example.

``` -------------------------------- ### Process Markdown Content to PDF in Go Source: https://context7.com/solworktech/md2pdf/llms.txt Shows how to use the Process method of the PdfRenderer to convert a byte slice of Markdown content into a complete PDF file. This method handles parsing, rendering, and writing the output to the specified file. ```go package main import ( "log" "github.com/solworktech/md2pdf/v2" ) func main() { params := mdtopdf.PdfRendererParams{ PdfFile: "report.pdf", TracerFile: "", Theme: mdtopdf.LIGHT, } renderer := mdtopdf.NewPdfRenderer(params) markdown := []byte(`# Project Report ## Introduction This is an automated report generated from Markdown. ## Features - Easy to use API - Multiple themes supported - Syntax highlighting | Feature | Status | |---------|--------| | Tables | Done | | Images | Done | | Links | Done | `) if err := renderer.Process(markdown); err != nil { log.Fatalf("PDF generation failed: %v", err) } // Output: report.pdf with formatted content } ``` -------------------------------- ### Markdown Pre-formatted Code Block Source: https://github.com/solworktech/md2pdf/blob/master/testdata/syntax.md Shows how to create pre-formatted code blocks in Markdown by indenting every line with at least 4 spaces or 1 tab. These blocks are rendered literally and wrapped in `
` and `` tags.

```markdown
This is a normal paragraph:

    This is a code block.
```

--------------------------------

### Shell Script for Network Interface Configuration

Source: https://github.com/solworktech/md2pdf/blob/master/testdata/syntax_highlighting.md

A shell script designed for network interface configuration. It sets up paths, checks for necessary utilities, and includes functions to manage network state files.

```sh
#!/bin/sh -e
PATH="/sbin:/bin"
RUN_DIR="/run/network"
IFSTATE="$RUN_DIR/ifstate"
STATEDIR="$RUN_DIR/state"

[ -x /sbin/ifup ] || exit 0
[ -x /sbin/ifdown ] || exit 0

. /lib/lsb/init-functions

CONFIGURE_INTERFACES=yes
EXCLUDE_INTERFACES=
VERBOSE=no

[ -f /etc/default/networking ] && . /etc/default/networking

verbose=""
[ "$VERBOSE" = yes ] && verbose=-v

check_ifstate() {
    if [ ! -d "$RUN_DIR" ] ; then
	if ! mkdir -p "$RUN_DIR" ; then
	    log_failure_msg "can't create $RUN_DIR"
	    exit 1
	fi
	if ! chown root:netdev "$RUN_DIR" ; then
	    log_warning_msg "can't chown $RUN_DIR"
	fi
    fi
    if [ ! -r "$IFSTATE" ] ; then
	if ! :> "$IFSTATE" ; then
	    log_failure_msg "can't initialise $IFSTATE"
	    exit 1
	fi
    fi
}
```

--------------------------------

### Command-line Options for md2pdf

Source: https://github.com/solworktech/md2pdf/blob/master/README.md

This section lists and describes the various command-line flags available for the md2pdf tool. These options control input/output files, metadata, styling, and PDF generation behavior.

```sh
  -author string
    	Author name; used if -footer is passed
  -font-file string
    	path to font file to use
  -font-name string
    	Font name ID; e.g 'Helvetica-1251'
  -generate-toc
    	Auto Generate Table of Contents (TOC)
  -help
    	Show usage message
  -i string
    	Input filename, dir consisting of .md|.markdown files or HTTP(s) URL; default is os.Stdin
  -log-file string
    	Path to log file
  -new-page-on-hr
    	Interpret HR as a new page; useful for presentations
  -o string
    	Output PDF filename; required
  -orientation string
    	[portrait | landscape] (default "portrait")
  -page-size string
    	[A3 | A4 | A5] (default "A4")
  -s string
    	Path to github.com/jessp01/gohighlight/syntax_files
  -theme string
    	[light | dark | /path/to/custom/theme.json] (default "light")
  -title string
    	Presentation title
  -unicode-encoding string
    	e.g 'cp1251'
  -version
    	Print version and build info
  -with-footer
    	Print doc footer (    <page number>)
```

--------------------------------

### Advanced PDF Manipulation via fpdf Access in Go

Source: https://context7.com/solworktech/md2pdf/llms.txt

Demonstrates how to access the underlying fpdf object in Go for advanced PDF manipulations, such as adding custom headers and footers, beyond the standard Markdown rendering capabilities.

```go
package main

import (
    "log"

    "github.com/solworktech/md2pdf/v2"
)

func main() {
    params := mdtopdf.PdfRendererParams{
        PdfFile: "advanced.pdf",
        Theme:   mdtopdf.LIGHT,
    }

    renderer := mdtopdf.NewPdfRenderer(params)

    // Access underlying fpdf for advanced operations
    pdf := renderer.Pdf

    // Add custom header
    pdf.SetHeaderFunc(func() {
        pdf.SetFont("Arial", "B", 10)
        pdf.Cell(0, 10, "Company Name - Confidential")
        pdf.Ln(15)
    })

    // Add custom footer
    pdf.SetFooterFunc(func() {
        pdf.SetY(-15)
        pdf.SetFont("Arial", "I", 8)
        pdf.CellFormat(0, 10, "Page "+string(rune(pdf.PageNo())), "", 0, "C", false, 0, "")
    })

    content := []byte("# Document Title\nDocument content with custom headers and footers.")

    if err := renderer.Process(content); err != nil {
        log.Fatal(err)
    }
}
```

--------------------------------

### Configuring Unicode Translator in Go

Source: https://github.com/solworktech/md2pdf/blob/master/README.md

Illustrates how to configure the PDF renderer in Go to support non-ASCII characters using `WithUnicodeTranslator`. This is essential for languages like Russian, requiring a specific encoding like 'cp1251'.

```go
// https://en.wikipedia.org/wiki/Windows-1251
pf := mdtopdf.NewPdfRenderer("", "", *output, "trace.log", mdtopdf.WithUnicodeTranslator("cp1251"))
```

--------------------------------

### Markdown Reference-Style Link Syntax

Source: https://github.com/solworktech/md2pdf/blob/master/testdata/syntax.md

Explains how to create reference-style links in Markdown. This involves defining a link label in square brackets within the text, and then defining the URL and optional title separately using a matching label followed by a colon and the URL.

```markdown
This is [an example][id] reference-style link.

This is [an example] [id] reference-style link.

[id]: http://example.com/  "Optional Title Here"

[id]: <http://example.com/>  "Optional Title Here"

[id]: http://example.com/longish/path/to/resource/here
    "Optional Title Here"

```

--------------------------------

### Markdown Phrase Emphasis

Source: https://github.com/solworktech/md2pdf/blob/master/testdata/Markdown Documentation - Basics.html

Illustrates how to apply emphasis and strong emphasis to text in Markdown using asterisks and underscores. Single asterisks or underscores create italic text, while double asterisks or underscores create bold text.

```markdown
Some of these words *are emphasized*.
Some of these words _are emphasized also_.

Use two asterisks for **strong emphasis**.
Or, if you prefer, __use two underscores instead__.

```

```html
<p>Some of these words <em>are emphasized</em>.
Some of these words <em>are emphasized also</em>.</p>

<p>Use two asterisks for <strong>strong emphasis</strong>.
Or, if you prefer, <strong>use two underscores instead</strong>.</p>

```

--------------------------------

### Execute Shell Command with Markdown Script

Source: https://github.com/solworktech/md2pdf/blob/master/testdata/syntax.md

This snippet demonstrates executing a shell command using 'shell_exec' in PHP, piping input to a markdown script. It's useful for server-side Markdown processing.

```php
return shell_exec("echo $input | $markdown_script");
```

--------------------------------

### Javascript Console Log Function

Source: https://github.com/solworktech/md2pdf/blob/master/cmd/test_syntax_highlighting.md

A simple Javascript function named 'myfunc' that logs 'hello world' to the console. This function can be used in various Javascript environments, such as web browsers or Node.js.

```javascript
function myfunc() {
	console.log("hello world");
}
```

--------------------------------

### Markdown to PDF in Presentation Mode (CLI)

Source: https://context7.com/solworktech/md2pdf/llms.txt

Demonstrates how to configure the `md2pdf` CLI for presentation mode, where horizontal rules trigger new pages. This is achieved using the `--new-page-on-hr` flag, and the `--orientation landscape` flag sets the page orientation.

```bash
# Presentation mode (HR creates new page)
md2pdf -i slides.md -o presentation.pdf --new-page-on-hr --orientation landscape
```

--------------------------------

### Markdown Image Syntax

Source: https://github.com/solworktech/md2pdf/blob/master/testdata/Markdown Documentation - Basics.html

Shows the Markdown syntax for embedding images, supporting both inline and reference-style definitions. The `alt text` is crucial for accessibility.

```markdown
![alt text](/path/to/img.jpg "Title")
![alt text][id]

[id]: /path/to/img.jpg "Title"
```

--------------------------------

### Customizing Text Styles with Styler in Go

Source: https://context7.com/solworktech/md2pdf/llms.txt

Shows how to use the Styler struct in Go to customize the appearance of different text elements in a PDF, such as normal text and headings. It involves creating a custom Styler and applying it via RenderOption.

```go
package main

import (
    "log"

    "github.com/solworktech/md2pdf/v2"
)

func main() {
    // Create custom styler for normal text
    customStyler := mdtopdf.Styler{
        Font:      "Helvetica",
        Style:     "",           // "" = normal, "b" = bold, "i" = italic, "bi" = bold italic
        Size:      14,           // Font size in points
        Spacing:   3,            // Line spacing in points
        TextColor: mdtopdf.Color{Red: 33, Green: 33, Blue: 33},
        FillColor: mdtopdf.Color{Red: 255, Green: 255, Blue: 255},
    }

    opts := []mdtopdf.RenderOption{
        func(r *mdtopdf.PdfRenderer) {
            r.Normal = customStyler
        },
    }

    params := mdtopdf.PdfRendererParams{
        PdfFile: "styled.pdf",
        Theme:   mdtopdf.LIGHT,
        Opts:    opts,
    }

    renderer := mdtopdf.NewPdfRenderer(params)

    // Customize heading styles after creation
    renderer.H1 = mdtopdf.Styler{
        Font:      "Helvetica",
        Style:     "b",
        Size:      28,
        Spacing:   8,
        TextColor: mdtopdf.Color{Red: 0, Green: 51, Blue: 102},
        FillColor: mdtopdf.Color{Red: 255, Green: 255, Blue: 255},
    }

    content := []byte("# Custom Heading\nCustom styled paragraph text.")

    if err := renderer.Process(content); err != nil {
        log.Fatal(err)
    }
}
```

--------------------------------

### YAML Configuration for File Type Detection

Source: https://github.com/solworktech/md2pdf/blob/master/testdata/syntax_highlighting.md

This YAML snippet defines rules for detecting and highlighting file types, specifically for diff files. It specifies patterns for filenames, headers, and different statement types within the diff.

```yaml
filetype: diff

detect: 
    filename: "\\.diff$"
    header: "^((---.*)|(\+\+\+.*))"
rules:
    - statement: "(^\+\+\+.*)"
    - statement: "(^---.*)"
    - type: "(^@@.*)"
    - constant.number: "(^\+.*)"
    - preproc: "(^-.*)"
```

--------------------------------

### Pre-commit Hook Test Status

Source: https://github.com/solworktech/md2pdf/blob/master/README.md

This section displays the status of various Go tests that are executed by the pre-commit hook. These tests ensure code quality and adherence to Go standards.

```sh
go fmt...................................................................Passed
go imports...............................................................Passed
go vet...................................................................Passed
go lint..................................................................Passed
go-critic................................................................Passed
```

--------------------------------

### Run md2pdf CLI for multiple files

Source: https://github.com/solworktech/md2pdf/blob/master/README.md

This command illustrates how to convert multiple Markdown files from a directory into a single PDF document. The `-i` flag accepts a directory path, and the `-o` flag specifies the name of the consolidated output PDF file.

```sh
go run md2pdf.go -i /path/to/md/directory -o test.pdf
```

--------------------------------

### INI Configuration for ctype Module

Source: https://github.com/solworktech/md2pdf/blob/master/testdata/syntax_highlighting.md

A simple INI configuration snippet for a module named 'ctype'. It includes a commented-out priority setting and specifies the extension file.

```ini
[ctype]
; priority=20
extension=ctype.so
```

--------------------------------

### XML Structure for a Presentation Deck

Source: https://github.com/solworktech/md2pdf/blob/master/testdata/syntax_highlighting.md

An XML document defining the structure of a presentation deck. It includes elements for the deck title, canvas, slides, images, text, lines, lists, rectangles, ellipses, curves, arcs, and polygons.

```xml
<?xml version="1.0" encoding="UTF-8"?>
<deck>
	<title>Sample Deck
	
	
	    
		Deck uses these elements
		
		
			
  • canvas
  • slide
  • text
  • list
  • image
  • line
  • rect
  • ellipse
  • curve
  • arc
  • ``` -------------------------------- ### Markdown Image Reference Syntax Source: https://github.com/solworktech/md2pdf/blob/master/testdata/syntax.md Demonstrates the reference-style syntax for including images in Markdown. It requires defining an image reference separately using a similar syntax to link references. Dimensions are not supported directly and require HTML. ```markdown ![Alt text][id] [id]: url/to/image "Optional title attribute" ``` -------------------------------- ### Markdown Image Syntax (Inline) Source: https://github.com/solworktech/md2pdf/blob/master/testdata/syntax.md Demonstrates the inline syntax for embedding images in Markdown. This format includes an exclamation mark, alt text in square brackets, and the image URL and optional title in parentheses. ```markdown ![Alt text](/path/to/img.jpg) ![Alt text](/path/to/img.jpg "Optional title") ``` -------------------------------- ### Markdown Inline Link Syntax Source: https://github.com/solworktech/md2pdf/blob/master/testdata/syntax.md Illustrates the creation of inline links in Markdown. Links are defined using square brackets for the link text, followed immediately by parentheses containing the URL and an optional title enclosed in quotes. ```markdown This is [an example](http://example.com/ "Title") inline link. [This link](http://example.net/) has no title attribute. See my [About](/about/) page for details. ``` -------------------------------- ### Markdown List Items with Paragraphs Source: https://github.com/solworktech/md2pdf/blob/master/testdata/syntax.md Shows how to include multiple paragraphs within a single list item. Subsequent paragraphs must be indented by 4 spaces or one tab. ```markdown 1. This is a list item with two paragraphs. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. Donec sit amet nisl. Aliquam semper ipsum sit amet velit. ``` ```markdown 2. Suspendisse id sem consectetuer libero luctus adipiscing. ``` -------------------------------- ### Enable Presentation Mode with Horizontal Rule Page Breaks (Go) Source: https://context7.com/solworktech/md2pdf/llms.txt Configures the PDF renderer to treat horizontal rules (---) as page breaks, enabling a presentation or slideshow mode. This is useful for creating multi-page documents where distinct sections are separated by horizontal lines. The function `IsHorizontalRuleNewPage(true)` is used within the `RenderOption` slice. ```go package main import ( "log" "github.com/solworktech/md2pdf/v2" ) func main() { opts := []mdtopdf.RenderOption{ mdtopdf.IsHorizontalRuleNewPage(true), } params := mdtopdf.PdfRendererParams{ PdfFile: "presentation.pdf", Orientation: "landscape", Theme: mdtopdf.DARK, Opts: opts, } renderer := mdtopdf.NewPdfRenderer(params) slides := []byte(`# Slide 1: Introduction Welcome to the presentation --- # Slide 2: Features - Feature A - Feature B --- # Slide 3: Conclusion Thank you! `) if err := renderer.Process(slides); err != nil { log.Fatal(err) } // Output: presentation.pdf with 3 separate pages } ``` -------------------------------- ### Markdown Inline Links Source: https://github.com/solworktech/md2pdf/blob/master/testdata/syntax.md Illustrates how to create links directly within the text using Markdown's inline link syntax. This method embeds the URL and optional title directly after the link text. ```markdown I get 10 times more traffic from [Google](http://google.com/ "Google") than from [Yahoo](http://search.yahoo.com/ "Yahoo Search") or [MSN](http://search.msn.com/ "MSN Search"). ``` -------------------------------- ### HTML Block Rendering in md2pdf Source: https://github.com/solworktech/md2pdf/blob/master/testdata/Inline HTML (Simple).html Demonstrates how the md2pdf project handles simple HTML blocks. It shows the rendering of basic div elements containing text. ```html
    foo
    ``` ```html
    foo
    ``` -------------------------------- ### Markdown Reference-Style Links Source: https://github.com/solworktech/md2pdf/blob/master/testdata/Markdown Documentation - Basics.html Illustrates reference-style links in Markdown, where links are defined by names elsewhere in the document. This allows for cleaner text and reusable link definitions. ```markdown I get 10 times more traffic from [Google][1] than from [Yahoo][2] or [MSN][3]. [1]: http://google.com/ "Google" [2]: http://search.yahoo.com/ "Yahoo Search" [3]: http://search.msn.com/ "MSN Search" I start my morning with a cup of coffee and [The New York Times][NY Times]. [ny times]: http://www.nytimes.com/ ``` -------------------------------- ### Markdown Implicit Link Name Shortcut Source: https://github.com/solworktech/md2pdf/blob/master/testdata/syntax.md Demonstrates the implicit link name shortcut in Markdown, where the link text itself is used as the link name. This is achieved by using an empty set of square brackets after the link text and defining the link with the text as the identifier. ```markdown [Google][] [Google]: http://google.com/ Visit [Daring Fireball][] for more information. [Daring Fireball]: http://daringfireball.net/ ``` -------------------------------- ### Extract Table of Contents Entries (Go) Source: https://context7.com/solworktech/md2pdf/llms.txt Parses Markdown content to extract headings and generate a table of contents. The function `GetTOCEntries` returns a slice of `TOCEntry` structs, each containing the heading's level, title, and a generated ID. This is useful for creating navigation within documents. ```go package main import ( "fmt" "log" "github.com/solworktech/md2pdf/v2" ) func main() { content := []byte(`# Chapter 1 Introduction text ## Section 1.1 Details here ## Section 1.2 More details # Chapter 2 Another chapter ### Subsection 2.1.1 Deep nesting `) entries, err := mdtopdf.GetTOCEntries(content) if err != nil { log.Fatal(err) } for _, entry := range entries { fmt.Printf("Level %d: %s (ID: %s)\n", entry.Level, entry.Title, entry.ID) } // Output: // Level 1: Chapter 1 (ID: chapter-1) // Level 2: Section 1.1 (ID: section-11) // Level 2: Section 1.2 (ID: section-12) // Level 1: Chapter 2 (ID: chapter-2) // Level 3: Subsection 2.1.1 (ID: subsection-211) } ``` -------------------------------- ### Markdown List Item with Hanging Indent Source: https://github.com/solworktech/md2pdf/blob/master/testdata/syntax.md This demonstrates how to format list items with hanging indents for better readability. Markdown allows wrapping items with indented text. ```markdown * Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus. * Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing. ``` -------------------------------- ### Markdown Unordered Lists Source: https://github.com/solworktech/md2pdf/blob/master/testdata/syntax.md Markdown supports unordered lists using asterisks, pluses, or hyphens as markers. These are interchangeable and render as bullet points. ```markdown * Red * Green * Blue ``` ```markdown + Red + Green + Blue ``` ```markdown - Red - Green - Blue ``` -------------------------------- ### Markdown List Item with Blockquote Source: https://github.com/solworktech/md2pdf/blob/master/testdata/syntax.md Demonstrates embedding a blockquote within a Markdown list item. The blockquote's delimiters must be indented along with the list item. ```markdown * A list item with a blockquote: > This is a blockquote > inside a list item. ``` -------------------------------- ### Resolve Color Names and Values (Go) Source: https://context7.com/solworktech/md2pdf/llms.txt Provides a utility function `Colorlookup` to resolve various color formats, including named colors, RGB strings, hex codes, and HSV strings, into RGB Color structs. This function is essential for applying custom colors in styling configurations. ```go package main import ( "fmt" "github.com/solworktech/md2pdf/v2" ) func main() { // By named color blue := mdtopdf.Colorlookup("cornflowerblue") fmt.Printf("cornflowerblue: R=%d G=%d B=%d\n", blue.Red, blue.Green, blue.Blue) // Output: cornflowerblue: R=100 G=149 B=237 // By hex code custom := mdtopdf.Colorlookup("#FF5733") fmt.Printf("#FF5733: R=%d G=%d B=%d\n", custom.Red, custom.Green, custom.Blue) // Output: #FF5733: R=255 G=87 B=51 // By RGB string rgb := mdtopdf.Colorlookup("rgb(128, 64, 255)") fmt.Printf("rgb(128,64,255): R=%d G=%d B=%d\n", rgb.Red, rgb.Green, rgb.Blue) // Output: rgb(128,64,255): R=128 G=64 B=255 // By HSV string hsv := mdtopdf.Colorlookup("hsv(200, 50, 80)") fmt.Printf("hsv(200,50,80): R=%d G=%d B=%d\n", hsv.Red, hsv.Green, hsv.Blue) // Output: hsv(200,50,80): R=102 G=170 B=204 } ``` -------------------------------- ### Markdown Emphasis (Bold and Italic) Source: https://github.com/solworktech/md2pdf/blob/master/testdata/syntax.md Shows how to apply emphasis to text in Markdown using single asterisks or underscores for italics and double asterisks or underscores for bold text. The same character must be used to open and close emphasis spans. ```markdown *single asterisks* _single underscores_ **double asterisks** __double underscores__ un*fucking*believable \*this text is surrounded by literal asterisks\* ``` -------------------------------- ### Markdown Code Block Indentation and Escaping Source: https://github.com/solworktech/md2pdf/blob/master/testdata/syntax.md Demonstrates how Markdown handles code blocks by removing one level of indentation and automatically converting special characters like ampersands and angle brackets to HTML entities. This ensures code is displayed literally without Markdown processing. ```markdown This is a normal paragraph: This is a code block. ``` ```markdown Here is an example of AppleScript: tell application "Foo" beep end tell ``` ```markdown ``` -------------------------------- ### Markdown List Item with Code Block Source: https://github.com/solworktech/md2pdf/blob/master/testdata/syntax.md Illustrates how to include a pre-formatted code block within a Markdown list item. The code block requires double indentation (8 spaces or two tabs). ```markdown * A list item with a code block: ``` -------------------------------- ### Markdown Automatic Link Syntax Source: https://github.com/solworktech/md2pdf/blob/master/testdata/syntax.md Illustrates how Markdown automatically creates clickable links for URLs and email addresses when enclosed in angle brackets. Email addresses are entity-encoded to help prevent spam. ```markdown ``` ```html http://example.com/ address@example.com ``` -------------------------------- ### Markdown Horizontal Rule Syntax Source: https://github.com/solworktech/md2pdf/blob/master/testdata/syntax.md Shows how to create horizontal rules (
    ) in Markdown using three or more hyphens, asterisks, or underscores on a line by themselves. Spaces can optionally be used between these characters. ```markdown * * * *** ***** - - - --------------------------------------- _ _ _ ``` -------------------------------- ### PHP Function for Multibyte String Splitting Source: https://github.com/solworktech/md2pdf/blob/master/testdata/syntax_highlighting.md This PHP code defines a function `mb_str_split` that splits a multibyte string into an array of smaller strings based on a specified length and encoding. It provides a fallback if the function is not already defined. ```php