Skip to content

Commit

Permalink
Added support for XML doc in C#, F#, and VB.net (#2340)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment authored May 13, 2020
1 parent 1946918 commit caec5e3
Show file tree
Hide file tree
Showing 12 changed files with 261 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,12 @@
},
"owner": "freakmaxi"
},
"xml-doc": {
"title": "XML doc (.net)",
"require": "markup",
"modify": ["csharp", "fsharp", "vbnet"],
"owner": "RunDevelopment"
},
"xojo": {
"title": "Xojo (REALbasic)",
"owner": "Golmote"
Expand Down
40 changes: 40 additions & 0 deletions components/prism-xml-doc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
(function (Prism) {

/**
* If the given language is present, it will insert the given doc comment grammar token into it.
*
* @param {string} lang
* @param {any} docComment
*/
function insertDocComment(lang, docComment) {
if (Prism.languages[lang]) {
Prism.languages.insertBefore(lang, 'comment', {
'doc-comment': docComment
});
}
}

var tag = Prism.languages.markup.tag;

var slashDocComment = {
pattern: /\/\/\/.*/,
greedy: true,
alias: 'comment',
inside: {
'tag': tag
}
};
var tickDocComment = {
pattern: /'''.*/,
greedy: true,
alias: 'comment',
inside: {
'tag': tag
}
};

insertDocComment('csharp', slashDocComment);
insertDocComment('fsharp', slashDocComment);
insertDocComment('vbnet', tickDocComment);

}(Prism));
1 change: 1 addition & 0 deletions components/prism-xml-doc.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions examples/prism-xml-doc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<h2>C#</h2>
<pre><code class="language-csharp">/// &lt;summary>
/// Summary documentation goes here.
/// &lt;/summary></code></pre>

<h2>F#</h2>
<pre><code class="language-fsharp">/// &lt;summary>
/// Summary documentation goes here.
/// &lt;/summary></code></pre>

<h2>VB.net</h2>
<pre><code class="language-vbnet">''' &lt;summary>
''' Summary documentation goes here.
''' &lt;/summary></code></pre>
1 change: 1 addition & 0 deletions plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
"velocity": "markup",
"wiki": "markup",
"xeora": "markup",
"xml-doc": "markup",
"xquery": "markup"
}/*]*/;

Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
"wasm": "WebAssembly",
"wiki": "Wiki markup",
"xeoracube": "XeoraCube",
"xml-doc": "XML doc (.net)",
"xojo": "Xojo (REALbasic)",
"xquery": "XQuery",
"yaml": "YAML",
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 65 additions & 0 deletions tests/languages/csharp!+xml-doc/inclusion.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/// <summary>
/// Class level summary documentation goes here.
/// </summary>
/// <remarks>
/// Longer comments can be associated with a type or member through
/// the remarks tag.
/// </remarks>

----------------------------------------------------

[
["doc-comment", [
"/// ",
["tag", [
["tag", [
["punctuation", "<"],
"summary"
]],
["punctuation", ">"]
]]
]],
["doc-comment", [
"/// Class level summary documentation goes here."
]],
["doc-comment", [
"/// ",
["tag", [
["tag", [
["punctuation", "</"],
"summary"
]],
["punctuation", ">"]
]]
]],
["doc-comment", [
"/// ",
["tag", [
["tag", [
["punctuation", "<"],
"remarks"
]],
["punctuation", ">"]
]]
]],
["doc-comment", [
"/// Longer comments can be associated with a type or member through"
]],
["doc-comment", [
"/// the remarks tag."
]],
["doc-comment", [
"/// ",
["tag", [
["tag", [
["punctuation", "</"],
"remarks"
]],
["punctuation", ">"]
]]
]]
]

----------------------------------------------------

Checks for XML documentation comments.
Loading

0 comments on commit caec5e3

Please sign in to comment.