running showdown.js serverside to conver Markdown to HTML (in PHP)

与世无争的帅哥 提交于 2019-12-19 11:12:21

问题


I am trying to implement WMD onto my website and was wondering how would I go about running showdown.js server side to convert markdown to HTML? (in order to store both in the DB)

I am using PHP...any tips would be helpful (never ran any sort of js from php before)

Thanks, Andrew


回答1:


You could use PHP Markdown, which is a port of the Markdown program written by John Gruber.

Here is a example of how to use PHP Markdown with your code.

include_once "markdown.php";
$my_html = Markdown($my_text);



回答2:


If you're going to run a markdown converter, why run the javascript port? Isn't that a bit backwards?

Markdown was originally designed to run server-side, showdown is a port that allows the conversion to happen in javascript.

Here is where you start.




回答3:


WMD handles the client side implementation of your markup. It allows the user to see a rich text version of their input before they submit.

Once the user is happy, they send their input to the server using the form.

At this point you will use your PHP script to take the input and sanitise it. You will need to remove all the possible XSS exploits and any HTML tags which you do not want to store in your database.



来源:https://stackoverflow.com/questions/724218/running-showdown-js-serverside-to-conver-markdown-to-html-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!