2013-10-28

Hgext.markdown for Windows

Python eggs

Main problem with this extension on Windows OS was external dependency Markdown and unlike on Ubuntu you cannot execute apt-get python-markdown in your shell. TortoiseHG has bundled python and you cannot simply add egg inside dist-packages. I look at source and find out, that original way for Windows user was uncomment and edit line sys.path.append("c:/python27/Lib/site-packages/markdown-2.2.0-py2.7.egg") but nothing was in documentation about it.

So I decide to rewrite this mechanism in fallback style: first we try to load markdown package and if failed, lookup using path from config (python can transparently lookup files in zip archives):
try:
    from markdown import Markdown 

except ImportError:
    dir = os.path.dirname(os.path.realpath(__file__))
    md = ui.config("web", "markdown.egg", "Markdown-2.3.1")
    ui.debug("Markdown not found search for egg in local dir %s for %s.zip\n" % (dir, md))
    sys.path.append(os.path.join(dir, "%s.zip\%s" % (md, md)))
    try:
        from markdown import Markdown
    except ImportError:
        ui.error("Unable to locate markdown in path %s" % sys.path)
global Markdown


this is final version corrected by Chris Eldredge. Now you can download markdown package and put it in extension folder.

Relative paths

Rendering comparison
BitBucket vs hgext.markdown

Second big improvement is relative paths in markdown files. We massively use crossreferences in the docs we store in our repository, and quickly find out some problems with relative links in which used parent (..) directory and hash (#). I fixed this and update demo page with picture and relative navigation. Unfortunately BitBucket incorrectly render this markdown because of the bug.

Preview

Also now you can navigate to preview of uncommited files with one click in menu. Not a big deal but usability improvement.

Summary

Chris already merged this patches to his repo. So if you want to see beautiful doc instead of raw markdown, even on Windows it is good time to install or update extension.