Pagedown Editor - 制作内联链接而不是引用链接

Pagedown Editor - make inline links instead of referenced links

有谁知道如何使用挂钩或编辑 Pagedown 中的 Markdown.Editor.js 以使其创建内联 link 而不是引用的?

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

[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/

  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);        
});

不幸的是,在 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. 盈利!