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 2 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
30 changes: 29 additions & 1 deletion styleguide/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,35 @@ 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.
Any language supported by [highlight.js](http://highlightjs.readthedocs.io/en/latest/css-classes-reference.html#language-names-and-aliases)
is supported.

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 region
Copy link
Contributor

Choose a reason for hiding this comment

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

"For cases where regions don't work, you can specify the start and end of a region" ->
For cases where regions don't work, you can specify the start and end of your snippet? it's a bit confusing to say regions don't work, so specify a region

using a triple-slash comment and an XML element name. 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 CI
Copy link
Contributor

Choose a reason for hiding this comment

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

CI -> 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