Convert HTML back to Markdown for editing in wmd
Asked Answered
N

5

18

I am curious to do what happens when you edit a post on this site.

I am using wmd for my markdown editor, of course when I goto edit, I get the HTML it generated not the markdown like on stackoverflow. Now, is there a way I can store both? or is it reliable enough to simply convert the HTML back to markdown to show in the wmd editor?

Thanks!

Novak answered 24/10, 2008 at 20:54 Comment(0)
A
13

Look at the optionsExample.html in your WMD distribution. There's an option to send the result to the server as Markdown.

Albertson answered 24/10, 2008 at 20:57 Comment(5)
Actually, I have seen how to get one or the other, but then I need to convert it to HTML everytime I display it. IS that they best way to go? Either way I think I am in the same boat. Seems more efficent to convert it back only when editing.Novak
You can convert to HTML on the server end, and store both HTML and Markdown in your database. That's how Stack Overflow does it, I believe.Albertson
To avoid lots of repeat sanitisations, I believe that SO also sanitises the HTML'd version before storing that in the DB. (I believe there is a SO blog entry that mentions this, but don't quote me on it.)Albertson
This is the javascritp you need to add before you load wmd.js: wmd_options = { output: "Markdown" };Rinaldo
@SamSelikoff Correct, but it actually has a server-side Markdown implementation to create the HTML with. It does not accept client-generated HTML willy-nilly. (Oh wait, I already said all this in my comments from 4.5 years ago. ;-))Albertson
F
14

If you want to convert HTML to Markdown in batch, I can recommend Aaron Swartz’s html2text.py Python script with which you can just:

cat my.html | python html2text.py # outputs markdown

Edit 05/11/12: Nowadays I use Pandoc which is like a swiss-knife for text documents. Can convert html<>textile<>markdown<>epub<>pdf<>latex, etc.

Feline answered 3/10, 2010 at 14:32 Comment(2)
Aaron's page also has a form to convert any URL to markdown. Very handy!Revelation
Second using Pandoc. Just used it now, and it's terrific!Amphiarthrosis
A
13

Look at the optionsExample.html in your WMD distribution. There's an option to send the result to the server as Markdown.

Albertson answered 24/10, 2008 at 20:57 Comment(5)
Actually, I have seen how to get one or the other, but then I need to convert it to HTML everytime I display it. IS that they best way to go? Either way I think I am in the same boat. Seems more efficent to convert it back only when editing.Novak
You can convert to HTML on the server end, and store both HTML and Markdown in your database. That's how Stack Overflow does it, I believe.Albertson
To avoid lots of repeat sanitisations, I believe that SO also sanitises the HTML'd version before storing that in the DB. (I believe there is a SO blog entry that mentions this, but don't quote me on it.)Albertson
This is the javascritp you need to add before you load wmd.js: wmd_options = { output: "Markdown" };Rinaldo
@SamSelikoff Correct, but it actually has a server-side Markdown implementation to create the HTML with. It does not accept client-generated HTML willy-nilly. (Oh wait, I already said all this in my comments from 4.5 years ago. ;-))Albertson
M
2

As Chris notes, you can send Markdown to the server so you can store it there as such. I started trying to use MarkdownJ to convert on the server-side, but it doesn't (at the time of this writing) convert images to HTML correctly and so I ended up going with Java 6 Scripting: Rhino engine + showdown.js. Since WMD uses showdown.js you get the same Markdown-to-HTML transformation. Works like a charm (for Java 6, anyway).

Melaniemelanin answered 31/12, 2008 at 6:32 Comment(0)
T
0

I have just know Markdownify (formerly html2text.php) that "writes texts in Markdown and save them in HTML. You won’t need a copy of the original Markdown input, since Markdownify can convert the saved HTML back to Markdown. And because page impressions are far more often than write actions, this gives you a simple way to increase your page’s performance. Another benefit for a CMS or similar software is that now only one format of text is saved — HTML. The user can now choose wether to write texts in plain HTML or use a full fledged Wysiwyg editor. And of course he can write in Markdown!"

Telpherage answered 4/1, 2011 at 0:52 Comment(1)
Your online demo appears to be broken.Poor
S
0

Open source html to markdown converters written in JavaScript:

Stebbins answered 9/12, 2015 at 23:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.