How to set a base url for markdown links in IPython?

放肆的年华 提交于 2019-12-10 20:13:11

问题


I was happily setting

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

in a Markdown cell in my IPython html notebook (IPython 0.12) in order to be able to abbreviate links as[wiki documentation](doc.html) in Markdown cells.

But this makes saving the notebook impossible (saving is restored by <base href='/'/>).

Is there any (alternative) way to achieve what I am seeking? I know how to produce the URL from Python code by use of IPython.core.display.HTML[1], but it is considerably more convenient to inline the links in the Markdown documentation

Thanks,

Álvaro.

[1] The non-optimal solution producing the link from Python is pasted below in case it is useful for somebody or you have suggestions for improvement

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

来源:https://stackoverflow.com/questions/11030525/how-to-set-a-base-url-for-markdown-links-in-ipython

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!