Documenting Your Code Comments · Text Files · Keywords, Topics, and Scope · Linking Formatting and Layout · Page Titles · Summaries · Javadoc Compatibility
Comments There is no special comment style for Natural Docs. You just embed Natural Docs topics into regular comments, and it’s pretty tolerant as far as style goes. You can use block comments or string together line comments. The only requirement is that the comments are not on the same line as code. /* Function: Multiply Multiplies two integers and returns the result. */ // Function: Multiply // Multiplies two integers and returns the result. Note that when stringing line comments together, blank lines that you want to include in the documentation must start with the comment symbol as well. If a line is completely blank, it’s considered the end of the comment and thus the end of the Natural Docs topic. Boxes and Horizontal Lines Natural Docs can also handle comment boxes and horizontal lines. It doesn’t matter what symbols they use. The boxes don’t need to be closed on the right side, and they can have different symbols for the edges and corners. /* * Function: Multiply * Multiplies two integers and returns the result. */ /* +-------------------------------------------------+ | Function: Multiply | | Multiplies two integers and returns the result. | +-------------------------------------------------+ */ ////////////////////////////////////////////////////////////// // // Function: Multiply // ------------------ // // Multiplies two integers together and returns the result. // ////////////////////////////////////////////////////////////// Javadoc Style If you have full language support, you can also use Javadoc-style comments to write Natural Docs documentation. To do this you repeat the last symbol on the first line of the comment once. The comment must appear directly above what it’s documenting, and you can omit the topic line if you want (the “ /** * Multiplies two integers and returns the result. */ /// // Multiplies two integers together and returns the result. If you omit the topic line and include any Javadoc tags in the comment, like Perl POD Perl users can also use POD to do block comments. =begin nd Function: Multiply Multiplies two integers and returns the result. =cut You can also use There’s a second form of just =nd Function: Multiply Multiplies two integers and returns the result. =cut Text Files Documentation can also be included in text files. Any file with a .txt extension appearing in the source tree and starting with a topic line will included in the documentation. It will be treated the same as a source file, meaning it will appear in the menu, its topics will be in the indexes, and its topics can be linked to from anywhere in the documentation. The only difference is you don’t need comment symbols. Remember that the topic line is required to be the first line of content. If the first non-blank line is not in the “ Title: License This project is licensed under the GPL. This method is convenient for documenting file formats, configuration settings, the general program architecture, or anything else that isn’t directly tied to a source file. Keywords, Topics, and Scope A topic in Natural Docs starts with a topic line in the format The list of keywords is pretty predictable: Function, Class, Variable, etc. Just use what you’re documenting. There are many synonyms as well, so you can use keywords like Func, Procedure, Proc, Method and Constructor. Look at the full list of keywords to see everything that’s available. The list of keywords is separated into topic types. Each type gets its own index, and which specific keyword you use doesn’t matter. Some also have scoping rules or other behavior as noted. Scope Like the code it’s documenting, Natural Docs topics have scope. This mostly has to do with linking: if you’re in a class you can link to its members by their name alone, but if you’re not, you have to use a notation like If you have full language support and are documenting something that appears in the code, the scope will be handled automatically. If you’re using text files, have basic language support, or are including a topic that doesn’t correspond to something in the code, scoping follows these rules:
List Topics If you looked at the list, you saw that most of the keywords have plural forms. That’s for list topics, which let you document many small things without using the full syntax. Anything that appears in definition lists within that topic will be treated as if it had its own topic. It will appear in the indexes and be linkable, just like normal topics. Function list topics will automatically break apart in the output as well, so it will look the same as if you documented each one individually. Linking Linking is the one place where Natural Docs has some negative effect on the readability of the comments. The alternative would be to automatically guess where links should be, but systems that do that can sometimes pepper your sentences with unintentional links to functions called “is” or “on”. However, the Natural Docs syntax is still as minimal as possible. Simply surround any topic you want to link to with angle brackets. Natural Docs will keep track off all the topics and where they are defined, so you don’t need to use HTML-like syntax or remember what file anything is in. Also, if the link can’t be resolved to anything, Natural Docs leaves the angle brackets in the output so if something wasn’t intended to be a link (such as Let's link to function <Multiply>. Let’s link to function Multiply. Links and topic names are case sensitive, regardless of whether the language is or not. When linking to functions, it doesn’t matter if you include empty parenthesis or not. Both If the topic has a summary sentence, hovering over the link will give it to you as a tooltip. If the topic has a prototype, that will be included as well. You can try it above. Scope If a topic is considered part of a class, they can be linked to using any of the three most common class/member notations: If you have multi-level classes and packages, links can be relative as well. So if you’re in Plurals and Possessives To make the documentation easier to write and easier to read in the source file, you can include plurals and possessives inside the angle brackets. In other words, you don’t have to use awkward syntax like URLs and E-Mail You can also link to URLs and e-mail addresses. It will detect them automatically, but you can also put them in angle brackets if you like. Visit <http://www.website.com> or send messages to email@address.com. Visit http://www.website.com or send messages to em@addre ss.com. ail E-mail addresses are protected in a way that should avoid spam crawlers. Although the link above looks and acts like a regular link (try it) the HTML code actually looks like this: <a href="#" onClick="location.href='mai' + 'lto:' + 'em' + 'ail' + '@' + 'addre' + 'ss.com'; return false;"> em<span style="display: none">.nosp@m.</span>ail <span>@</span> addre<span style="display: none">.nosp@m.</span>ss.com </a> Formatting and Layout You can apply additional formatting and layout to your Natural Docs content, all in ways that will appear very natural in the source code. Paragraphs You can break paragraphs by leaving blank lines between them. So we have this in our content: The first paragraph blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah. The second paragraph blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah. and we get this in our output: The first paragraph blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah. The second paragraph blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah. Bold and Underline You can apply bold to a stretch of text by surrounding it with asterisks. You can apply underlining by surrounding it with underscores instead. With underlining, it doesn’t matter if you use an underscore for every space between words or not; they’ll be converted to spaces if you do. Some *bold text* and some _underlined text_ and yet _more_underlined_text_. Some bold text and some underlined text and yet more underlined text. Headings You can add headings to your output just by ending a line with a colon and having a blank line above it. Some text before the heading. Heading: Some text under the heading. Some text before the heading. HeadingSome text under the heading. You must have a blank line above the heading or it will not work. You can skip the blank after it but not before. Bullet Lists You can add bullet lists by starting a line with a dash, an asterisk, an o, or a plus. Bullets can have blank lines between them if you want, and subsequent lines don’t have to be indented. You end a list by skipping a line and doing something else. - Bullet one. - Bullet two. Bullet two continued. - Bullet three. Some text after the bullet list. o Spaced bullet one. o Spaced bullet two. Spaced bullet two continued. o Spaced bullet three. Some text after the spaced bullet list.
Some text after the bullet list.
Some text after the spaced bullet list. Definition Lists You can add a definition list by using the format below, specifically “text space dash space text”. Like bullet lists, you can have blank lines between them if you want, subsequent lines don’t have to be indented, and you end the list by skipping a line and doing something else. First - This is the first item. Second - This is the second item. This is more of the second item. Third - This is the third item. This is more of the third item. Some text after the definition list.
Some text after the definition list. Remember that with definition lists, if you’re using the plural form of the keywords each entry can be linked to as if it had its own topic. Code and Text Diagrams You can add example code or text diagrams by starting each line with : a = b + c; > +-----+ +-----+ > | A | --> | B | > +-----+ +-----+ > | > +-----+ > | C | > +-----+ a = b + c; +-----+ +-----+ For long stretches, this may be too tedious. You can start a code section by placing (start code) if (x == 0) { DoSomething(); } return x; (end) if (x == 0) { You can also use Images You can include images in your documentation by writing “ This is the first paragraph. (see logo.gif) This is the second paragraph. This is the first paragraph. This is the second paragraph. If it’s not alone on a line the image will appear after the end of the paragraph, the text will become a link to it, and the file name will be used as a caption. This is the first paragraph (see logo.gif) This is more of the first paragraph. This is the first paragraph (see logo) This is more of the first paragraph. The image file names are relative to the source file the comment appears in or any directories specified with the Natural Docs supports gif, jpg, jpeg, png, and bmp files. Page Titles Natural Docs automatically determines the page title as follows:
This should be enough for most people. However, if you don’t like the page title Natural Docs has chosen for you, add a “ Summaries Summaries are automatically generated for every file, class, and section. You don’t have to do anything special to get them. There are two things you may want to keep in mind when documenting your code so that the summaries are nicer. The first is that they use the first sentence in the topic as the description, so long as it’s plain text and not something like a bullet list. It will also appear in the tooltip whenever that topic is linked to. The second is that you may want to manually add group topics to divide long lists and make the summaries easier to navigate. Natural Docs will automatically group them by type if you do not, but sometimes you want to be more specific. You don’t need to provide a description, just adding a “ Here’s an example summary. Note that as before, when you hover over a link, you’ll get the prototype and summary line as a tooltip. Summary
Javadoc Compatibility If you have full language support Natural Docs will also extract documentation from actual Javadoc comments, not just Natural Docs comments written with the Javadoc comment symbols. This provides you with a good method of migrating to Natural Docs as you don’t have to convert all of your existing documentation. /** * Multiplies two integers. * * @param x The first integer. * @param y The second integer. * @return The two integers multiplied together. * @see Divide */ While most Javadoc tags and simple HTML formatting are supported, Natural Docs is not a full Javadoc parser and may not support some advanced tags and HTML. See this page for a list of what’s supported and what isn’t. A source file can contain both Natural Docs and Javadoc comments. However, you cannot mix the two within a single comment. For example, you can’t use asterisks for bold in a | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Copyright © 2003-2008 Greg Valure |