Assembling Documentation with mdoc - Jonathan Pryor's web log
« Exporting mdoc Repositories to Microsoft XML Documentation | Main | Configuring the ASP.NET front-end for mdoc »
Assembling Documentation with mdoc
We previously discussed exporting the mdoc repository into static HTML files using mdoc export-html and into a Microsoft XML Documentation file with mdoc export-msxdoc. Today, we'll discuss exporting documentation with mdoc assemble.
mdoc assemble is used to assemble documentation for use with the monodoc Documentation browser and the ASP.NET front-end. This involves the following steps:
- Running mdoc assemble.
- Writing a .source file.
- Installing the files.
Unfortunately we're taking a diversion from the Windows world, as the monodoc browser and the ASP.NET front-end won't run under Windows (due to limitations in the monodoc infrastructure). I will attempt to fix these limitations in the future.
Running mdoc assemble: mdoc assemble has three arguments of interest:
- -f=FORMAT is used to specify the format of the files to assemble. When documenting assemblies you can skip this, as the default format is for mdoc repositories. This is useful if you want to assemble other materials, such as man pages or plain HTML files.
- -o=PREFIX is used to specify the output prefix. mdoc assemble generates two files, a .tree and a .zip file. The PREFIX value is the basename to use for these to files.
- The list of files or directories to process. Whether these need to be files or directories (and related semantics) depends upon the format specified; see the FORMATS section of the mdoc-assemble(1) man page for details.
For our current documentation, we would run:
$ mdoc assemble -o Demo Documentation/en.docs
This will create the files Demo.tree and Demo.zip in the current working directory.
The .source file is used to tell the documentation browser where in the tree the documentation should be inserted. It's an XML file that contains two things: a (set of) /monodoc///node elements describing where in the tree the documentation should be inserted, and /monodoc/source elements which specify the files to use. For example:
<?xml version="1.0"?> <monodoc> <node label="Demo Library" name="Demo-lib" parent="libraries" /> <source provider="ecma" basefile="Demo" path="Demo-lib"/> </monodoc>
The /monodoc/node element describes where in the monodoc tree the documentation should be placed. It has three attributes, two of which are required:
- label is the text to display in the tree view.
- name is the name of the node, so that other nodes and the /monodoc/source/@path attribute may refer to it.
- parent is optional, and contains the //node/@name
value of the node which should be the parent of this node.
This is used to provide a degree of structure. It should be a value from
$prefix/lib/monodoc/monodoc.xml in the //node/@name
attribute values. Currently these include:
- languages for programming language references, e.g. The C# Language Specification.
- libraries for class library documentation.
- man for man pages and other command references.
- tools and various for anything that doesn't fit in the above descriptions.
The /monodoc/source element describes what file basename to use when looking for the .tree and .zip files. (By convention the .source, .tree, and .zip files share the same basename, but this is not required. The .tree and .zip files must share the same basename, but the .source basename may differ, and will differ if e.g. one .source file pulls in several .tree/.zip pairs.) It has three attributes, all of which are required:
- basefile is the file basename of the .tree and .zip files.
- path is the //node/@name value that will be associated with the docs within basefile.tree and basefile.zip.
- provider is the format provided to mdoc assemble. For assembly documentation, this should be ecma.
Installing the files. Files need to be installed into $prefix/lib/monodoc/sources. You can obtain this directory with pkg-config(1):
$ cp Demo.source Demo.tree Demo.zip \ `pkg-config monodoc --variable=sourcesdir`
Now when we run monodoc, we can navigate to the documentation that was just installed:
Additionally, those paying attention on January 10 will have noticed that the With() method we documented is an extension method. Monodoc supports displaying extension methods on the relevant type documentation. In this case, With() is an extension on TSource, which is, for all intents and purposes, System.Object. Thus, if we view the System.Object docs within our local monodoc browser, we will see the With() extension method:
In fact, we will see With() listed as an extension method on all types (which is arguably a bug, as static types can't have instance methods...).
Furthermore, mdoc export-html will also list extension methods. However, mdoc export-html is far more limited: it will only look for extension methods within the mdoc repositories being processing, and it will only list those methods as extension methods on types within the mdoc repository. Consequently, mdoc export-html will not list e.g. IEnumerable<T> extension methods on types that implement IEnumerable<T>. (It simply lacks the information to do so.)
Examples of mdoc export-html listings of extension methods can be found in the mdoc unit tests and the Cadenza.Collections.CachedSequence<T> docs (which lists a million extension methods because Cadenza.Collections.EnumerableCoda contains a million extension methods on IEnumerable<T>).
Next time, we'll discuss setting up the ASP.NET front end under Linux.
blog comments powered by Disqus