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

时间:2015-02-09 16:52:55

标签: javascript markdown pagedown

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

同样,我想在单击链接按钮时发生这种情况:

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

2 个答案:

答案 0 :(得分:2)

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

  5. enter image description here

答案 1 :(得分:0)

  1. 获取副本
  2. 打开文件Markdown.Converter.js
  3. 滚动到第724行
  4. 编辑方法function _DoImages(text) {}
  5. 滚动至第581行
  6. 编辑方法function _DoAnchors(text) {}
  7. 最后,通过编辑源代码,您可以获得绝对任何可想象的结果。

    UPD:

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

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