|
| 1 | +# Usage |
| 2 | +Projects using `cppdoc` must have a `cppdoc.toml` configuration file, see [CONFIG.md](CONFIG.md) for the available configuration options. |
| 3 | + |
| 4 | +## Command-line options: |
| 5 | +To build documentation for a project: |
| 6 | + |
| 7 | +``` |
| 8 | +cppdoc build |
| 9 | +``` |
| 10 | + |
| 11 | +To output JSON representing the codebase: |
| 12 | + |
| 13 | +``` |
| 14 | +cppdoc build -d |
| 15 | +``` |
| 16 | + |
| 17 | +More command-line options can be displayed using `-h` or `--help`. |
| 18 | + |
| 19 | + |
| 20 | +## Comments |
| 21 | +Comments are written using `///` or `//<`, the latter being used for inline documentation, as such: |
| 22 | + |
| 23 | +```cpp |
| 24 | +/// Documentation for 'MyEnum' |
| 25 | +enum MyEnum { |
| 26 | + A //< Documentation for 'A' |
| 27 | +} |
| 28 | +``` |
| 29 | + |
| 30 | +Comments content are parsed as cppdoc-flavored markdown, there is no support for `javadoc`/Doxygen-style comments. |
| 31 | + |
| 32 | +## Markdown syntax |
| 33 | +`cppdoc` introduces a few extensions to markdown. |
| 34 | + |
| 35 | +- To link documentation objects, one must prefix the link path with `::`. For example: |
| 36 | + |
| 37 | +``` |
| 38 | +See [MyStruct](::MyStruct) |
| 39 | +``` |
| 40 | + |
| 41 | +- Mermaid graphs can be displayed using `mermaid` codeblocks: |
| 42 | + |
| 43 | +```mermaid |
| 44 | +graph TD; |
| 45 | + A-->B; |
| 46 | + A-->C; |
| 47 | + B-->D; |
| 48 | + C-->D; |
| 49 | +``` |
| 50 | + |
| 51 | +## Documentation tests |
| 52 | +`cppdoc` supports running documentation tests akin to `rustdoc`, these tests are written in `cpp` and `c++` codeblocks and help ensure that code examples are up-to-date with API usage. |
| 53 | + |
| 54 | +Documentation codeblocks feature special syntax: |
| 55 | +- Lines prefixed with `@` won't be displayed, but will be added to the source code: |
| 56 | + |
| 57 | +``` |
| 58 | +@int a = 1; |
| 59 | +int b = a + 2; |
| 60 | +``` |
| 61 | + |
| 62 | +Will only display: |
| 63 | + |
| 64 | +``` |
| 65 | +int b = a + 2; |
| 66 | +``` |
| 67 | + |
| 68 | +But will be compiled fully, that is with `int a = 1` included. |
| 69 | + |
| 70 | + |
| 71 | +- Similarly, `@include` allows for quiet inclusion of a header file: |
| 72 | + |
| 73 | +``` |
| 74 | +@include "file.h" |
| 75 | +int a = 1; |
| 76 | +``` |
| 77 | + |
| 78 | +Will only display: |
| 79 | + |
| 80 | +``` |
| 81 | +int a = 1; |
| 82 | +``` |
| 83 | + |
| 84 | +Notice that documentation tests don't need a `main` function, this is because documentation tests run by default in `main`, to disable this behavior one must set the codeblock language to `nomain` instead of `c++` or `cpp`. |
| 85 | + |
| 86 | + |
| 87 | +### Test framework |
| 88 | +`cppdoc` includes a basic test framework for documentation tests, this is useful for testing that examples still run successfully. |
| 89 | +The following macros are defined: |
| 90 | + |
| 91 | +- `ASSERT` and `ASSERT_EQ`: test for truth and equality, respectively |
| 92 | +- `ASSERT_FALSE` and `ASSERT_NE`: test for falsity and inequality, respectively |
| 93 | +- `ASSERT_GT` and `ASSERT_LT`: test for greater than and less than, respectively |
| 94 | +- `ASSERT_GE` and `ASSERT_LE`: test for greater than or equal and less than or equal, respectively |
| 95 | + |
| 96 | +Therefore, it is possible to write code like so: |
| 97 | + |
| 98 | +```c++ |
| 99 | +int a = 1; |
| 100 | + |
| 101 | +ASSERT(a == 1); |
| 102 | +``` |
| 103 | +
|
| 104 | +The code above will compile and run successfuly, but the following code will fail to run: |
| 105 | +
|
| 106 | +```c++ |
| 107 | +int a = 2; |
| 108 | +ASSERT(a == 1); |
| 109 | +``` |
| 110 | + |
| 111 | + |
| 112 | +# Styling |
| 113 | +`cppdoc` expects a `style.css` file to be present at the root of the generated documentation. It is recommended to put the stylesheets in a static directory and set the `static` option in the configuration file. |
0 commit comments