ASP.NET MVC 3 및 Stackoverflow의 Markdown을 사용하는 방법
나는 지금 몇 시간 동안 조사를 해왔고 이에 대한 실제 출처를 찾을 수 없었습니다. ASP.NET MVC 3에서 사이트를 구축 중이며 StackOverflow에서 사용하는 Markdown 편집기를 활용하고 싶습니다. 누구든지 좋은 튜토리얼이 있습니까?
최신 마크 다운은 어디에서 다운로드합니까? 어떤 언어로 작성 되었습니까? 이것을 MVC 3 프로젝트에 통합하려면 어디에서 시작해야합니까? 모든 검색과 읽기를 마친 후에도 여전히 혼란 스럽습니다.
한 사이트를 발견했습니다. http://daringfireball.net/projects/markdown/ 그러나 이것은 이상하게 오래되어 보이지만 전혀 경험이없는 CGI와 PERL에 대해 조금 배워야 할 것 같습니다. javascript / jQuery 버전은 훌륭합니다. 모든 아이디어, 링크, 참조는 대단히 감사합니다.
최신 정보
이 질문이 상당한 조회수를 얻고 있다는 것을 알았으므로 유용한 참고 자료로 업데이트하기로 결정했습니다. CodeTunnel.com 에서 잘 작동하는 Markdown 편집기를 얻을 수 있었고 이에 대한 블로그를 몇 개 작성했습니다. 바라건대 그들은이 질문을 접하는 모든 사람을 돕습니다.
Stackoverflow는 Markdown 버전을 세계에 공개했습니다. MarkdownSharp 라고 하며 C #으로 작성되었습니다.
누군가 HtmlHelper를 여기에 작성했습니다 : http://blog.dantup.com/2011/03/an-asp-net-mvc-htmlhelper-extension-method-for-markdown-using-markdownsharp
자바 스크립트 편집기를 구현하는 방법을 찾고 있다면 기존 질문이 있습니다. Markitup 텍스트 편집기를 ASP.NET MVC 프로젝트에 통합
MarkdownSharp를 찾고있을 것입니다.
Stack Overflow에 소개 된 Markdown 프로세서의 오픈 소스 C # 구현입니다.
MVC 앱에 통합하려면 :
until 또는 공통 컨트롤러에서 다음 작업 방법을 추가하십시오.
public ActionResult FormatMarkdown(string markdownText) { var md = new MarkdownSharp.Markdown(); string html = md.Transform(markdownText); return Json(html, JsonRequestBehavior.AllowGet); }
클라이언트 측보기에서 :
@Html.TextArea("mdText", new { rows = 12, cols = 60 }) <div id="mdFormatted"></div>
및 클라이언트 측 JS :
$(function () { var mdText = $("#mdText"); var mdFormatted = $("#mdFormatted"); function setFormatted(data) { mdFormatted.html(data); }; mdText.toObservable("keypress") .Throttle(200) .Subscribe(function () { $.getJSON("@VirtualPathUtility.ToAbsolute("~/Util/FormatMarkdown/")", { markdownText: mdText.val() }, setFormatted); })
MSDN 에서 RxJ를 다운로드 하고 다음 두 개의 js 파일을 포함합니다.
<script src="@Url.Content("~/Scripts/rx.js")" type="text/javascript"></script> <script src="@Url.Content("~/Scripts/rx.jquery.js")" type="text/javascript"></script>
나는이 질문이 오래되었다는 것을 알고 있지만 MVC와 매우 친숙한 다른 솔루션 markdowndeep 을 우연히 발견했습니다.
Nuget PM> Install-Package MarkdownDeep.Full을 통해 설치할 수 있습니다.
// Create an instance of Markdown
var md = new MarkdownDeep.Markdown();
// Set options
md.ExtraMode = true;
md.SafeMode = false;
string output = md.Transform(input);
1. 제공된 js, css, png 및 htm 파일을 서버에 복사합니다. 이러한 파일을 서버에 배치하는 위치에 따라 css 파일에서 이미지 URL을 업데이트해야 할 수 있습니다.
2. jQuery, MarkdownDeep 라이브러리 및 MarkdownDeep css 파일을 참조하도록 페이지를 업데이트합니다 (다시 경로를 변경해야 할 수 있음).
<link rel="stylesheet" href="mdd_styles.css"
<script type="text/javascript" src="jQuery-1.4.2.min.js">
<script type="text/javascript" src="MarkdownDeepLib.min.js">
NB : MarkdownDeepLib.min.js는 MarkdownDeep.js, MarkdownDeepEditor.js 및 MarkdownDeepEditorUI.js의 패키지화 된 축소 버전입니다. 디버깅을 위해이 세 파일을 대신 참조 할 수 있습니다.
3. Markdown 편집기를 다음과 같이 페이지에 삽입합니다.
<div class="mdd_toolbar"></div>
<textarea cols=50 rows=10 class="mdd_editor"></textarea>
<div class="mdd_resizer"></div>
<div class="mdd_preview"></div>
Note: the associated divs are all optional and if missing, the plugin will create them. However... you might experience the page jumping around during load if you do this. ie: it's recommended to explicitly include them.
4.Called the MarkdownDeep jQuery plugin to convert the textarea to a MarkdownEditor
$("textarea.mdd_editor").MarkdownDeep({
help_location: "/Content/mdd_help.html",
disableTabHandling:true
});
Although I really like their product I am not affiliated with the makers of markdowndeep. I just thought they made a good product
This question is old, but I'm just leaving an answer here so that future readers can benefit from it.
I have used MarkdownSharp v1.13, It does NOT sanitize your html output. For example, if you type:
<script type="text/javascript">alert("Hacked");</script>
Into your input field, the output from MarkdownSharp contains the same script. Thus it exposes your website to XSS vulnerability.
Read this from Stackoverflow's article on PageDown:
It should be noted that Markdown is not safe as far as user-entered input goes. Pretty much anything is valid in Markdown, in particular something like
<script>doEvil();</script>
. This PageDown repository includes the two plugins that Stack Exchange uses to sanitize the user's input; see the description of Markdown.Sanitizer.js below.
So, from other point of view, maybe Markdown was not supposed to sanitize your input in the first place and MarkdownSharp implementation of it just conformed with those principles. I should mention that Stackoverflow does uses MarkdownSharp on their server side.
참고URL : https://stackoverflow.com/questions/5320922/how-to-use-asp-net-mvc-3-and-stackoverflows-markdown
'IT박스' 카테고리의 다른 글
Git에서 특정 태그로 되 돌리는 방법은 무엇입니까? (0) | 2020.11.05 |
---|---|
Android 권한 : 전화 통화 : 전화 상태 및 ID 읽기 (0) | 2020.11.05 |
gcc에서 '-l'옵션의 순서가 중요한 이유는 무엇입니까? (0) | 2020.11.05 |
# 모든 .cpp 파일을 단일 컴파일 단위에 포함 하시겠습니까? (0) | 2020.11.05 |
데이터 바인딩 유형을 안전하게 만들고 리팩토링을 지원하는 방법 (0) | 2020.11.05 |