Glavin001 / atom-beautify

:mega: Help Wanted - Looking for Maintainer: https://github.com/Glavin001/atom-beautify/issues/2572 | :lipstick: Universal beautification package for Atom editor (:warning: Currently migrating to https://github.com/Unibeautify/ and have very limited bandwidth for Atom-Beautify Issues. Thank you for your patience and understanding :heart: )
http://unibeautify.com/
MIT License
1.5k stars 453 forks source link

.remarkrc file is not respected #965

Closed chdsbd closed 6 years ago

chdsbd commented 8 years ago

Description

When beautifying markdown using remark, atom-beautify does not respect .remarkrc file in the home directory.

Expected Results

Atom-beautify should follow the .remarkrc file in home directory by default, just as linter-markdown does.

Steps to Reproduce

  1. Add code to Atom editor
  2. Run command Atom Beautify: Beautify Editor
  3. This beautified code does not look right!
ChrisRast commented 7 years ago

Hi @Glavin001, what can I do to address this issue? I have the same problem... Can you give us indication on where to look if we want to add support for a configuration file for remark? Thank you for your work!

Glavin001 commented 7 years ago

Hi @ChrisRast.

Pull Requests welcome! Applicable file is https://github.com/Glavin001/atom-beautify/blob/master/src/beautifiers/remark.coffee#L39

Please feel free to open the PR earlier than later so I can review and answer questions 😃 .

stale[bot] commented 7 years ago

This issue has been automatically marked as stale because it has not had recent activity. If this is still an issue, please add a comment. It will be closed if no further activity occurs. Thank you for your contributions.

ChrisRast commented 7 years ago

Still an issue, but did not have time & knowledge to address it. :(

kachkaev commented 6 years ago

@Glavin001 I'm interested in implementing this feature and submitting a PR. However, there is an issue I'd like to ask @wooorm, the author of remark. It is to do with how .remarkrc is searched.

It's great that beautify method can receive the fourth parameter called context, which means that we have access to context.filePath and therefore path.dirname(context.filePath). This is where we should start searching for .remarkrc or .remarkrc.js. When glancing through remark and its parent unifiedjs library I noticed the use of cwd, which suggests that this is how current working directory could be defined. However, none of my experiments to search for .remarkrc in it worked. These are the most sane attempts:

modifiedOptions = Object.assign({}, options, {detectConfig: true })
cleanMarkdown = remark({
  cwd: path.dirname(context.filePath)
}).process(text, modifiedOptions).toString()
modifiedOptions = Object.assign({}, options, {detectConfig: true, cwd: path.dirname(context.filePath) })
cleanMarkdown = remark().process(text, modifiedOptions).toString()

@wooorm could you please hint on how to pass cwd into remark so that it could find .remarkrc? Importantly, here we pass the contents of the file separately to a folder where it is located. This is because we often want to beautify something that has not been saved yet or just a user selection.

kachkaev commented 6 years ago

Ping @wooorm. Will appreciate your help here 🙌

wooorm commented 6 years ago

@kachkaev Hi, sorry about that! The stuff you’re looking for isn’t in unified or remark, but instead in unified-engine. Specifically here:

https://github.com/unifiedjs/unified-engine/blob/e720037d4bd193af7c15a7964ca8fb9a3e899e7a/lib/configuration.js

Does that help?

P.S. Maybe it makes sense to create something like remark-cli instead of using remark!

kachkaev commented 6 years ago

Thanks @wooorm, see #2008. Happy to hear your feedback guys!

stale[bot] commented 6 years ago

This issue has been automatically marked as stale because it has not had recent activity. If this is still an issue, please add a comment. It will be closed if no further activity occurs. Thank you for your contributions.