問題描述
這是一個事實調查"問題,旨在了解使用 showdown.js 解析器. 已經有一個使用 showdown.js 的 java 實現(參見本文末尾的代碼),我想看看如何為 ColdFusion 實現它.我沒有 Java 方面的經驗,我不會特別稱自己為程序員",但我不希望這阻止我嘗試.
This is a "fact finding" question to see how difficult it would be to create a ColdFusion UDF to parse markdown on the server using the showdown.js parser. There is already a java implementation that utilizes showdown.js (see code at the end of this post) and I want to see how to go about implementing it for ColdFusion. I have no experience in Java and I would not particularly call myself "a programmer," but I don't want this to stop me from trying.
總結
我想在服務器端運行 Shadown.js 以便將 Markdown 轉換為 HTML.
I would like to run Shadown.js server-side in order to convert markdown to HTML.
為什么?
保存用戶條目的兩個版本,一個是 Markdown 格式,另一個是 HTML,允許我們向最終用戶顯示原始 Markdown 版本,以防他們想要編輯他們的條目.
Saving two versions of a user entry, one in markdown format and another in HTML, allows us to display the raw markdown version to the end user in case they wanted to edit their entry.
為什么不使用服務器端解析器?
有兩個原因:
- 到目前為止,還沒有針對此特定目的的 ColdFusion 降價解析器
- 在客戶端使用 Showdown.js,然后在服務器端使用不同的解析器,將導致顯示給客戶端的預覽與存儲在數據庫中的版本之間的標記不一致.鑒于 Markdown 定義松散,大多數解析器實現都會有細微差別.
有一個非常好的博客條目 討論這個問題.
為什么不在客戶端進行所有解析并發布兩個版本?
這并不是一個安全的解決方案.我還認為用戶可能會使用不匹配的 HTML 發布降價.
This does not strike me as a secure solution. I also think users would potentially be able to post markdown with HTML that does not match.
是否有任何現有的實現?
有 一個名為 CFShowdown 的實現,但它不是為了這個特定目的.相反,它用于處理頁面上的輸出.上述博客的評論區具有一個名為 David 的用戶編寫的純 Java 實現:
There is one implementation called CFShowdown, but it's not for this specific purpose. Rather, it's for handling output on a page. The comments section of the aforementioned blog features a pure Java implementation written by a user called David:
目標
創建一個 java 類,允許我們將此實現與 ColdFusion UDF 或組件內的自定義標簽一起使用,類似于 <cfset html = getMarkdown(string)>
Create a java class that would allow us to use this implementation with a ColdFusion UDF or a custom tag inside a component, something along the lines of <cfset html = getMarkdown(string)>
由于我沒有使用 Java 的經驗,我想從用戶那里獲得一些建議和意見,了解從何處以及如何開始執行此任務.我創建了一個
Since I have no experience with Java, I want to get some advice and input from users on where and how to start going about this task. I created a
推薦答案
有文件 攤牌.js 和同一目錄中的文件 markdown.txt(如下示例).
Have files showdown.js and a file markdown.txt (example below) in the same directory.
showdown.cfm
ma??rkdown.txt
更新
這是一個采用 Adam Presley 在 Java 中的工作 并且全部在 CFC 中完成.請注意,我把他在 showdown.js 末尾添加的那一點魔法放入一個 CFC 函數中,該函數的返回值被附加(即 showdownAdapterJS()
).
Here's a version that takes Adam Presley's work in Java and does it all in a CFC. Note I took that little bit of magic he added at the end of showdown.js and put it into a CFC function whose return value is appended (i.e. showdownAdapterJS()
).
氟氯化碳
用法
這篇關于在服務器端為 ColdFusion 實現 Showdown.js 降價解析器的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!