Skip to content

Examples

Brett Terpstra edited this page Dec 6, 2025 · 1 revision

Examples

Practical examples of using Apex for common tasks.

Basic Conversion

Simple Markdown to HTML

apex document.md > output.html

From stdin

echo "# Hello World" | apex

Blog Post Generation

Generate a complete blog post with custom styling:

apex post.md \
  --standalone \
  --title "My Blog Post" \
  --style blog.css \
  --pretty \
  -o post.html

Documentation Site

Create documentation with table of contents:

<!--TOC-->

# Introduction
...

# Getting Started
...

# API Reference
...
apex docs.md --standalone --title "Documentation" --pretty

GitHub-Compatible README

Convert README for GitHub preview:

apex README.md --mode gfm --pretty > README.html

Review Document with Critic Markup

Draft with changes:

# Document

This is {++new text++} and {--old text--}.

{~~old~>new~~} substitution.

Review mode (show all changes):

apex draft.md > review.html

Accept all changes (final version):

apex draft.md --accept > final.html

Reject all changes (original):

apex draft.md --reject > original.html

Wiki-Style Documentation

Using wiki links and relaxed tables:

# Wiki Documentation

See [[Getting Started]] for details.

## Data Table

one | two | three
1 | 2 | 3
4 | 5 | 6
apex wiki.md --mode unified --pretty

Math Document

Document with mathematical equations:

# Math Examples

Inline: $E = mc^2$

Display:
$$
\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}
$$
apex math.md --standalone --title "Math Examples"

MultiMarkdown Document

Using metadata and variables:

---
title: Report
author: John Doe
date: 2025-12-06
---

# [%title]

By [%author] on [%date]

Content here...
apex report.md --mode mmd --standalone

Kramdown Document

With IAL attributes and relaxed tables:

# Header {: #custom-id .class}

one | two
1 | 2
apex doc.md --mode kramdown --pretty

C Program Example

#include <apex/apex.h>
#include <stdio.h>
#include <string.h>

int main() {
    const char *markdown =
        "# Hello\n\n"
        "This is **bold** and a [[WikiLink]].\n\n"
        "Math: $E = mc^2$\n";

    apex_options opts = apex_options_default();
    opts.pretty = true;

    char *html = apex_markdown_to_html(markdown, strlen(markdown), &opts);

    if (html) {
        printf("%s\n", html);
        apex_free_string(html);
        return 0;
    }

    return 1;
}

Objective-C Example

#import "NSString+Apex.h"

- (NSString *)convertMarkdownToHTML:(NSString *)markdown {
    return [NSString convertWithApex:markdown];
}

- (NSString *)convertWithGFM:(NSString *)markdown {
    return [NSString convertWithApex:markdown mode:@"gfm"];
}

Batch Processing

Process multiple files:

for file in *.md; do
    apex "$file" -o "${file%.md}.html"
done

Pipeline Example

Combine with other tools:

# Preprocess with sed, then convert
sed 's/OLD/NEW/g' input.md | apex > output.html

# Convert and post-process
apex input.md | sed 's/<h1>/<h1 class="title">/g' > output.html

Related

Quick Links

Clone this wiki locally