0

I'm still in the middle of coding my final year project at university, and I have come across an issue where I need to either convert from HTML to Markdown or visa versa. Now I have no experience whatsoever of Perl, Python, etc. so I'm in need of an easy-to-implement solution, I only have about 6 weeks left to complete this now. I'm writing the data from a WMD text box to SQL Server, and I can either upload it as Markdown or HTML but if that data needs editing it cannot be in HTML as this would be too confusing for the end user who is perceived to have zero/very little computing "know how".

What should I do?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Stefan
  • 327
  • 1
  • 5
  • 18
  • I guess I should ask some more questions, as I don't really understand exactly what the problem is. Are you able to store the data from your WMD text area in the database? Do you know how to display the data from the database in the browser? What back-end language are you using? Do you have a Markdown library for that language? – Gavin Anderegg Feb 19 '11 at 17:20
  • Maybe I should have been clearer, Yes I can store the text from the WMD text are in my database that bit is sorted. For the retrieval of data I am creatin a recordset that is filled from a SQL stored procedure. I am then using response.write.... to display the data, and this is where I become stuck, I am using Classic ASP as that is all I know, I have not experienced .Net and at this late stage in the project I dont think it would be a wise idea to try and implement a change in the code. – Stefan Feb 19 '11 at 17:56
  • Thanks for you help guys, I have implement ed my own solution however after thinking about things. What ive done (this is VERY messy and probably not how a pro web developer would do things) is this: when the form is validating (using javascript), im writing the innerHTML of the wmd-preview div to a hidden text field. Then I will just upload an html and a MarkDown description to the SQL server, when its the customer viewing information I will pull down the HTML description, when its staff editing I will pull down the MarkDown version...Thank you for your help anyway its much appreciated – Stefan Feb 19 '11 at 19:15

2 Answers2

1

If you look at the web site for Markdown, you'll find a Perl script that converts Markdown-syntax documents to HTML. Keep Markdown text in your database and invoke the script whenever you need to display the text. No Perl knowledge required!

Karmastan
  • 5,618
  • 18
  • 24
  • I may be a bit silly here but how do I go about invoking the script on an HTML page? – Stefan Feb 19 '11 at 15:58
  • @Stefan: How are you generating the HTML? Most languages should have some way to invoke an external command. – Karmastan Feb 19 '11 at 17:02
  • Im using the wmd-editor to generate the text to go to the database, as I mentioned I can use either HTML or MarkDown as the output from wmd-editor. On another page im pulling the data back from the database using asp and running an SQL query, this is where I need the MarkDown to convert to HTML so that item lists show as a list of items instead of a continuous string such as "hello -world -etc" Is this clearer? – Stefan Feb 19 '11 at 17:24
1

Karmastan's answer is probably the best here. Keeping the raw Markdown in the database is a really good solution as it allows users to upkeep the content in a form with which they're familiar.

However, if you have a bunch of HTML which is already converted, you might want to look at something like Markdownify: The HTML to Markdown converter for PHP.

Edit: based on what you've said below, there are a few things you should keep in mind:

  1. Make sure that the following is set in wmd.js:

    wmd_options = {"output": "Markdown"};

    This ensures that you're storing Markdown in the database.

    Source: How do you store the markdown using WMD in ASP.NET?

  2. When outputting the Markdown to the web, you need to transform it to HTML. To do this, you'll need a library which does Markdown -> HTML conversion. Here are two examples:

I'm not a .NET developer, so I can't really help with how these libraries should be used, but hopefully the documentation will make that clear.

Community
  • 1
  • 1
Gavin Anderegg
  • 6,281
  • 2
  • 25
  • 35
  • Ok I had a look at the solution @Karmastan gave but I cant see how I get it to work. I copied the file to a folder within my web application but I don't know what to do then...Can you provide any assistance...i'm completely at a loss – Stefan Feb 19 '11 at 16:31
  • Karmastan's solution didn't require the Markdown code at the linked site. The idea is that you just store the raw Markdown code (the Markdown code written by the user) in your database. You then only display the HTML-ised version of that code when outputting the page (assuming this is a web application). – Gavin Anderegg Feb 19 '11 at 17:10
  • Im using WMD-Editor to save the MarkDown output to the SQL Database, im then using ASP to pull this data back from the SQL Server, this is where I need it to be encoded as HTML. I Hope im making some sense, you are correct however that this is a web application – Stefan Feb 19 '11 at 17:27
  • I've updated my answer. Hopefully this should be more helpful. – Gavin Anderegg Feb 19 '11 at 17:37
  • @Gaving Anderegg, Thank you, I have added a comment to my original question. Unfortunately i neglected to say i'm using classic ASP so the .Net solutions wont work (I dont believe, correct me if i'm wrong) – Stefan Feb 19 '11 at 17:57