如何在IPython中为markdown链接设置基本URL?

时间:2012-06-14 09:45:23

标签: python html markdown ipython

我很开心地设置

 
<head>
<base href="http://complex_url_to_local_wiki:port/path/" target="_blank" />
</head>

在我的IPython html笔记本(IPython 0.12)中的Markdown单元格中,以便能够在Markdown单元格中将链接缩写为[wiki documentation](doc.html)

但是这使得无法保存笔记本(保存由<base href='/'/>恢复。)

有没有(替代)方式来实现我所寻求的目标?我知道如何使用IPython.core.display.HTML [1]从Python代码生成URL,但是在Markdown文档中内联链接要方便得多

谢谢,

阿尔瓦罗。

[1]下面粘贴了生成Python链接的非最佳解决方案,以防它对某人有用或者你有改进建议

def wurl(x, text="Node {} in wiki",
            baseurl="http://complex_url_to_local_wiki:port/path/{}"):
    """Render a link on a base URL as html."""

    from IPython.core.display import HTML
    url_t = '<a href="{baseurl}" target="_blank">{text}</a>'
    return HTML(url_t.format(baseurl=baseurl.format(x), text=text.format(x)))

0 个答案:

没有答案
相关问题