-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
bin/linux_x64/clang-format | ||
|
||
'use strict' | ||
|
||
var visit = require('unist-util-visit') | ||
var fs = require('fs') | ||
spawn = require('child_process').spawn | ||
|
||
function getNativeBinary() { | ||
let nativeBinary; | ||
|
||
if (os.platform() === 'win32') { | ||
nativeBinary = path.join(`${__dirname}`, `../clang-format/bin/win32/clang-format.exe`); | ||
} else { | ||
nativeBinary = path.join(`${__dirname}`, `../clang-format/bin/${os.platform()}_${os.arch()}/clang-format`); | ||
} | ||
|
||
if (!fs.existsSync(nativeBinary)) { | ||
const message = 'This module doesn\'t bundle the clang-format executable for your platform. ' + | ||
`(${os.platform()}_${os.arch()})\n` + | ||
'Consider installing it with your native package manager instead.\n'; | ||
throw new Error(message); | ||
} | ||
return nativeBinary; | ||
} | ||
|
||
|
||
function visitor(node) { | ||
let nativeBinary = getNativeBinary() | ||
if (node.type == 'code' || node.type == 'inlineCode') { | ||
if (node.lang.toLowerCase() == 'c++' || node.lang.toLowerCase() == 'cpp') { | ||
var child = spawnSync(nativeBinary); | ||
|
||
child.stdin.setEncoding('utf-8'); | ||
child.stdout.pipe(process.stdout); | ||
|
||
child.stdin.write(node.value); | ||
|
||
child.stdin.end(); | ||
|
||
node.value = format(child.stdout) | ||
} | ||
} | ||
} | ||
|
||
module.exports = function attacher() { | ||
return function transformer(tree, file) { | ||
visit(tree, visitor) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "remark-clang-format", | ||
"version": "0.0.1", | ||
"description": "run clang-format for code in markdown", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Ir1d/remark-clang-format.git" | ||
}, | ||
"keywords": [ | ||
"clang-format", | ||
"remark" | ||
], | ||
"author": "Ir1d", | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/Ir1d/remark-clang-format/issues" | ||
}, | ||
"homepage": "https://github.com/Ir1d/remark-clang-format#readme", | ||
"dependencies": { | ||
"clang-format": "^1.2.4", | ||
"unist-util-visit": "^1.4.0" | ||
} | ||
} |