2

有谁知道如何使用挂钩或Markdown.Editor.js从 Pagedown 编辑来创建内联链接而不是引用的链接?

如,我希望在单击链接按钮时发生这种情况:

[inline link](http://www.google.com)
![alt text](http://website.com/bear.jpg "title text")

而不是这个:

[referenced link][1]
![referenced image][2]


  [1]: http://google.com/
  [2]: http://website.com/bear.jpg "title text"

谢谢!

供参考:https ://code.google.com/p/pagedown/

4

2 回答 2

3

不幸的是,在Markdown.Editor.js. 然而,我能够找到负责此的代码部分,并为您想要的功能创建一个补丁。

  1. Markdown.Editor.js在您选择的编辑器中打开。
  2. 找到这部分代码:

                    var linkDef = " [999]: " + properlyEncoded(link);
    
                    var num = that.addLinkDef(chunk, linkDef);
                    chunk.startTag = isImage ? "![" : "[";
                    chunk.endTag = "][" + num + "]";
    
  3. 替换为以下代码:

                    chunk.startTag = isImage ? "![" : "[";
                    chunk.endTag = "](" + properlyEncoded(link) + ")";
    
  4. 利润!

在此处输入图像描述

于 2015-02-11T18:18:02.433 回答
0
  1. 获取副本
  2. 打开一个文件Markdown.Converter.js
  3. 滚动到第 724 行
  4. 编辑方法function _DoImages(text) {}
  5. 滚动到第 581 行
  6. 编辑方法function _DoAnchors(text) {}

最后,您可以通过编辑源代码获得绝对任何可以想象的结果。

升级版:

只是为了好玩补丁(如果你喜欢补丁):

converter.hooks.chain("postConversion", function (text) {
    var anchors = [];
    // definitions
    text = text.replace(/\[(\d+)\]\: (htt.+)\n/gi, function(anchor_definition){
         anchors.push(anchor_definition.match(/(htt.+)\n/i)[1]);
         return("");
    });
    // anchors in the text
    text = text.replace(/\]\[\d+\]/gi, function(anchor){
        var id = parseInt(anchor.match(/\d+/)[0]);
        var code = "][" + (anchors[id - 1]) + "]";
            return(code);
    });

    return(text);        
});
于 2015-02-11T17:49:50.547 回答