久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在服務器端為 ColdFusion 實現 Showdown.js 降價解析器

Implementating Showdown.js markdown parser on the server side for ColdFusion(在服務器端為 ColdFusion 實現 Showdown.js 降價解析器)
本文介紹了在服務器端為 ColdFusion 實現 Showdown.js 降價解析器的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

這是一個事實調查"問題,旨在了解使用 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.

為什么不使用服務器端解析器?

有兩個原因:

  1. 到目前為止,還沒有針對此特定目的的 ColdFusion 降價解析器
  2. 在客戶端使用 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:

ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine jsEngine = manager.getEngineByName("js");
try
{
    jsEngine.eval(new InputStreamReader(getClass().getResourceAsStream("showdown.js")));
    showdownConverter = jsEngine.eval("new Showdown.converter()");
}
catch (Exception e)
{
    log.error("could not create showdown converter", e);
}

try
{
    return ((Invocable) jsEngine).invokeMethod(
        showdownConverter, 
        "makeHtml", 
        markdownString
    ) + "";
}
catch (Exception e)
{
    log.error("error while converting markdown to html", e);
    return "[could not convert input]";
}

目標

創建一個 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

<cfscript>
manager = createObject("java", "javax.script.ScriptEngineManager").init();
jsEngine = manager.getEngineByName("js");

showdownJS = fileRead('#getDirectoryFromPath(getCurrentTemplatePath())#/showdown.js');

jsEngine.eval(showdownJS);
showdownConverter = jsEngine.eval("new Showdown.converter()");

markdownString = fileRead("#getDirectoryFromPath(getCurrentTemplatePath())#/markdown.txt");

args = [markdownString];

result = jsEngine.invokeMethod(
    showdownConverter,
    "makeHtml",
    args
) & "";
</cfscript>

ma??rkdown.txt

Showdown Demo
-------------

You can try out Showdown on this page:

  - Type some [Markdown] text on the left side.
  - See the corresponding HTML on the right.

For a Markdown cheat-sheet, switch the right-hand window from *Preview* to *Syntax Guide*.

Showdown is a JavaScript port of the original Perl version of Markdown.  You can get the full [source code] by clicking on the version number at the bottom of the page.

Also check out [WMD, the Wysiwym Markdown Editor][wmd].  It'll be open source soon; email me at the address below if you'd like to help me test the standalone version.

**Start with a [blank page] or edit this document in the left window.**

  [Markdown]: http://daringfireball.net/projects/markdown/
  [source code]: http://attacklab.net/showdown/showdown-v0.9.zip
  [wmd]: http://wmd-editor.com/
  [blank page]: ?blank=1 "Clear all text"

更新

這是一個采用 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()).

氟氯化碳

<cfcomponent output="false" accessors="true">
    <cffunction name="init" output="false" access="public" returntype="Showdown" hint="Constructor">
        <cfset variables.manager = createObject("java", "javax.script.ScriptEngineManager").init()>
        <cfset variables.engine = manager.getEngineByName("javascript")>
        <cfreturn this/>
    </cffunction>

    <cffunction name="toHTML" output="false" access="public" returntype="any" hint="">
        <cfargument name="markdownText" type="string" required="true"/>
        <cfset var local = structNew()/>
        <cfset var bindings = variables.engine.createBindings()>
        <cfset var result = "">

        <cftry>
            <cfset bindings.put("markdownText", arguments.markdownText)>
            <cfset variables.engine.setBindings(bindings, createObject("java", "javax.script.ScriptContext").ENGINE_SCOPE)>
            <cfset var showdownJS = fileRead('#getDirectoryFromPath(getCurrentTemplatePath())#/showdown.js')>
            <cfset showdownJS &= showdownAdapterJS()>
            <cfset result = engine.eval(showdownJS)>
            <cfcatch type="javax.script.ScriptException">
                <cfset result = "The script had an error: " & cfcatch.Message>
            </cfcatch>
        </cftry>

        <cfreturn result>
    </cffunction>

    <cffunction name="showdownAdapterJS" output="false" access="private" returntype="string" hint="">
        <cfset var local = structNew()/>
<cfsavecontent variable="local.javascript">
<cfoutput>#chr(13)##chr(10)#var __converter = new Showdown.converter();
__converter.makeHtml(markdownText);</cfoutput>
</cfsavecontent>
        <cfreturn local.javascript>
    </cffunction>
</cfcomponent>

用法

<cfset showdown = createObject("component", "Showdown").init()>
<cfset markdownString = fileRead("#getDirectoryFromPath(getCurrentTemplatePath())#/markdown.txt")>
<cfoutput>#showdown.toHTML(markdownString)#</cfoutput>

這篇關于在服務器端為 ColdFusion 實現 Showdown.js 降價解析器的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數據庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 91国在线高清视频 | 日韩精品一区二 | 国产美女精品 | 日韩在线不卡 | 欧美久久久久 | 色综合av| 国产成人91视频 | 亚洲欧洲在线视频 | 欧美中文 | 欧美一级网站 | 久久久久久国产精品 | 在线视频h | 欧美亚洲一区二区三区 | 久久99国产精一区二区三区 | 亚洲视频 欧美视频 | 久久久av中文字幕 | 亚洲国产成人精品女人久久久 | 日韩电影免费观看中文字幕 | 91高清免费观看 | 一区二区三区不卡视频 | 亚洲精品福利视频 | 欧美一区二| 亚洲伊人久久综合 | 亚洲国产精品久久久久久 | 一区二区三区免费 | 久久国产精品一区二区 | 国产一区二区黑人欧美xxxx | 色橹橹欧美在线观看视频高清 | 成人精品一区二区三区 | 久久精品亚洲欧美日韩久久 | 99reav| 国产免费一区二区 | 久久伊人久久 | 91欧美激情一区二区三区成人 | 久久神马 | 国产精品一区一区三区 | 亚洲高清视频一区二区 | 亚洲高清在线播放 | 欧美日韩高清 | 久久国产精品-久久精品 | 免费看国产a|