jerone / UserScripts

🐵 My UserScripts
https://github.com/jerone/UserScripts#readme
GNU General Public License v3.0
342 stars 39 forks source link

Live preview of comment in Github Comment Enhancer #64

Closed ghost closed 9 years ago

ghost commented 9 years ago

For example, when I type something in italic using the comment enhancer, I'd like it to show up as italic text , and not as markdown.

jerone commented 9 years ago

Interesting idea. I'm open for PR's...

ghost commented 9 years ago

Is it possible to simply grab the formatted text from the preview tab to accomplish this?

jerone commented 9 years ago

What you want is a complete GitHub Flavored MarkDown WYSIWYG editor. To get this functionality I would recommend a proven library to handle all cases. All this requires a complete rewrite of the UserScript.

ghost commented 9 years ago

You didn't understand me. I meant that the script would simply automatically fetch the formatted contents of the preview tab, and automatically placing them in the write tab, doing so for each modification of the contents of the comment.

jerone commented 9 years ago

I think I understand you perfectly, but just to be sure we are talking about the same thing, you want something like https://stackedit.io/editor or http://hallojs.org ?

ghost commented 9 years ago

Nope. I meant like, say, if you type *this is italic text* , it automatically gets converted to this is italic text, and the markdown is hidden. You could probably add a Markdown tab, which displays the markdown if people still want to modify it.

jerone commented 9 years ago

Both examples above do exactly as you describe...

ghost commented 9 years ago

Well, nope. I actually described it in the way that the markdown is hidden as soon as you type it, and it is replaced with the formatted it. https://stackedit.io/editor does it by simply making the markdown light grey, but not hiding it.

Both options are good, but then you'd have to maintain both the options at the same time and make sure they work, so I suggest using the first one only, unless you can add both, which would be amazing!

jerone commented 9 years ago

And that is called a WYSIWYG editor.

Like I said this requires a complete rewrite to integrate this with the toolbar and GitHub website. I'm not that interested to put that much effort and time in a feature I won't use. On the other hand, as mentioned earlier, I'm open for a PR.

ghost commented 9 years ago

This does not require a complete rewrite or anything like that. Like I said, all you need to do is simply fetch the contents of the preview tab, and replace the markdown with them. The contents are stored in a div tag, specifically : <div class="comment-body markdown-body js-preview-body" and the actual content then lies in the <p> tags inside the div

jerone commented 9 years ago

And after the commentbox is replaced with the preview code, how do you make another edit? Remember that the textarea is replaced with HTML from the preview tab.

ghost commented 9 years ago

What do you mean by how do you make another edit? You can easily edit the comment again and then the script would re-fetch the contents of the preview tab. The script would become a little bit slow, but then it's a ton better than having the script to manually convert the markdown to formatted text.