Skip to content

Commit

Permalink
Add support for C & C++ files
Browse files Browse the repository at this point in the history
  • Loading branch information
xt0rted committed Oct 2, 2020
1 parent f7176c5 commit 5278409
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/core/load-plugins.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { default as BowerManifest } from '@octolinker/plugin-bower-manifest';
export { default as Composer } from '@octolinker/plugin-composer-manifest';
export { default as C } from '@octolinker/plugin-c';
export { default as CSS } from '@octolinker/plugin-css';
export { default as Docker } from '@octolinker/plugin-docker';
export { default as DotNetCore } from '@octolinker/plugin-dot-net-core';
Expand Down
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"@octolinker/helper-sort-urls": "1.0.0",
"@octolinker/plugin-bower-manifest": "1.0.0",
"@octolinker/plugin-composer-manifest": "1.0.0",
"@octolinker/plugin-c": "1.0.0",
"@octolinker/plugin-css": "1.0.0",
"@octolinker/plugin-docker": "1.0.0",
"@octolinker/plugin-dot-net": "1.0.0",
Expand Down
12 changes: 12 additions & 0 deletions packages/helper-grammar-regex-collection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ const captureJsQuotedWord = regex`
['"\`] # end quote
`;

const captureCStyleQuotedWord = regex`
["<] # beginning quote
(?<$1>[^"<>]+) # capture the word inside the quotes
[">] # end quote
`;

const diffSigns = regex`
^[ \t]*[+-]?
`;
Expand Down Expand Up @@ -268,3 +274,9 @@ export const NET_PROJ_FILE_REFERENCE = regex`
(Include|Update)=${captureSpacedQuotedWord}
.*/?>
`;

export const C_INCLUDE = regex`
\#include
\s*
${captureCStyleQuotedWord}
`;
36 changes: 36 additions & 0 deletions packages/plugin-c/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { C_INCLUDE } from '@octolinker/helper-grammar-regex-collection';
import relativeFile from '@octolinker/resolver-relative-file';

export default {
name: 'C',

resolve(path, [target]) {
const [, , , , , ...parts] = path.split('/');
const urls = parts.map((_currentValue, index) =>
relativeFile({ path, target: '../'.repeat(index) + target }),
);
return urls;
},

getPattern() {
return {
pathRegexes: [
/\.c$/,
/\.cc$/,
/\.cpp$/,
/\.cxx$/,
/\.c%2B%2B.*$/, // .c++ needs to be url encoded to match
/\.h$/,
/\.hh$/,
/\.hpp$/,
/\.hxx$/,
/\.h%2B%2B.*$/, // .h++ needs to be url encoded to match
],
githubClasses: [],
};
},

getLinkRegexes() {
return [C_INCLUDE];
},
};
12 changes: 12 additions & 0 deletions packages/plugin-c/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@octolinker/plugin-c",
"version": "1.0.0",
"description": "",
"repository": "https://github.com/octolinker/octolinker/tree/master/packages/plugin-c",
"license": "MIT",
"main": "./index.js",
"dependencies": {
"@octolinker/helper-grammar-regex-collection": "1.0.0",
"@octolinker/resolver-relative-file": "1.0.0"
}
}

0 comments on commit 5278409

Please sign in to comment.