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

Add .remarkrc.js config support #14

Merged
merged 1 commit into from
Dec 22, 2019
Merged
Changes from all 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
27 changes: 22 additions & 5 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,19 @@ function showOutput(msg: string): void {
}

function getWorkspaceConfig() {
return vscode.workspace.findFiles('**/*remarkrc', '**/node_modules/**').then((files) => {
return vscode.workspace.findFiles('**/*remarkrc*', '**/node_modules/**').then((files) => {
if (files.length === 0) {
return null;
}

if (files[0].fsPath.endsWith('.js')) {
try {
return require(files[0].fsPath);
} catch (err) {
return 'SyntaxError';
}
}

return fileRead(files[0].fsPath).then((content) => {
try {
return JSON.parse(content);
Expand All @@ -63,12 +71,19 @@ function getWorkspaceConfig() {
function getPlugins(list: string[]): Promise<IPlugin[]> {
const root = vscode.workspace.rootPath || '';

const pluginList = list.map((name) => 'remark-' + name);
const pluginList = list.map((name) => {
if (typeof name === 'string') {
return 'remark-' + name;
} else {
return 'remark-' + name[0];
}
});

return resolveMany(pluginList, root).then((filepaths) => {
return filepaths.map((filepath, index) => <IPlugin>{
name: list[index],
package: filepath !== undefined ? require(filepath) : undefined
package: filepath !== undefined ? require(filepath) : undefined,
settings: typeof list[index] !== 'string' ? list[index][1] : undefined
});
});
}
Expand Down Expand Up @@ -119,8 +134,10 @@ async function runRemark(document: vscode.TextDocument, range: vscode.Range): Pr
}

try {
if (remarkSettings[plugin.name]) {
api = api.use(plugin.package, remarkSettings[plugin.name]);
const settings = plugin.settings !== undefined
? plugin.settings : remarkSettings[plugin.name];
if (settings !== undefined) {
api = api.use(plugin.package, settings);
} else {
api = api.use(plugin.package);
}
Expand Down