Skip to content

Commit 74ff20c

Browse files
committed
feat!: rewrite to typescript with modern templates and structured API
- migrate all source from ES5 CommonJS to strict TypeScript ESM - replace winston with lightweight console/file logger - replace commander v2 with commander v13 - replace xml2js v0.4 with v0.6 - add vitest test suite (32 tests) - fix pipe regex bug in escape.cell (string literal instead of regex) - fix console.assert misuse in parser - add structured member data (params, returnType, templateParams, qualifiers) - add modern templates with code-block signatures and parameter tables - preserve classic templates at templates/classic/ - add java language support with dedicated templates - add interface/enum compound type handling - add variable initializer support - fix compound parsing order with two-pass index resolution - add CI workflow and README badges
1 parent bf80851 commit 74ff20c

47 files changed

Lines changed: 4507 additions & 1817 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
branches: [master]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
node-version: [18, 20, 22]
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-node@v4
18+
with:
19+
node-version: ${{ matrix.node-version }}
20+
cache: npm
21+
- run: npm ci
22+
- run: npm run build
23+
- run: npm run lint
24+
- run: npm test

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
node_modules/
2+
dist/
23
npm-debug.log
3-
package-lock.json
4+
*.tsbuildinfo

README.md

Lines changed: 84 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,113 @@
11
# Moxygen
22

3-
Moxygen is a Doxygen XML to Markdown converter for C++ developers who want a minimal and beautiful solution for documentating their projects.
3+
[![CI](https://github.com/sourcey/moxygen/actions/workflows/ci.yml/badge.svg)](https://github.com/sourcey/moxygen/actions/workflows/ci.yml)
4+
[![npm](https://img.shields.io/npm/v/moxygen)](https://www.npmjs.com/package/moxygen)
5+
[![Node](https://img.shields.io/node/v/moxygen)](https://nodejs.org)
6+
[![License](https://img.shields.io/npm/l/moxygen)](https://github.com/sourcey/moxygen/blob/master/LICENCE)
47

5-
Moxygen is currently used in conjunction with GitBook to generate the API documentation for [LibSourcey](http://sourcey.com/libsourcey/).
8+
Doxygen XML to Markdown converter for C++ and Java developers who want minimal, beautiful API documentation.
69

710
## Features
811

9-
* **Multi page output**: Output single or multiple files
10-
* **Internal linking**: Anchors in comments and function definitions are supported
11-
* **Markdown comments**: Markdown in Doxygen comments are rendered
12-
* **Doxygen groups**: Doxygen [grouping](http://www.doxygen.nl/manual/grouping.html) is supported for more organised documentation
13-
* **Custom templates**: Modify the core Markdown templates to add your own flavour
14-
* **Optional index**: Optionally render a top level index
12+
- **Multi-language** - C++ and Java supported out of the box
13+
- **Multi-page output** - single file, per-group, per-class, or per-page
14+
- **Internal linking** - anchors in comments and function definitions
15+
- **Markdown comments** - Markdown in Doxygen comments is rendered
16+
- **Doxygen groups** - [grouping](http://www.doxygen.nl/manual/grouping.html) support for organised docs
17+
- **Custom templates** - modify the Handlebars templates to suit your needs
18+
- **Optional index** - optionally render a top-level index
1519

16-
## Usage
20+
## Install
1721

18-
1. Add `GENERATE_XML=YES` to your `Doxyfile` first.
19-
2. Run `doxygen` to generate the XML documentation.
20-
3. Install `moxygen` like so: `npm install moxygen -g`.
21-
4. Run `moxygen` providing the folder location of the XML documentation as the first argument ie. `{OUTPUT_DIRECTORY}/xml`.
22-
```
23-
Usage: moxygen [options] <doxygen XML directory>
22+
```
23+
npm install moxygen -g
24+
```
2425

25-
Options:
26+
Requires Node.js 18+.
2627

27-
-V, --version output the version number
28-
-o, --output <file> output file, must contain "%s" when using `groups` or `classes`
29-
-g, --groups output doxygen groups into separate files
30-
-c, --classes output doxygen classes into separate files
31-
-p, --pages output doxygen pages into separate files
32-
-n, --noindex disable generation of the index, ignored with `groups` or `classes`
33-
-a, --anchors add anchors to internal links
34-
-H, --html-anchors add html anchors to internal links
35-
-l, --language <lang> programming language
36-
-t, --templates <dir> custom templates directory
37-
-L, --logfile [file] output log messages to file
38-
-q, --quiet quiet mode
39-
-h, --help output usage information
40-
```
28+
## Usage
4129

42-
## Multi-page Output
30+
1. Add `GENERATE_XML=YES` to your `Doxyfile`
31+
2. Run `doxygen` to generate the XML documentation
32+
3. Run `moxygen` pointing to the XML output directory
4333

44-
Moxygen supports the doxygen [groups](http://www.doxygen.nl/manual/grouping.html#modules) syntax for generating multi page documentation. Every [\defgroup](http://www.doxygen.nl/manual/commands.html#cmddefgroup) in your source code will be parsed and output into a separate markdown file, with internal reference updated accordingly.
34+
```
35+
moxygen [options] <doxygen XML directory>
36+
37+
Options:
38+
-V, --version output the version number
39+
-o, --output <file> output file, must contain "%s" when using groups or classes
40+
-g, --groups output doxygen groups into separate files
41+
-c, --classes output doxygen classes into separate files
42+
-p, --pages output doxygen pages into separate files
43+
-n, --noindex disable generation of the index
44+
-a, --anchors add anchors to internal links
45+
-H, --html-anchors add HTML anchors to internal links
46+
-l, --language <lang> programming language (default: cpp)
47+
-t, --templates <dir> custom templates directory
48+
-L, --logfile [file] output log messages to file (default: moxygen.log)
49+
-q, --quiet quiet mode
50+
-h, --help display help
51+
```
4552

46-
Example:
53+
## Examples
4754

55+
Single file output:
4856
```
49-
moxygen --anchors --groups --output api-%s.md /path/to/doxygen/xml
57+
moxygen --anchors /path/to/doxygen/xml
5058
```
5159

52-
## Example
60+
Multi-file grouped output:
61+
```
62+
moxygen --anchors --groups --output api-%s.md /path/to/doxygen/xml
63+
```
5364

54-
To get a feel for how Moxygen works you can play with the example which is located in the [example](/example) folder. The example contains:
65+
Per-class files:
66+
```
67+
moxygen --classes --output api-%s.md /path/to/doxygen/xml
68+
```
5569

56-
* Documented C++ example code
57-
* A `Doxyfile` file (for doxygen 1.8.13)
58-
* Pre-generated XML output in [example/xml](/example/xml)
59-
* Pre-generated output Markdown files in [example/doc](/example/doc)
70+
Java project:
71+
```
72+
moxygen --language java --anchors /path/to/doxygen/xml
73+
```
6074

61-
To fully build the example, follow these steps (once you've installed `doxygen`. See **Development & Contribution**, below):
75+
## Custom Templates
6276

63-
1. Rebuild the XML: run `doxygen` from within the example folder.
64-
2. Rebuild the Moxygen output: from within this directory,
77+
Moxygen uses Handlebars templates for output. The default modern templates produce clean Markdown with code-block signatures and parameter tables.
6578

79+
To use the classic (pre-1.0) template style:
6680
```
67-
node bin/moxygen.js --groups --pages --anchors --output=example/doc/api-%s.md example/xml
81+
moxygen --templates ./templates/classic /path/to/xml
82+
```
83+
84+
To create your own templates, copy the `templates/cpp/` directory and modify. Templates receive the full parsed compound data including structured parameter info, inheritance, and more.
85+
86+
## Programmatic API
87+
88+
```typescript
89+
import { run } from 'moxygen';
90+
91+
await run({
92+
directory: '/path/to/doxygen/xml',
93+
output: 'api.md',
94+
anchors: true,
95+
});
6896
```
6997

70-
## Development & Contribution
98+
## Development
7199

72-
You can develop this project as you would any other Node project:
100+
```bash
101+
npm install
102+
npm run build
103+
npm test
104+
```
73105

74-
1. Clone this repo.
75-
2. `npm install` from this directory.
106+
To test against the example:
107+
```bash
108+
npm run example
109+
```
76110

77-
This project is tested through integration, by building the `example/`. To quickly test this project:
111+
## Licence
78112

79-
1. Install `doxygen` (`brew install doxygen`, `choco install doxygen`, for example). Only must be done once per computer.
80-
2. `npm test` from this directory. This will run Doxygen on the `example/` and build the output.
113+
MIT

TODO.md

Lines changed: 0 additions & 7 deletions
This file was deleted.

bin/moxygen.js

Lines changed: 0 additions & 48 deletions
This file was deleted.

example/doc/api-bicycle.md

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,59 @@
1-
# group `bicycle` {#group__bicycle}
1+
# bicycle {#group__bicycle}
22

33
Bicycle module contains the bicycle class. Bicycles are a useful way of transporting oneself, without too much effort.
44

5-
## Summary
5+
### Classes
66

7-
Members | Descriptions
8-
--------------------------------|---------------------------------------------
9-
`class `[`transport::Bicycle`](#classtransport_1_1Bicycle) | Standard bicycle class.
7+
| Name | Description |
8+
|------|-------------|
9+
| [`Bicycle`](#classtransport_1_1Bicycle) | Standard bicycle class. |
1010

11-
# class `transport::Bicycle` {#classtransport_1_1Bicycle}
11+
## Bicycle {#classtransport_1_1Bicycle}
12+
13+
> **Subclasses:** `transport::MountainBike`, `transport::RacingBike`
14+
> **Defined in:** `bicycle.h`
1215
1316
Standard bicycle class.
1417

1518
[Bicycle](#classtransport_1_1Bicycle) implements a standard bicycle. Bicycles are a useful way of transporting oneself, without too much effort (unless you go uphill or against the wind). If there are a lot of people on the road, you can use `RingBell` to ring your bell (**note**, not all bicycles have bells!).
1619

17-
## Summary
20+
### Members
21+
22+
| Name | Description |
23+
|------|-------------|
24+
| [`PedalHarder`](#classtransport_1_1Bicycle_1a7df6cce8f18012fb07bef5be9dadd8ef) | PedalHarder makes you go faster (usually). |
25+
| [`RingBell`](#classtransport_1_1Bicycle_1a7d2be572f09c78b4d4ae38ef22f3e98b) | Ring bell on the bike. |
26+
| [`~Bicycle`](#classtransport_1_1Bicycle_1a5f62d09b772a7705634bfb3551803c25) | Default destructor. |
1827

19-
Members | Descriptions
20-
--------------------------------|---------------------------------------------
21-
`public virtual void `[`PedalHarder`](#classtransport_1_1Bicycle_1a7df6cce8f18012fb07bef5be9dadd8ef)`()` | PedalHarder makes you go faster (usually).
22-
`public virtual void `[`RingBell`](#classtransport_1_1Bicycle_1a7d2be572f09c78b4d4ae38ef22f3e98b)`()` | Ring bell on the bike.
23-
`public virtual `[`~Bicycle`](#classtransport_1_1Bicycle_1a5f62d09b772a7705634bfb3551803c25)`()` | Default destructor.
28+
---
2429

25-
## Members
30+
#### PedalHarder {#classtransport_1_1Bicycle_1a7df6cce8f18012fb07bef5be9dadd8ef}
2631

27-
#### `public virtual void `[`PedalHarder`](#classtransport_1_1Bicycle_1a7df6cce8f18012fb07bef5be9dadd8ef)`()` {#classtransport_1_1Bicycle_1a7df6cce8f18012fb07bef5be9dadd8ef}
32+
```cpp
33+
virtual void PedalHarder()
34+
```
2835

2936
PedalHarder makes you go faster (usually).
3037

31-
#### `public virtual void `[`RingBell`](#classtransport_1_1Bicycle_1a7d2be572f09c78b4d4ae38ef22f3e98b)`()` {#classtransport_1_1Bicycle_1a7d2be572f09c78b4d4ae38ef22f3e98b}
38+
---
39+
40+
#### RingBell {#classtransport_1_1Bicycle_1a7d2be572f09c78b4d4ae38ef22f3e98b}
41+
42+
```cpp
43+
virtual void RingBell()
44+
```
3245

3346
Ring bell on the bike.
3447

3548
RingBell rings the bell on the bike. Note that not all bikes have bells.
3649

37-
#### `public virtual `[`~Bicycle`](#classtransport_1_1Bicycle_1a5f62d09b772a7705634bfb3551803c25)`()` {#classtransport_1_1Bicycle_1a5f62d09b772a7705634bfb3551803c25}
50+
---
51+
52+
#### ~Bicycle {#classtransport_1_1Bicycle_1a5f62d09b772a7705634bfb3551803c25}
53+
54+
```cpp
55+
virtual ~Bicycle()
56+
```
3857

3958
Default destructor.
4059

0 commit comments

Comments
 (0)