Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recommend snippet syntax #1209

Merged
merged 5 commits into from
Nov 8, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion styleguide/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,53 @@ You can use a [Markdown table generator tool](http://www.tablesgenerator.com/mar

## Code

### Code blocks with language identifier
The best way to include code is to include snippets from a working sample. Create your
sample following the instructions in the [contributing guide](../CONTRIBUTING.md#contributing-to-samples).

You can include the code using include syntax:

```
[!code-csharp[<title>](<pathToFile>#<RegionName)]
```

The example above shows C# syntax, but other languages are supported.
Use `code-fsharp` for F# samples; use `code-vbnet` for Visual Basic samples.
Other languages that are supported are:
* C++: `code-cpp`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cpp only like the others? or add code- to all other below?

* HTML: `code-html`
* JavaScript: `code-javascript`
* Powershell: `code-ps`
* SQL: `code-sql`
* XML: `code-xml`



The text you place for `<title>` shows up as a rollover on the text. The `<pathToFile>`
is the path to the source file. The `<RegionName>` should be a region in your source
code that should be included. Use the `#region` and `#endregion` preprocessor syntax
to specify the region of code to include.

For cases where regions don't work, you can specify the start and end of a snippet
using an XML element name in a single line comment. For example, you could write this in C#:

```csharp
// <CodeToInclude>
int j = 5;
int i ; 10;
int sum = i + j;
// </CodeToInclude>
```

In other languages, use the comment syntax for that language.
Finally, you can use line
numbers: `#L1-L10` would include lines 1 through 10. We discourage line numbers
because they are very brittle.

Including snippets from full programs ensures that all code runs through our Continuous Integration (CI)
system. However, if you need to show something that causes compile time or
runtime errors, you can use inline code blocks.

### Inline code blocks with language identifier

Use three backticks (\`\`\`) + a language ID to apply language-specific color coding to a code block. Here is the entire list of [GFM language IDs](https://github.com/jmm/gfm-lang-ids/wiki/GitHub-Flavored-Markdown-(GFM)-language-IDs).

Expand Down