1

wmd编辑器是否可以添加一个按钮让用户将图像上传到Web服务器并将相应的img markdown放在文本框中?如果没有,另一个好的就地编辑器会这样做吗?背景:我正在使用 asp.net mvc、C#,我是一个真正的 javascript 初学者。

4

3 回答 3

1

这是 WMD 附带的最小示例的变体:

    <!DOCTYPE html>
<html>
  <head>
    <title>WMD minimal example</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>
    <script type="text/javascript">
    $.fn.insertAtCaret = function (myValue) {
            return this.each(function(){
                    //IE support
                    if (document.selection) {
                            this.focus();
                            sel = document.selection.createRange();
                            sel.text = myValue;
                            this.focus();
                    }
                    //MOZILLA/NETSCAPE support
                    else if (this.selectionStart || this.selectionStart == '0') {
                            var startPos = this.selectionStart;
                            var endPos = this.selectionEnd;
                            var scrollTop = this.scrollTop;
                            this.value = this.value.substring(0, startPos)
                                          + myValue
                                  + this.value.substring(endPos,
    this.value.length);
                            this.focus();
                            this.selectionStart = startPos + myValue.length;
                            this.selectionEnd = startPos + myValue.length;
                            this.scrollTop = scrollTop;
                    } else {
                            this.value += myValue;
                            this.focus();
                    }
            });

    };

    int i = 50;

    function Add()
    {
        $("#myTextarea").insertAtCaret("![alt text][" +(i++)+"]");
        // You'll need to add the link too, at the bottom
    }
    </script>
  </head>
  <body>

    <form>
    <a href="javascript:Add()">test</a>
        <textarea id="myTextarea" style="width: 500px; height: 200px;">*This* is a minimal example.</textarea>
    </form>
    <div class="wmd-preview"></div>

    <script type="text/javascript" src="wmd/wmd.js"></script>
  </body>
</html>

但这只是你可能知道的开始。这个markdown编辑器看起来更好

于 2009-02-01T20:13:59.757 回答
1

对WMD的简要阅读似乎表明该功能不直接支持,并且该控件不是特别可插入的。

话虽如此,没有什么可以阻止您创建按钮/上传字段/将图像发送到您的服务器并注入适当的任何内容:

<img src="http://your.server.com/path/to/attachments/..." />

进入控件的底层文本区域。

于 2008-12-17T18:00:45.840 回答
0

我写了一篇博文,解释了我是如何解决这个问题的。在帖子中,我使用 PHP - 如果您愿意将我的 PHP 逻辑转换为 ASP.NET,您可能会发现它很有帮助!

于 2012-09-18T07:07:14.277 回答