diff --git a/MarkdownSource/acknowledgements.md b/MarkdownSource/acknowledgements.md index 27b9196..d5d3db9 100644 --- a/MarkdownSource/acknowledgements.md +++ b/MarkdownSource/acknowledgements.md @@ -6,3 +6,4 @@ This application wouldn't be possible without the work of others. The (likely in * [MkDocs](http://www.mkdocs.org/). `Docnet` borrows a great deal from `MkDocs`: the theme css `Docnet` uses is based on a cleaned up version of their `Readthedocs` theme, as well as the javascript based search is from MkDocs. * [MarkdownDeep](http://www.toptensoftware.com/markdowndeep/). The markdown parser is an extended version of the `MarkdownDeep` parser from topten software. * [Json.NET](http://www.newtonsoft.com/json). The reading/writing of json files is important for `Docnet` and it uses Json.NET for that. +* [ProjBook](http://defrancea.github.io/Projbook/). The snippet extraction code in `DocNet` is based on ProjBook's extractors. \ No newline at end of file diff --git a/MarkdownSource/docnet.json b/MarkdownSource/docnet.json index 955a0ed..d268a83 100644 --- a/MarkdownSource/docnet.json +++ b/MarkdownSource/docnet.json @@ -3,7 +3,7 @@ "Source" : ".", "Destination" : "..\\", "IncludeSource": "Includes", - "Theme" : "Default", + "Theme" : "Light", "Footer" : "Made with DocNet. Get your copy at: https://github.com/FransBouma/DocNet.", "Pages" : { diff --git a/MarkdownSource/markdownextensions.md b/MarkdownSource/markdownextensions.md index 79cfd15..ecded4d 100644 --- a/MarkdownSource/markdownextensions.md +++ b/MarkdownSource/markdownextensions.md @@ -116,6 +116,27 @@ Now, the second tab however is very interesting. At least let's pretend it is! @end @endtabs + +##Snippets +You can include snippets from other files as fenced code blocks using the directive `@snippet` which has the following syntax: + +`@snippet language [file specification] pattern` + +Here, _language_ can be one of `cs`, `txt` or `xml`. If an unknown language is specified, `txt` is chosen. _Pattern_ is used to determine which part of the file specified between `[]` +is to be embedded at the spot of the `@snippet` fragment. This code is based on [Projbook's extractor feature](http://defrancea.github.io/Projbook/projbook.html#Pageextractormd) and follows the same pattern system. + +Below, the method `GenerateToCFragment` is embedded in a C# fenced code block. This method is a DocNet method and is obtained directly from the source code. This shows the `@snippet` +feature's power as it keeps the documentation in sync with the embedded code without the necessity of updating things. + +The following snippet, if the DocNet sourcecode is located at the spot reachable by the path below: + +```nohighlight +@snippet cs [../../DocNet/src/DocNet/NavigationLevel.cs] GenerateToCFragment +``` + +will result in: +@snippet cs [../../DocNet/src/DocNet/NavigationLevel.cs] GenerateToCFragment + ##Include files You can include other files in your markdown files using the directive `@@include("filename")`, where `filename` is the name of the file to include. The include system isn't recursive. The files to include are read from a special folder, specified under `IncludeSource` in the [docnet.json](docnetjson.htm) file. If no `IncludeSource` directive is diff --git a/acknowledgements.htm b/acknowledgements.htm index 5f1ae33..8d9ba9f 100644 --- a/acknowledgements.htm +++ b/acknowledgements.htm @@ -76,6 +76,7 @@
Docnet borrows a great deal from MkDocs: the theme css Docnet uses is based on a cleaned up version of their Readthedocs theme, as well as the javascript based search is from MkDocs. MarkdownDeep parser from topten software.
Docnet and it uses Json.NET for that. DocNet is based on ProjBook's extractors. This is the text for the first tab. It's nothing special
As you can see, it can deal with newlines as well.
Now, the second tab however is very interesting. At least let's pretend it is!
-You can include snippets from other files as fenced code blocks using the directive @snippet which has the following syntax:
@snippet language [file specification] pattern
Here, language can be one of cs, txt or xml. If an unknown language is specified, txt is chosen. Pattern is used to determine which part of the file specified between []
+is to be embedded at the spot of the @snippet fragment. This code is based on Projbook's extractor feature and follows the same pattern system.
Below, the method GenerateToCFragment is embedded in a C# fenced code block. This method is a DocNet method and is obtained directly from the source code. This shows the @snippet
+feature's power as it keeps the documentation in sync with the embedded code without the necessity of updating things.
The following snippet, if the DocNet sourcecode is located at the spot reachable by the path below:
+@snippet cs [../../DocNet/src/DocNet/NavigationLevel.cs] GenerateToCFragment +
will result in:
+/// <summary>
+/// Generates the ToC fragment for this element, which can either be a simple line or a full expanded menu.
+/// </summary>
+/// <param name="navigatedPath">The navigated path to the current element, which doesn't necessarily have to be this element.</param>
+/// <param name="relativePathToRoot">The relative path back to the URL root, e.g. ../.., so it can be used for links to elements in this path.</param>
+/// <returns></returns>
+public override string GenerateToCFragment(NavigatedPath navigatedPath, string relativePathToRoot)
+{
+ var fragments = new List<string>();
+ if(!this.IsRoot)
+ {
+ fragments.Add("<li class=\"tocentry\">");
+ }
+ if(navigatedPath.Contains(this))
+ {
+ // we're expanded. If we're not root and on the top of the navigated path stack, our index page is the page we're currently generating the ToC for, so
+ // we have to mark the entry as 'current'
+ if(navigatedPath.Peek() == this && !this.IsRoot)
+ {
+ fragments.Add("<ul class=\"current\">");
+ }
+ else
+ {
+ fragments.Add("<ul>");
+ }
+
+ // first render the level header, which is the index element, if present or a label. The root always has an __index element otherwise we'd have stopped at load.
+ var elementStartTag = "<li><span class=\"navigationgroup\"><i class=\"fa fa-caret-down\"></i> ";
+ var indexElement = this.IndexElement;
+ if(indexElement == null)
+ {
+ fragments.Add(string.Format("{0}{1}</span></li>", elementStartTag, this.Name));
+ }
+ else
+ {
+ if(this.IsRoot)
+ {
+ fragments.Add(indexElement.PerformGenerateToCFragment(navigatedPath, relativePathToRoot));
+ }
+ else
+ {
+ fragments.Add(string.Format("{0}<a href=\"{1}{2}\">{3}</a></span></li>", elementStartTag, relativePathToRoot, HttpUtility.UrlPathEncode(indexElement.TargetURL),
+ this.Name));
+ }
+ }
+ // then the elements in the container. Index elements are skipped here.
+ foreach(var element in this.Value)
+ {
+ fragments.Add(element.GenerateToCFragment(navigatedPath, relativePathToRoot));
+ }
+ fragments.Add("</ul>");
+ }
+ else
+ {
+ // just a link
+ fragments.Add(string.Format("<span class=\"navigationgroup\"><i class=\"fa fa-caret-right\"></i> <a href=\"{0}{1}\">{2}</a></span>",
+ relativePathToRoot, HttpUtility.UrlPathEncode(this.TargetURL), this.Name));
+ }
+ if(!this.IsRoot)
+ {
+ fragments.Add("</li>");
+ }
+ return string.Join(Environment.NewLine, fragments.ToArray());
+}
+
+
+You can include other files in your markdown files using the directive @@include("filename"), where filename is the name of the file to include. The include system isn't recursive.
The files to include are read from a special folder, specified under IncludeSource in the docnet.json file. If no IncludeSource directive is
specified in the docnet.json file, the folder Includes is assumed.