Load a *.md file


#1

Hey guys, I have been looking around the web and I have not been able to find a way to open .md files when pressing cmd+o or ctrl + o.

Can someone please provide an example on how to do this?

Thanks!


#2

Is this a question about Atom or Electron?


#3

This is a question about electron.


#4

Electron doesn’t have any way to know what to do with Markdown. It displays HTML and runs JavaScript. You have to interpret the Markdown into HTML and send that to the window, and for that you need a Markdown parser.


#5

I know, but I want to know how to open the actual file so I can pass it to markdown.


#6

Not with the Open dialog. Electron isn’t an editor. You need to have your JavaScript read the file into a variable and then run the conversion function.

I’m a bit concerned about your understanding of how this works. You should probably take a step back and read up on reading/writing files in programming generally and Node specifically. Art of Node is a pretty good resource.


#7

I am aware Electron isn’t a text editor. Thanks for sharing the art of node btw.

What I meant was that I want to know how to use electron to get the text of a .md file. That way I can take the content and parse it with marked and then output it onto the screen.

Thanks,


#8

Electron provides the full set of NodeJS APIs, you can read/write to the file system with Node’s fs module.


#9

In addition to @enlight’s comment, you also might want to check out dialog.showOpenDialog for getting the file path.


#10

Yea, thanks. I found it on a stack overflow post.

Thanks!