timsayshey / Ghost-Markdown-Editor

Just a responsive jquery markdown editor with instant preview.
MIT License
472 stars 59 forks source link

How can I get the markdown and html from the editor ? #8

Open dutchiexl opened 10 years ago

dutchiexl commented 10 years ago

var editor = $(".editor").ghostDown(); console.log(editor.getMarkdown());

ricomonster commented 9 years ago

ghost down utilizes codemirror to have an editor like interface, to get the value/markdown you can do this:

Codemirror = CodeMirror.fromTextArea(document.getElementById("the_editor"), { options });

console.log(Codemirror.getValue());
thornycrackers commented 9 years ago

Was this ever solved? I'm currently only able to get the original value of the editor from:

console.log(Codemirror.getValue());

It doesn't include the changes made through the editor.

thornycrackers commented 9 years ago

So I figured out the issue that I was having and I thought I would make a quick post on how to go about this. @ricomonster had the right idea but the problem isn't that you need to instantiate a new CodeMirror object it's that you don't have access to the one that currently exists. If you put his code into the page the console log statement will just print the original value because the page edits the original CodeMirror object and your new CodeMirror object is left alone. Instead look inside the jquery.ghostdown.js file for the following

this.editor = CodeMirror.fromTextArea(this.element.find('textarea')[
    mode: 'markdown',
    tabMode: 'indent',
    lineWrapping: true
 });

This is the object that you want to have access to so you can just make this object global by putting this right after the statement:

window.theEditor = this.editor

After you add that line in you can open your js console and type:

window.theEditor.getValue()

And you will be able to get the markdown that you are looking for

creativefull commented 8 years ago

i get error like this

Uncaught TypeError: $(...).ghostDown is not a function(…)

16patsle commented 7 years ago

@creativefull Try the suggestion by @thornycrackers

creativefull commented 5 years ago

@16patsle ok thanks bro