pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

在服務(wù)器端為 ColdFusion 實(shí)現(xiàn) Showdown.js 降價(jià)解析器

Implementating Showdown.js markdown parser on the server side for ColdFusion(在服務(wù)器端為 ColdFusion 實(shí)現(xiàn) Showdown.js 降價(jià)解析器)
本文介紹了在服務(wù)器端為 ColdFusion 實(shí)現(xiàn) Showdown.js 降價(jià)解析器的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

這是一個(gè)事實(shí)調(diào)查"問(wèn)題,旨在了解使用 showdown.js 解析器. 已經(jīng)有一個(gè)使用 showdown.js 的 java 實(shí)現(xiàn)(參見(jiàn)本文末尾的代碼),我想看看如何為 ColdFusion 實(shí)現(xiàn)它.我沒(méi)有 Java 方面的經(jīng)驗(yàn),我不會(huì)特別稱(chēng)自己為程序員",但我不希望這阻止我嘗試.

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.

總結(jié)

我想在服務(wù)器端運(yùn)行 Shadown.js 以便將 Markdown 轉(zhuǎn)換為 HTML.

I would like to run Shadown.js server-side in order to convert markdown to HTML.

為什么?

保存用戶(hù)條目的兩個(gè)版本,一個(gè)是 Markdown 格式,另一個(gè)是 HTML,允許我們向最終用戶(hù)顯示原始 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.

為什么不使用服務(wù)器端解析器?

有兩個(gè)原因:

  1. 到目前為止,還沒(méi)有針對(duì)此特定目的的 ColdFusion 降價(jià)解析器
  2. 在客戶(hù)端使用 Showdown.js,然后在服務(wù)器端使用不同的解析器,將導(dǎo)致顯示給客戶(hù)端的預(yù)覽與存儲(chǔ)在數(shù)據(jù)庫(kù)中的版本之間的標(biāo)記不一致.鑒于 Markdown 定義松散,大多數(shù)解析器實(shí)現(xiàn)都會(huì)有細(xì)微差別.

有一個(gè)非常好的博客條目 討論這個(gè)問(wèn)題.

為什么不在客戶(hù)端進(jìn)行所有解析并發(fā)布兩個(gè)版本?

這并不是一個(gè)安全的解決方案.我還認(rèn)為用戶(hù)可能會(huì)使用不匹配的 HTML 發(fā)布降價(jià).

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.

是否有任何現(xiàn)有的實(shí)現(xiàn)?

有 一個(gè)名為 CFShowdown 的實(shí)現(xiàn),但它不是為了這個(gè)特定目的.相反,它用于處理頁(yè)面上的輸出.上述博客的評(píng)論區(qū)具有一個(gè)名為 David 的用戶(hù)編寫(xiě)的純 Java 實(shí)現(xiàn):

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]";
}

目標(biāo)

創(chuàng)建一個(gè) java 類(lèi),允許我們將此實(shí)現(xiàn)與 ColdFusion UDF 或組件內(nèi)的自定義標(biāo)簽一起使用,類(lèi)似于 <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)>

由于我沒(méi)有使用 Java 的經(jīng)驗(yàn),我想從用戶(hù)那里獲得一些建議和意見(jiàn),了解從何處以及如何開(kāi)始執(zhí)行此任務(wù).我創(chuàng)建了一個(gè)

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"

更新

這是一個(gè)采用 Adam Presley 在 Java 中的工作 并且全部在 CFC 中完成.請(qǐng)注意,我把他在 showdown.js 末尾添加的那一點(diǎn)魔法放入一個(gè) CFC 函數(shù)中,該函數(shù)的返回值被附加(即 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>

這篇關(guān)于在服務(wù)器端為 ColdFusion 實(shí)現(xiàn) Showdown.js 降價(jià)解析器的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周?chē)h(huán)繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動(dòng)生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數(shù)據(jù)庫(kù))
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對(duì)象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 工业机械三维动画制作 环保设备原理三维演示动画 自动化装配产线三维动画制作公司-南京燃动数字 聚合氯化铝_喷雾聚氯化铝_聚合氯化铝铁厂家_郑州亿升化工有限公司 | 生物风-销售载体,基因,质粒,ATCC细胞,ATCC菌株等,欢迎购买-百风生物 | 十字轴_十字轴万向节_十字轴总成-南京万传机械有限公司 | 橡胶接头_橡胶软接头_套管伸缩器_管道伸缩器厂家-巩义市远大供水材料有限公司 | 深圳天际源广告-形象堆头,企业文化墙,喷绘,门头招牌设计制作专家 | 西安文都考研官网_西安考研辅导班_考研培训机构_西安在职考研培训 | 小港信息港-鹤壁信息港 鹤壁老百姓便民生活信息网站 | 济南ISO9000认证咨询代理公司,ISO9001认证,CMA实验室认证,ISO/TS16949认证,服务体系认证,资产管理体系认证,SC食品生产许可证- 济南创远企业管理咨询有限公司 郑州电线电缆厂家-防火|低压|低烟无卤电缆-河南明星电缆 | 安徽控制器-合肥船用空调控制器-合肥家电控制器-合肥迅驰电子厂 安徽净化板_合肥岩棉板厂家_玻镁板厂家_安徽科艺美洁净科技有限公司 | 香港新时代国际美容美发化妆美甲培训学校-26年培训经验,值得信赖! | 美能达分光测色仪_爱色丽分光测色仪-苏州方特电子科技有限公司 | 高博医疗集团上海阿特蒙医院| 重庆钣金加工厂家首页-专业定做监控电视墙_操作台 | 中高频感应加热设备|高频淬火设备|超音频感应加热电源|不锈钢管光亮退火机|真空管烤消设备 - 郑州蓝硕工业炉设备有限公司 | 上海刑事律师|刑事辩护律师|专业刑事犯罪辩护律师免费咨询-[尤辰荣]金牌上海刑事律师团队 | 亚克力制品定制,上海嘉定有机玻璃加工制作生产厂家—官网 | 美国HASKEL增压泵-伊莱科elettrotec流量开关-上海方未机械设备有限公司 | 电主轴-高速精密电主轴-高速电机厂家-瑞德沃斯品牌有限公司 | 土壤有机碳消解器-石油|表层油类分析采水器-青岛溯源环保设备有限公司 | 纯化水设备-EDI-制药-实验室-二级反渗透-高纯水|超纯水设备 | 发电机价格|发电机组价格|柴油发电机价格|柴油发电机组价格网 | 免费分销系统 — 分销商城系统_分销小程序开发 -【微商来】 | 泰来华顿液氮罐,美国MVE液氮罐,自增压液氮罐,定制液氮生物容器,进口杜瓦瓶-上海京灿精密机械有限公司 | 精雕机-火花机-精雕机 cnc-高速精雕机-电火花机-广东鼎拓机械科技有限公司 | 聚丙烯酰胺_厂家_价格-河南唐达净水材料有限公司| 压片机_高速_单冲_双层_花篮式_多功能旋转压片机-上海天九压片机厂家 | 湖南自考_湖南自学考试网 | 合肥卓创建筑装饰,专业办公室装饰、商业空间装修与设计。 | 闪蒸干燥机-喷雾干燥机-带式干燥机-桨叶干燥机-[常州佳一干燥设备] | 热处理温控箱,热处理控制箱厂家-吴江市兴达电热设备厂 | 隧道风机_DWEX边墙风机_SDS射流风机-绍兴市上虞科瑞风机有限公司 | 电机修理_二手电机专家-河北豫通机电设备有限公司(原石家庄冀华高压电机维修中心) | 苗木价格-苗木批发-沭阳苗木基地-沭阳花木-长之鸿园林苗木场 | vr安全体验馆|交通安全|工地安全|禁毒|消防|安全教育体验馆|安全体验教室-贝森德(深圳)科技 | 手持式浮游菌采样器-全排二级生物安全柜-浙江孚夏医疗科技有限公司 | 盘扣式脚手架-附着式升降脚手架-移动脚手架,专ye承包服务商 - 苏州安踏脚手架工程有限公司 | 环氧乙烷灭菌器_压力蒸汽灭菌器_低温等离子过氧化氢灭菌器 _低温蒸汽甲醛灭菌器_清洗工作站_医用干燥柜_灭菌耗材-环氧乙烷灭菌器_脉动真空压力蒸汽灭菌器_低温等离子灭菌设备_河南省三强医疗器械有限责任公司 | 防爆电机-高压防爆电机-ybx4电动机厂家-河南省南洋防爆电机有限公司 | ASA膜,ASA共挤料,篷布色母料-青岛未来化学有限公司 | 天坛家具官网| 活性氧化铝|无烟煤滤料|活性氧化铝厂家|锰砂滤料厂家-河南新泰净水材料有限公司 |