Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+3 votes
1.5k views
in Plugins by

I tried using the mark-down editor of Scott. Post data seems to be displayed by this plugin correctly.

However, I have a big question.

Markdown code is stored in the "content" of qa_posts table directly. Is this process correct? Because, Q2A and other plugins treat content as HTML or plain text.

Right processing is as follows?
  1. Store: Convert from markdown to HTML
  2. Output: Just display HTML
  3. Edit: Convert from HTML to markdown

What do you think about this?

Q2A version: 1.6.3
by
I agree with this .. +1

2 Answers

0 votes
by
"format" field in ^posts determines which format it's using.

now two things can make problem for developers:

1. the Editor modul does not check(and convert) format if necessary. it should be happening in get_field() function in editor's modul class.

2. the plugin does not get editor modul and use it's get_field() function to get standard post content.

 

so, dispite what editor you are using, if it's converting the conten(rule 1) and you get editor calss using qa_load_module() function and call it's get_field() function to get post data(rule 2) you should be fine.
+1 vote
by

Yes it is correct. There is no such thing as "conversion from HTML to Markdown", it's a one-way system.

Technically it is possible but since MD allows HTML inside it too it's incredibly messy. I've used a MD plugin for Wordpress that stores as HTML and converts back to MD for editing and it's a complete nightmare.

Q2A and other plugins treat content as HTML or plain text.

Yes, and Markdown is pretty much treated as plain text. You can change the format to 'text' in your database and it will work fine.

by
It seems there are some library to convert from HTML to markdown.

Library    language    license    extend expression
------------------------------------------------------------------------
"reMarked.js"    JavaScript    MIT    YES
"to-markdown"    JavaScript    MIT    NO
"HTML2Markdown"    JavaScript    ?    NO
"Simple HTML to Markdown Extra converter with regex"    JavaScrpt    GPLv3    YES
"Markdownify"    PHP    LGPL    YES
"HTML To Markdown for PHP"    PHP    MIT    NO
"html2text"    Python    GPLv3    NO
"url2markdown (html2text)"    Python    GPLv3    NO
"reverse_markdown"    Ruby    WTFPL    YES
"html2markdown"    Ruby    MIT    NO
"Html2Markdown"    C#    ?    NO
"Pandoc"    -    -    YES
"Markable"    -    -    NO

However, it is questionable that these libraries would work perfectly.
There may be a way to save to another field markdown code.

qa_post::format (1)
qa_post::content (2)
qa_post::content_md (3) <<< New field

Store:
MD editor stores "markdown" to (1)
MD editor stores converted HTML code to (2)
MD editor stores MD code to (3)

Display: (Q2A core and other plugin):
These program display (2)

Edit:
MD editor edit (3)

We can not be solved in such a simple way? hahaha
by
Why do you say Markdown should be stored in a separate field and not in 'content'? I don't really understand what your issue is.

A few reasons HTML-to-Markdown is messy:
1. The MD you get back can be different to what you put in. If you write a list with dashes, when it's converted back it may use asterisks instead. Same goes for headings, bold, italics, links and more.
2. There was no official spec for Markdown, so different converters may do different things. (This may be fixed in time with commonmark.org but it's a long way off being implemented everywhere.)
3. There is no specification for the formatting for the HTML itself. MD conversion usually uses regular expressions but for the reverse I'm not sure this is possible (at least it's incredibly difficult) so they need to use full HTML parsers which may be slower.

I see no reason to change how it works right now. Like I said above, you should treat the MD stored in the same way you treat plain text. Plain text is not stored in HTML, neither should Markdown.
by
Mark down editor is made according to the specifications of Q2A. This is particularly qa-markdown-viewer.php.
http://www.question2answer.org/modules.php?module=viewer

However, this specification is a little unreasonable. Many plugins will refer to the database directly, and output content as HTML or plain text.
by
Markdown is typically for people who don't want to see HTML, in the clientside fields or in the database, period. So the idea of editing in Markdown but storing in HTML is fictitious for Markdown users.

If the user is consistently serious, he'll only use other plugins that can handle Markdown plaintext from database.
...