IonicaBizau / medium-editor-markdown

:pencil: A Medium Editor extension to add markdown support.
http://ionicabizau.github.io/medium-editor-markdown/
MIT License
777 stars 66 forks source link

Conversion not done when pane MediumEditor created with default content. #28

Open envygeeks opened 8 years ago

envygeeks commented 8 years ago

Given you initialize MediumEditor with default content, MEMarkdown doesn't convert to Markdown from the HTML that MediumEdtior receives via it's element, resulting in MEMarkdown simply passing HTML. This was discovered during component updates via React.

IonicaBizau commented 8 years ago

Hmm, interesting. Sounds like an issue. Contributions are welcome! ✨

nickspiel commented 8 years ago

@envygeeks did you get this to work? I am looking for the same behaviour.

envygeeks commented 8 years ago

@nickspiel we ended up just building our own convert class that runs 100% of the time before content is spawned and storing the current language as a state, showdown and html2markdown (I can't remember the actual lib name, that might be it) did the trick real well.

nickspiel commented 8 years ago

Yeah, I considered doing the same in my app (Vuejs). I might dig into the medium-editor plugin tonight and see if I can make a PR. Makes sense to have this plugin handle the conversion on both ends.

chenillen commented 7 years ago

I found the same problem as initializing with markdown content. Prepopulate should be consider as a feature in the future release?

IonicaBizau commented 7 years ago

The plugin is supposed to be called on init, according to this line.

And in fact, it does do that on the demo page (where the ME has content in it already).

Can any of you provide a demo where this is failing? Thanks!

chenillen commented 7 years ago

Supposed we will use textarea as the provider of initial content which we stored via markdown source in it.

<textarea id="content">## Markdown Medium Editor\n\n**Hello**</textarea>
<div id="editor"></div>
<script>
markDownEl = $('#content');
mdEditor = new MediumEditor($('#editor'), {
  extensions: {
                markdown: new MeMarkdown(function (md) {
                    markDownEl.textContent = md;
                })
            }
});
</script>

When the "#editor" initialized, the default content will be disappeared.

IonicaBizau commented 7 years ago

@chenillen In this case it simply works as expected, because there is no relation between textarea :arrow_right: ME.

What you're experiencing is #42, which is not solved yet.

chenillen commented 7 years ago

I finally added the markdown2html initializer after initializes the editor, convert the default markdown content to HTML( which I put another library instead. :-<

Thanks btw.

IonicaBizau commented 7 years ago

@chenillen I think we can add in ME Markdown an optional function to be called to convert the Markdown into HTML. For example:


new MeMarkdown({
    markdownToHtml: markdown2html
    // or
    markdownToHtml: md => yourOwnMarkdownConverter(md)
}, function (md) {
    markDownEl.textContent = md;
})
chenillen commented 7 years ago

@IonicaBizau that could be awesome, we can save lots of logics 👍