2

我正在使用 PageDown 编辑器,并且在我的 asp.net 页面中有以下标记:

<script type="text/javascript" src="js/Markdown.Converter.js"></script>
        <script type="text/javascript" src="js/Markdown.Sanitizer.js"></script>
        <script type="text/javascript" src="js/Markdown.Editor.js"></script>
    </HEAD>
    <body>
        <form id="myForm" runat="server">
            <div class="wmd-panel">
                <div id="wmd-button-bar"></div>
                <textarea id="wmd_input" class="wmd-input" runat="server"></textarea>
                <div id="wmd-preview" class="wmd-panel wmd-preview"></div>
            </div>
            <script type="text/javascript">
            (function () {
                var converter1 = Markdown.getSanitizingConverter();
                var editor1 = new Markdown.Editor(converter1);
                editor1.run();
            })();
            </script>
            <asp:button id="Button1" runat="server" Text="Set"></asp:button><asp:button id="Button2" runat="server" Text="Get"></asp:button><asp:label id="Label1" runat="server">Label</asp:label></form>
    </body>
</HTML>

结果如下:

在此处输入图像描述

所以我有一个服务器端事件,它只是获取存储的值并将其分配给一个标签,这样我就可以看到我得到了什么:

Me.Label1.Text = Me.wmd_input.Value

因此,如果我**test**的文本区域框中有类似的内容(以粗体显示),我希望能够单击“获取”按钮并返回具有此效果的内容<b>test</b>,而不是**test**. 现在我要回来了**test**,有什么办法可以<b>test</b>取而代之的是 HTML 标记?

4

1 回答 1

1

.makeHtml("markdown text")在客户端使用

对于您的情况

    converter1.makeHtml("*Hello World*")

要在服务器端获取 Html 值,请使用MarkDown Sharp等降价的服务器端实现,或者您可以使用隐藏的输入字段。

 <script type="text/javascript" src="js/Markdown.Converter.js"></script>
    <script type="text/javascript" src="js/Markdown.Sanitizer.js"></script>
    <script type="text/javascript" src="js/Markdown.Editor.js"></script>
</HEAD>
<body>
    <form id="myForm" runat="server">
        <div class="wmd-panel">
            <div id="wmd-button-bar"></div>
            <textarea id="wmd_input" class="wmd-input" runat="server"></textarea>
            <div id="wmd-preview" class="wmd-panel wmd-preview"></div>
        </div>
        <script type="text/javascript">
        (function () {
            var converter1 = Markdown.getSanitizingConverter();
            var editor1 = new Markdown.Editor(converter1);
            editor1.run();
        })();
        function SetHidden(){
            var hidden = document.getElementById('<%= HiddenMarkdow.ClientID %>');
            var textArea = document.getElementById('<%= wmd_input.ClientID %>');
            var converter1 = Markdown.getSanitizingConverter();
            hidden.value = converter1.makeHtml(textArea.value);
            return true;
        }



        </script>
        <asp:HiddenField id="HiddenMarkdown" runat="server"/>
        <asp:button id="Button1" runat="server" Text="Set"></asp:button><asp:button id="Button2" runat="server" Text="Get" OnClick="SetHidden()"></asp:button><asp:label id="Label1" runat="server">Label</asp:label></form>
</body>

于 2012-11-05T16:56:27.537 回答