bevacqua / woofmark

:dog2: Barking up the DOM tree. A modular, progressive, and beautiful Markdown and HTML editor
https://bevacqua.github.io/woofmark
MIT License
1.63k stars 65 forks source link

Enhancement Request: Set the value of the editor using markdown #15

Closed samhagman closed 8 years ago

samhagman commented 9 years ago

The way I picture this working is a function being added to the editor object like editor.setValue(markdownString).

This would internally check editor.mode and then either just insert the markdownString into the editor (if in markdown mode) or run editor.parseMarkdown(markdownString) and then either render or insert the resulting HTML string into the editor (if in html or wysiwyg mode respectively).

It also wouldn't hurt to make this an option to pass into the woofmark() function with a name like option.initialValue or something.

P.S. Thanks for this great extensible library.

tsileo commented 9 years ago

I use a command that update the chunk with the new value:

var newString = 'new **markdown** value';
editor.runCommand(function(chunks, mode) {
  chunks.after='';
  if (mode == 'html') {
    chunks.before = editor.parseMarkdown(newString);
  } else {
    chunks.before = newString;
  }
});
jywarren commented 8 years ago

Perhaps this should be integrated into the editor.value() method -- that way value('new **markdown** value') could be used as a setter and a getter. I would be happy to open a pull request for this as it seems a very common thing to want to do and an easy addition.

bevacqua commented 8 years ago

Sounds good to me

jywarren commented 8 years ago

I seemed to be able to make a simpler fix which added a setter ability to the value() method; see #27.

samhagman commented 8 years ago

@jywarren Awesome, I'll close this when that gets merged, thank you for your efforts!

bevacqua commented 8 years ago

4.1.0