Skip to content
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

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

Open
dutchiexl opened this issue Aug 25, 2014 · 6 comments
Open

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

dutchiexl opened this issue Aug 25, 2014 · 6 comments

Comments

@dutchiexl
Copy link

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

@ricomonster
Copy link

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
Copy link

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
Copy link

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
Copy link

i get error like this

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

@16patsle
Copy link

@creativefull Try the suggestion by @thornycrackers

@creativefull
Copy link

@16patsle ok thanks bro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants