@title Authors Style Guide @intro Style Guide for Angular Authors @description This guide covers design and layout patterns for documentation for Angular. The patterns should be followed by Authors contributing to this documentation. Throughout this guide, patterns are illustrated by first showing a working example and then presenting working code for that example. ## Basic Layout You will use the following layouts throughout your documentation to specify sections and sub-sections of content. ## Main Section Title Main section titles should preceeded by ##. This is equvalent to the h2 HTML tag. Content for this section can start on the next line. ## Sub Section Title The content in any sub-section is related to the main section and _falls within_ the main section. Any sub-section title should preceeded by ###. This is equivalent to the h3 HTML tag. Content for this sub-section can start on the next line. ### Additional Sub Section Information To present more detailed information to the user that may require redirection to other pages, internal or external to the docs, you can use class 'l-sub-section'. Here is an example of such a sub-section.
You'll learn about more styles for live examples in the [section below](guide/docs-style-guide#section-LiveExamples).
The code for this is here. ```html
You'll learn about more sytles for live examples in the [section below](guide/docs-style-guide#section-LiveExamples).
``` Note that blank lines have been left within the div tags. Blank lines within HTML tags is a cue to Markdown to process the tags and the content within these tags as HTML. ## Table of Contents The table of contents (TOC) is automatically generated by fetching section titles and sub-section titles. By default the TOC is two levels deep, that is, it is limited to displaying only the section and sub-section titles. To exclude a section or sub-section title from the TOC, use a class called 'no-toc'. This class must be used in conjunction with HTML heading tags. Titles displayed using Markdown heading hash tags cannot be excluded from the TOC. ### Example ```html

Heading not displated in the TOC

``` ## Left-hand Side Navigation When you create the Markdown file for your guide, and include it at the appropriate location in navigation.json, you should see the title of your guide displayed in the navigation panel on the left hand side of the docs. You can make further modifications to navigation.json to include any sub-chapters you may have. The sub-chapter titles should be displayed in the navigation panel, indented below the title of the main chapter. ## Code Examples Code examples can be used to display code on a page. This code can be displayed inline or displaying by extracting from files. Code examples allow you to display code with line numbers, code of various programming languages, display these in tabbed interfaces and such. ### Code-Example Attributes * path: a file in the content/examples folder * title: seen in the header of the code listing * region: name of a docregion, a merked region in a source file and explained in a section later in this guide * language: specify only for inline examples. Values can be javascript, html, css, typescript, json, sh or any other language that you will use in your Angular application * linenums: true, false, for example linenums=4 to specify that the starting line is 4. When not specified, line numbers are automatically displayed when there are 10 or more lines of code * class: no-box, code-shell, avoid ### Including a code example from the _examples_ folder One of the design goals for this documentation was that any code samples that appear within the documentation be 'testable'. In practice this means that a set of standalone testable examples exist somewhere in the same repository as the rest of the documentation. These examples will each typically consist of a collection of Typescript, HTML, Javascript and CSS files. Clearly there also needs to be some mechanism for including fragments of these files into the Markdown generated HTML. By convention all of the 'testable' examples within this repository should be created within the content/examples folder. #### A Basic Code-example Code-example displays code or content exactly as entered in a code-example. localhost:3000/hero/15 localhost:3004/hero/again ```html localhost:3000/hero/15 localhost:3004/hero/again ``` #### Code from an External File Code-example will read the content/examples/toh-pt1/src/index.html file and include it with the heading 'src/index.html'. Note that the file will be properly escaped and color coded according to the extension on the file (html in this case). The code will be displayed as shown here. The code for the above example is displayed below. ```html ``` #### Commands in a Command Window To display commands in a command window, you can use the code-shell class supported by code-examples. npm start The code below uses the code-shell class to display the command terminal and code within the terminal. ```html npm start ``` #### Example of Code to be Avoided To present code that users should avoid, you can use a class called avoid. <hero-details nghost-pmm-5> <h2 ngcontent-pmm-5>Mister Fantastic</h2> <hero-team ngcontent-pmm-5 nghost-pmm-6> <h3 _ngcontent-pmm-6>Losing Team</h3> </hero-team> </hero-details> The code to create this display is below. ```html nghost-pmm-5>

ngcontent-pmm-5>Mister Fantastic

ngcontent-pmm-5 nghost-pmm-6>

_ngcontent-pmm-6>Losing Team

``` #### Example of HTML code Backticked code blocks can be used to enclose HTML code without using escape characters. ```html

Mister Fantastic

Losing Team

``` You can use the syntax below to enclose HTML within a backticked code block. ```html <hero-details> <h2>Mister Fantastic</h2> <hero-team> <h3>Losing Team</h3> </hero-team> </hero-details> ``` #### Marking up a Source File To mark any part of a file, add a single comment line in the line above the area to be marked. The comment should contain the string #docregion. Optionally, a second string can follow. The second string is the 'name' of the region. A file may have any number of #docregion comments with the only requirement being that the names of each region within a single file be unique. This also means that there can only be one blank docregion. Further, docregions can be nested.
Docregions are not supported in JSON
#### Example of a nested docregion: // #docregion export-AppComponent export class AppComponent { title = 'Tour of Heroes'; heroes = HEROES; // #docregion selected-hero selectedHero: Hero; // #enddocregion selected-hero // #docregion on-select, onSelect-parameters onSelect(hero: Hero): void { this.selectedHero = hero; } // #enddocregion on-select } // #enddocregion export-AppComponent <code-example path="docs-style-guide/app.component.ts" linenums="false" title="a docregion" region="selected-hero"> </code-example> <code-example path="docs-style-guide/app.component.ts" linenums="false" title="Multiple docregions" region="onSelect-parameters"> </code-example> Here is code for the above code-examples that use docregions. HTML files can also contain docregions: ```html ... ... ``` as can CSS files: ```html /* #docregion center-global */ .center-global { max-width: 1020px; margin: 0 auto; } ``` ## Code Tabs Code tabs display code much like Code examples do. The added advantage is that they can display mutiple code samples within a tabbed interface. Each tab is displayed using Code-pane. ### Code-tabs Attributes * linenums: true, false, display line numbers in the code in all tabs when the number of code statements are 10 or more ### Code-pane Attributes * path: a file in the content/examples folder * title: seen in the header of a tab * linenums: true, false, display line numbers for the code in this tab when the number of code statements are 10 or more The example below uses the source code for a small application that bundles with Webpack techniques. This will create multiple tabs, each with its own title and be appropriately color coded. By default, line numbers are shown. Line number display can be specified using the linenums attribute at the code tab or code pane level. The example below shows us how to display line numbers in just one code pane. The code below will create multiple tabs, each with its own title and be appropriately color coded. ```html ``` {@a section-LiveExamples} ## Live Examples Here is how we do live examples. All examples here will point to other guides such as TOH-6 for convenience. ### Plain Live Example When a live example is included in a guide, it allows readers to run the example and download the code that the Author has placed in the content/examples folder for their respective guide. A plain live example looks like this: The code is shown here. ```html ``` ### Live Example with Title Attribute To replace 'live-example' with a title, you can provide a title as shown here. ```html ``` ### Live Example with Body Another way to display aletrnative text for 'live-example' is to include it in the body of the live-example. The effect is the same as when you use the title attribute. ```html Live Example Flesh & Blood ``` ### Live Example from Another Guide Example of live-example from the router guide Live Example from the Router guide. ```html Live Example from the Router guide ``` ### Live Example other than Default for Guide ```html ``` ### Live Example Without Download ```html ``` ### Live Example with only Download ```html ``` ### Live Example with Embedded Plunkers Embedded Plunkrs have default image. img allows you to override the default image. ```html ``` {@a section-Anchors} ## Anchors To mark a location that a reader should reach when they click an anchor link, insert the anchor tag shown below at that location. My location has been marked using {@ section-Anchors} To use this anchor, replace alternative text below with text that will be visible to the reader and that the reader will click on. Replace path-to-page/dir-of-page with the relative path to the page that has the location that the reader should reach. ```html [alternative text] (path-to-page/dir-of-page/#section-Anchors) ``` ## Alerts Please use alerts sparingly throughout the docs. They are meant to draw attention to important occasions. Alerts should not be used for multi-line content (use callouts insteads) or stacked on top of each other. Note that the content of an alert is indented to the right by two spaces.
A very critical alert.
A very important alert.
A very helpful alert.
Here is sample code to generate alerts. ```html
A very critical alert.
A very important alert.
A very helpful alert.
``` ## Callouts Please use callouts sparingly throughout the docs. Callouts (like alerts) are meant to draw attention to important occasions. Unlike alerts, callouts are designed to display multi-line content.
A CRITICAL TITLE
Pitchfork hoodie semiotics, roof party pop-up paleo messenger bag cred Carles tousled Truffaut yr. Semiotics viral freegan VHS, Shoreditch disrupt McSweeney's. Intelligentsia kale chips Vice four dollar toast, Schlitz crucifix
A VERY IMPORTANT TITLE
Pitchfork hoodie semiotics, roof party pop-up paleo messenger bag cred Carles tousled Truffaut yr. Semiotics viral freegan VHS, Shoreditch disrupt McSweeney's. Intelligentsia kale chips Vice four dollar toast, Schlitz crucifix
A VERY HELPFUL TITLE
Pitchfork hoodie semiotics, roof party pop-up paleo messenger bag cred Carles tousled Truffaut yr. Semiotics viral freegan VHS, Shoreditch disrupt McSweeney's. Intelligentsia kale chips Vice four dollar toast, Schlitz crucifix
Here is sample code to generate important callouts. ```html
A VERY IMPORTANT TITLE
Pitchfork hoodie semiotics, roof party pop-up paleo messenger bag cred Carles tousled Truffaut yr. Semiotics viral freegan VHS, Shoreditch disrupt McSweeney's. Intelligentsia kale chips Vice four dollar toast, Schlitz crucifix
``` ## Trees Trees can be used to represent heirarchial data. Here is an example.
sample-dir
src
app
app.component.ts
app.module.ts
styles.css
tsconfig.json
node_modules ...
package.json
Here is the code for this tree. ```html
sample-dir
src
app
app.component.ts
app.module.ts
styles.css
tsconfig.json
node_modules ...
package.json
``` ## Tables Tables can be used to present tabular data as it relates to each other.
Framework Task Speed
AngularJS Routing Fast
Angular 2 Routing Faster
Angular 4 Routing Fastest :)
Here is code for this table. ```html table tr th Framework th Task th Speed tr td AngularJS td Routing td fast tr td Angular 2 td Routing td faster ``` ## Images ### Using Images HTML should be used to declare images in the docs. Do not use the markdown \!\[\.\.\.\]\(\.\.\.\) shorthand. The HTML to use is an <img src="..." alt="..."> tag. You must supply a src attribute that is relative to the base path; and you should provide an alt attribute describing the image for accessibility. _Note that Image tags do not have a closing tag._ ### Image Size The doc generation process will read the image dimensions and automatically add width and height attributes to the img tag. If you want to control the size of the image then you should supply your own width and height images. Images should not be wider than 700px otherwise they may overflow the width of the document in certain viewports. If you wish to have a larger image then provide a link to the actual image that the user can click on to see the larger images separately. ### Image Formatting There are three types of images that you can put in docs: inline, floating and standalone. #### Inline Images To create an inline image, simply place the img tag in the content where you want the image to appear. For example: ```html The image here ... is visible inline in the text. ``` #### Floating Images You can cause an image to float to the left or right of the text by applying the class="left" or class="right" attributes respectively. ```html ...This text will wrap around the to the right of this floating image. ``` All headings and code-examples will automatically clear a floating image. If you need to force a piece of text to clear a floating image then you can use the following snippet: ```html
``` Finally, if you have floating images inside alerts or sub-sections then it is a good idea to apply the clear-fix class to the div to ensure that the image doesn't overflow its container. For example: ```html
... Some **markdown** formatted text.
``` #### Standalone Images Some images should stand alone from the text. You do this by wrapping the img tag in a figure tag. This causes the image to get additional styling, such as a rounded border and shadow. The text will not flow around this image but will stop before the image and start again afterword. For example: ```html Some paragraph preceding the image.
```