You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* update template to recommend code snippets
We prefer them to inline code that doesn’t run through the CI build.
* Fix contributing link
* update list of languages to the correct smaller set.
* respond to feedback
* respond to feedback.
Copy file name to clipboardExpand all lines: styleguide/template.md
+47-1Lines changed: 47 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -202,7 +202,53 @@ You can use a [Markdown table generator tool](http://www.tablesgenerator.com/mar
202
202
203
203
## Code
204
204
205
-
### Code blocks with language identifier
205
+
The best way to include code is to include snippets from a working sample. Create your
206
+
sample following the instructions in the [contributing guide](../CONTRIBUTING.md#contributing-to-samples).
207
+
208
+
You can include the code using include syntax:
209
+
210
+
```
211
+
[!code-csharp[<title>](<pathToFile>#<RegionName)]
212
+
```
213
+
214
+
The example above shows C# syntax, but other languages are supported.
215
+
Use `code-fsharp` for F# samples; use `code-vbnet` for Visual Basic samples.
216
+
Other languages that are supported are:
217
+
* C++: `code-cpp`
218
+
* HTML: `code-html`
219
+
* JavaScript: `code-javascript`
220
+
* Powershell: `code-ps`
221
+
* SQL: `code-sql`
222
+
* XML: `code-xml`
223
+
224
+
225
+
226
+
The text you place for `<title>` shows up as a rollover on the text. The `<pathToFile>`
227
+
is the path to the source file. The `<RegionName>` should be a region in your source
228
+
code that should be included. Use the `#region` and `#endregion` preprocessor syntax
229
+
to specify the region of code to include.
230
+
231
+
For cases where regions don't work, you can specify the start and end of a snippet
232
+
using an XML element name in a single line comment. For example, you could write this in C#:
233
+
234
+
```csharp
235
+
// <CodeToInclude>
236
+
intj=5;
237
+
inti ; 10;
238
+
intsum=i+j;
239
+
// </CodeToInclude>
240
+
```
241
+
242
+
In other languages, use the comment syntax for that language.
243
+
Finally, you can use line
244
+
numbers: `#L1-L10` would include lines 1 through 10. We discourage line numbers
245
+
because they are very brittle.
246
+
247
+
Including snippets from full programs ensures that all code runs through our Continuous Integration (CI)
248
+
system. However, if you need to show something that causes compile time or
249
+
runtime errors, you can use inline code blocks.
250
+
251
+
### Inline code blocks with language identifier
206
252
207
253
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).
0 commit comments