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

Doc comment highlighting #1541

Merged
merged 29 commits into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ca4ced3
JavaDoc and JSDoc support
RunDevelopment Jul 13, 2018
7a978ec
Improved JSDoc
RunDevelopment Jul 14, 2018
525c52a
Added JavaDoc-like
RunDevelopment Jul 20, 2018
1ec183d
Use rest instead of inside to add doc
RunDevelopment Jul 21, 2018
82e5b9e
Added PHPDoc
RunDevelopment Jul 29, 2018
606ecf1
Resolved Merge conflict
RunDevelopment Aug 23, 2018
d37b835
Added peer dependencies between languages
RunDevelopment Aug 23, 2018
2274020
Fixed circular dependency between n4js and jsdoc
RunDevelopment Aug 23, 2018
aa9c9b1
Minor improvements
RunDevelopment Aug 23, 2018
3015589
Updated tests
RunDevelopment Aug 23, 2018
5066542
Fixed catastrophic backtracking for PHPDoc
RunDevelopment Aug 23, 2018
3100fcd
Reverted unnecessary white-space change
Aug 24, 2018
7e55a77
Resolved merge conflict
RunDevelopment Sep 22, 2018
ff15d15
Resolved merge conflict
RunDevelopment Dec 1, 2018
83c349d
Inlined variables
RunDevelopment Dec 1, 2018
1f17b43
JavaDoc uses Markup's `tag`
RunDevelopment Dec 1, 2018
19a5bb8
Resolved merge conflict
RunDevelopment Dec 2, 2018
db8f312
Fixed test
RunDevelopment Dec 2, 2018
883337f
JSDoc improvements
RunDevelopment Dec 2, 2018
686abbf
PHPDoc improvements
RunDevelopment Dec 2, 2018
602568b
addSupport improvements
RunDevelopment Dec 2, 2018
a3a92d5
Resolved merge conflict
RunDevelopment Dec 3, 2018
4e7ac10
JavaDocLike improvement
RunDevelopment Dec 3, 2018
e7e604d
Improved JSDoc
RunDevelopment Dec 3, 2018
7d7477b
Fixed empty comment bug
RunDevelopment Dec 3, 2018
f67d8ca
Improved doc
RunDevelopment Dec 3, 2018
55c5d0d
Resolved merge conflicts
RunDevelopment Dec 18, 2018
f9bcfb0
Resolved merge conflict
RunDevelopment Dec 27, 2018
1f072fe
Resolved conflicts
RunDevelopment Feb 28, 2019
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
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,37 @@
"require": "clike",
"owner": "sherblot"
},
"javadoc": {
"title": "JavaDoc",
"require": ["java", "javadoclike"],
"peerDependencies": [
"scala"
],
"owner": "RunDevelopment"
},
"javadoclike": {
"title": "JavaDoc-like",
"peerDependencies": [
"java",
"javascript",
"php"
],
"owner": "RunDevelopment"
},
"jolie": {
"title": "Jolie",
"require": "clike",
"owner": "thesave"
},
"jsdoc": {
"title": "JSDoc",
"require": ["javascript", "javadoclike"],
"peerDependencies": [
"actionscript",
"coffeescript"
],
"owner": "RunDevelopment"
},
"json": {
"title": "JSON",
"alias": "jsonp",
Expand Down Expand Up @@ -464,6 +490,9 @@
"n4js": {
"title": "N4JS",
"require": "javascript",
"peerDependencies": [
"jsdoc"
],
"alias": "n4jsd",
"owner": "bsmith-n4"
},
Expand Down Expand Up @@ -537,6 +566,11 @@
"require": ["clike", "markup-templating"],
"owner": "milesj"
},
"phpdoc": {
"title": "PHPDoc",
"require": ["php", "javadoclike"],
"owner": "RunDevelopment"
},
"php-extras": {
"title": "PHP Extras",
"require": "php",
Expand Down Expand Up @@ -623,6 +657,9 @@
"jsx": {
"title": "React JSX",
"require": ["markup", "javascript"],
"peerDependencies": [
"jsdoc"
],
"owner": "vkbansal"
},
"tsx": {
Expand Down
56 changes: 56 additions & 0 deletions components/prism-javadoc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
(function (Prism) {

var javaDocLike = Prism.languages.javadoclike;
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
var java = Prism.languages.java;

var codeLines = {
'code': {
pattern: /(^(\s*(?:\*\s*)*)).*[^*\s].+$/m,
lookbehind: true,
inside: java,
alias: 'language-java'
}
};

Prism.languages.javadoc = Prism.languages.extend('javadoclike', {});
Prism.languages.insertBefore('javadoc', 'keyword', {
'class-name': [
{
pattern: /(@(?:exception|throws|see|link|linkplain|value)\s+(?:[a-z\d]+\.)*)[A-Z](?:\w*[a-z]\w*)?(?:\.[A-Z](?:\w*[a-z]\w*)?)*/,
lookbehind: true,
inside: {
'punctuation': /\./
}
},
{
pattern: /(@param\s+)<[A-Z]\w*>/,
lookbehind: true,
inside: {
'punctuation': /[.<>]/
}
}
],
'namespace': {
pattern: /(@(?:exception|throws|see|link|linkplain)\s+)(?:[a-z\d]+\.)+/,
lookbehind: true,
inside: {
'punctuation': /\./
}
},
'code-section': [
{
pattern: /(\{@code\s+)(?:[^{}]|\{[^{}]*\})+?(?=\s*\})/,
lookbehind: true,
inside: codeLines
},
{
pattern: /(<(code|tt)>\s*)[\s\S]+?(?=\s*<\/\2>)/,
lookbehind: true,
inside: codeLines
}
],
'tag': /<\/?(?!\d)[^\s>\/=$<%]+(?:\s+[^\s>\/=]+(?:=(?:("|')(?:\\[\s\S]|(?!\1)[^\\])*\1|[^\s'">=]+))?)*\s*\/?>/i,
});

javaDocLike.addSupport(['java'], Prism.languages.javadoc);
}(Prism));
1 change: 1 addition & 0 deletions components/prism-javadoc.min.js

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

78 changes: 78 additions & 0 deletions components/prism-javadoclike.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
(function (Prism) {

var javaDocLike = Prism.languages.javadoclike = {
'parameter': {
pattern: /(^\s*(?:\/{3}|\*|\/\*\*)\s*@(?:param|arg|arguments)\s+)\w+/m,
lookbehind: true
},
'keyword': {
// keywords are the first word in a line preceded be an `@` or surrounded by curly braces.
// @word, {@word}
pattern: /(^\s*(?:\/{3}|\*|\/\*\*)\s*|\{)@[a-z][a-zA-Z-]+\b/m,
lookbehind: true
},
'punctuation': /[{}]/
};


/**
* Adds doc comment support to the given language and calls a given callback on each doc comment pattern.
*
* @param {string} lang the language add doc comment support to.
* @param {(pattern: {inside: {rest: undefined}}) => void} callback the function called with each doc comment pattern as argument.
*/
function docCommentSupport(lang, callback) {
var tokenName = 'doc-comment';

var grammar = Prism.languages[lang];
if (!grammar) return;

var token = grammar[tokenName];

if (!token) {
// add doc comment: /** */
var definition = {};
definition[tokenName] = {
pattern: /(^|[^\\])\/\*\*[\s\S]*?(?:\*\/|$)/,
alias: 'comment',
inside: {}
};

grammar = Prism.languages.insertBefore(lang, 'comment', definition);
token = grammar[tokenName];

} else if (token instanceof RegExp) { // convert existing regex to object
token = grammar[tokenName] = { pattern: token };
}

if (Prism.util.type(token) === 'Array') {
for (var i = 0, l = token.length; i < l; i++) {
if (token[i] instanceof RegExp)
token[i] = { pattern: token[i] };
callback(token[i]);
}
} else {
callback(token);
}
}

Object.defineProperty(javaDocLike, 'addSupport', {
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved

/**
* Adds doc-comment support to the given languages for the given documentation language.
*/
value: function addSupport(languages, docLanguage) {
languages.forEach(function (lang) {
docCommentSupport(lang, function (pattern) {
if (!pattern.inside)
pattern.inside = {};
pattern.inside.rest = docLanguage;
});
});
}

});

javaDocLike.addSupport(['java', 'javascript', 'php'], javaDocLike);

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

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

57 changes: 57 additions & 0 deletions components/prism-jsdoc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
(function (Prism) {

var javaDocLike = Prism.languages.javadoclike;
var javascript = Prism.languages.javascript;

var type = /\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})+\}/.source;

Prism.languages.jsdoc = Prism.languages.extend('javadoclike', {
'parameter': {
pattern: /(@(?:param|arg|argument)\s+(?:\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})+\}\s+)?)(?:\w+|\[\w+(?:=[^[[\]]+)?\])(?=\s|$)/,
lookbehind: true,
inside: {
'code': {
pattern: /(\w=)[^[[\]]+(?=\]$)/,
lookbehind: true,
inside: javascript,
alias: 'language-javascript'
},
'punctuation': /[=[\]]/
}
}
});

Prism.languages.insertBefore('jsdoc', 'keyword', {
'class-name': [
{
pattern: /(@[a-z]+\s+)\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})+\}/,
lookbehind: true,
inside: {
'punctuation': /[.,:?=<>|{}()[\]]/
}
},
{
pattern: /(@(?:augments|extends|class|interface|memberof!?|this)\s+)[A-Z]\w*(?:\.[A-Z]\w*)*/,
lookbehind: true,
inside: {
'punctuation': /\./
}
}
],
'example': {
pattern: /(@example\s+)[^@]+?(?=\s*(?:\*\s*)?(?:@\w|\*\/))/,
lookbehind: true,
inside: {
'code': {
pattern: /^(\s*(?:\*\s*)?).+$/m,
lookbehind: true,
inside: javascript,
alias: 'language-javascript'
}
}
}
});

javaDocLike.addSupport(['javascript'], Prism.languages.jsdoc);

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

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

28 changes: 28 additions & 0 deletions components/prism-phpdoc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
(function (Prism) {

var typeExpression = /(?:[a-zA-Z]\w*|[|\\[\]])+/.source;

Prism.languages.phpdoc = Prism.languages.extend('javadoclike', {
RunDevelopment marked this conversation as resolved.
Show resolved Hide resolved
'parameter': {
pattern: RegExp('(' + /@(?:global|param|property(?:-read|-write)?|var)\s+/.source + '(?:' + typeExpression + '\\s+)?)' + /\$\w+/.source),
lookbehind: true
}
});

Prism.languages.insertBefore('phpdoc', 'keyword', {
'class-name': [
{
pattern: RegExp(/(@(?:global|package|param|property(?:-read|-write)?|return|subpackage|throws|var)\s+)/.source + typeExpression),
lookbehind: true,
inside: {
'keyword': /\b(?:callback|resource|boolean|integer|double|object|string|array|false|float|mixed|bool|null|self|true|void|int)\b/,
'punctuation': /[|\\[\]()]/
}
}
],
});

var javaDocLike = Prism.languages.javadoclike;
javaDocLike.addSupport(['php'], Prism.languages.phpdoc);

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

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

2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
}

// The dependencies map is built automatically with gulp
var lang_dependencies = /*languages_placeholder[*/{"javascript":"clike","actionscript":"javascript","arduino":"cpp","aspnet":["markup","csharp"],"bison":"c","c":"clike","csharp":"clike","cpp":"c","coffeescript":"javascript","crystal":"ruby","css-extras":"css","d":"clike","dart":"clike","django":"markup","erb":["ruby","markup-templating"],"fsharp":"clike","flow":"javascript","glsl":"clike","gml":"clike","go":"clike","groovy":"clike","haml":"ruby","handlebars":"markup-templating","haxe":"clike","java":"clike","jolie":"clike","kotlin":"clike","less":"css","markdown":"markup","markup-templating":"markup","n4js":"javascript","nginx":"clike","objectivec":"c","opencl":"cpp","parser":"markup","php":["clike","markup-templating"],"php-extras":"php","plsql":"sql","processing":"clike","protobuf":"clike","pug":"javascript","qore":"clike","jsx":["markup","javascript"],"tsx":["jsx","typescript"],"reason":"clike","ruby":"clike","sass":"css","scss":"css","scala":"java","smarty":"markup-templating","soy":"markup-templating","swift":"clike","tap":"yaml","textile":"markup","tt2":["clike","markup-templating"],"twig":"markup","typescript":"javascript","vbnet":"basic","velocity":"markup","wiki":"markup","xeora":"markup","xquery":"markup"}/*]*/;
var lang_dependencies = /*languages_placeholder[*/{"javascript":"clike","actionscript":"javascript","arduino":"cpp","aspnet":["markup","csharp"],"bison":"c","c":"clike","csharp":"clike","cpp":"c","coffeescript":"javascript","crystal":"ruby","css-extras":"css","d":"clike","dart":"clike","django":"markup","erb":["ruby","markup-templating"],"fsharp":"clike","flow":"javascript","glsl":"clike","gml":"clike","go":"clike","groovy":"clike","haml":"ruby","handlebars":"markup-templating","haxe":"clike","java":"clike","javadoc":["java","javadoclike"],"jolie":"clike","jsdoc":["javascript","javadoclike"],"kotlin":"clike","less":"css","markdown":"markup","markup-templating":"markup","n4js":"javascript","nginx":"clike","objectivec":"c","opencl":"cpp","parser":"markup","php":["clike","markup-templating"],"phpdoc":["php","javadoclike"],"php-extras":"php","plsql":"sql","processing":"clike","protobuf":"clike","pug":"javascript","qore":"clike","jsx":["markup","javascript"],"tsx":["jsx","typescript"],"reason":"clike","ruby":"clike","sass":"css","scss":"css","scala":"java","smarty":"markup-templating","soy":"markup-templating","swift":"clike","tap":"yaml","textile":"markup","tt2":["clike","markup-templating"],"twig":"markup","typescript":"javascript","vbnet":"basic","velocity":"markup","wiki":"markup","xeora":"markup","xquery":"markup"}/*]*/;

var lang_data = {};

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.

Loading