-
Notifications
You must be signed in to change notification settings - Fork 452
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
Switch to remark-cli to support .remarkrc and unlock remark version #2008
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,62 @@ | ||
### | ||
Requires https://github.com/remarkjs/remark | ||
### | ||
"use strict" | ||
Beautifier = require('./beautifier') | ||
|
||
module.exports = class Remark extends Beautifier | ||
name: "Remark" | ||
link: "https://github.com/wooorm/remark" | ||
link: "https://github.com/remarkjs/remark" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The project has been moved to an org in ≈ Dec 2017 |
||
options: { | ||
_: { | ||
gfm: true | ||
yaml: true | ||
commonmark: true | ||
footnotes: true | ||
pedantic: true | ||
breaks: true | ||
entities: true | ||
setext: true | ||
closeAtx: true | ||
looseTable: true | ||
spacedTable: true | ||
fence: true | ||
fences: true | ||
bullet: true | ||
listItemIndent: true | ||
incrementListMarker: true | ||
rule: true | ||
ruleRepetition: true | ||
ruleSpaces: true | ||
strong: true | ||
emphasis: true | ||
position: true | ||
search_for_configuration: true | ||
} | ||
Markdown: true | ||
} | ||
|
||
beautify: (text, language, options) -> | ||
return new @Promise((resolve, reject) -> | ||
try | ||
remark = require 'remark' | ||
cleanMarkdown = remark().process(text, options).toString() | ||
resolve cleanMarkdown | ||
catch err | ||
@error("Remark error: #{err}") | ||
reject(err) | ||
executables: [ | ||
{ | ||
name: "Remark CLI" | ||
cmd: "remark" | ||
homepage: "https://github.com/remarkjs/remark" | ||
installation: "https://github.com/remarkjs/remark/tree/master/packages/remark-cli#installation" | ||
version: { | ||
parse: (text) -> | ||
return text.match(/remark: (\d+\.\d+\.\d+)/)[1] | ||
runOptions: { | ||
returnStderr: true | ||
} | ||
} | ||
} | ||
] | ||
|
||
beautify: (text, language, options, context) -> | ||
cwd = context.filePath and path.dirname context.filePath | ||
remarkArgs = [ | ||
'--no-color' | ||
'--no-ignore' | ||
'--file-path' | ||
context.filePath | ||
] | ||
remarkOptions = {} | ||
|
||
if (!options.search_for_configuration) | ||
settings = Object.assign({}, options) | ||
delete settings.search_for_configuration | ||
serializedSettings = JSON.stringify(settings).slice(1, -1) | ||
remarkArgs.push('--no-config', '--setting', serializedSettings) | ||
|
||
return new Promise((resolve, reject) => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A new promise object is not really necessary here at this point, but it is helpful to integrate the new implementation of the beautifier with #1990 |
||
@exe("remark") | ||
.run(remarkArgs, { | ||
cwd | ||
onStdin: (stdin) -> | ||
stdin.end text | ||
}) | ||
.then (output) -> | ||
resolve(output) | ||
.catch(reject) | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kachkaev @szeck87 : I think we can support both Remark-CLI and be backwards compatible with
remark
as a Node.js dependency.Since the
Remark CLI
is now an Executable we should be able to determine if it is installed or not.See
atom-beautify/src/beautifiers/executable.coffee
Lines 99 to 107 in 30dece2
I'm thinking something along the lines of:
I would prefer to add new features while being backwards compatible. Removable of
remark
as a builtin dependency is considered a breaking change to me. However, there is value in usingRemark CLI
directly 👍, such as the configuration file.