Better links with Python Markdown

2014-01-04T10:24:23Z Homepage

Python Markdown package renders links like <http://example.com> as <a href="http://example.com">http://example.com</a>, i.e. with http:// in the text. As for me, it doesn’t have any use and just adds visual clutter. Luckily, this markdown processor is easily extensible, and with a couple lines of code you can make such links to render as <a href="http://example.com">example.com</a>. The corresponding Python code, which adds a postprocessing step:

import re
from markdown import Markdown
from markdown.postprocessors import Postprocessor

class LinkPostprocessor(Postprocessor):
    def run(self, text):
        return re.sub(r'(<a [^>]+>)https?://', r'\1', text)

md = Markdown(...)
md.postprocessors.add('links', LinkPostprocessor(md), '_end')

Fix addresses starting with "www"

2014-01-03T20:34:15Z Homepage

For a long time I didn’t notice that addresses like www.plav.in returned 404 - Not Found, as I myself never use them. Recently I was told about this issue and fixed it - now you can use such addresses as well. Old domain name also works, like this: www.blog.aplavin.ru/fix-addresses-starting-with-www. All these URLs redirect to the “canonical” one, at plav.in and without www.

The related piece of my Nginx configuration, to make this post useful for more people :) is below:

server {
    server_name aplavin.ru;
    rewrite ^ http://plav.in$request_uri? permanent;
}

server {
    server_name ~^(?<subdomain>.+)\.aplavin\.ru$;
    rewrite ^ http://$subdomain.plav.in$request_uri? permanent;
}

server {
    server_name www.plav.in;
    rewrite ^ http://plav.in$request_uri? permanent;
}

server {
    server_name ~^www\.(?<subdomain>.+)\.plav\.in$;
    rewrite ^ http://$subdomain.plav.in$request_uri? permanent;
}

Requested changes and comments

2013-08-12T22:28:11Z Mercurial, GSoC

In this post, and may be other such posts in the future, I will list important comments received in response to my sent patches, not to forget something. As for now, they are:

  • search mode indication: wrap “Assuming …” in <p>...</p>
  • search mode indication: make mode descriptions localisable
  • revset tree depth: clearer commit message
  • revset search: blacklist regexps usage
  • makeRequest (js): get rid of all the ActiveXObject IE-related magic
  • ajax infinite scroll: don’t strip one entry in the backend explicitly
  • ajax infinite scroll: indicate when there are no more items
  • ajax infinite scroll: get rid of shortlogajax template

Infinite scrolling

2013-07-23T20:23:05Z Mercurial, GSoC

I’ve started implementing ‘infinite scrolling’ feature, and now it’s already available in action for shortlog view at my running hgweb instance.

Upcoming plan

2013-07-23T20:02:17Z Mercurial, GSoC

Some things I’m going to implement/extend in hgweb soon as part of the GSoC project:

  • search field looks also for file names (not sure if it’s wanted through)
  • ‘infinite scrolling’ with AJAX for {short,change}log, graph, search
  • dynamic search results (without page reload)

Hgweb search - extended

2013-07-23T09:42:22Z Mercurial, GSoC

Currently hgweb supports only simple keyword search and matching exact revisions by number or hash, and you can’t control it: i.e. there is no ability to search for string ‘1234’ in commit descriptions, if revision #1234 is in the repo, or to search for ‘abc’ if a changeset hash starts with ‘abc’ (and if there are multiple such changesets, you will just see an error).

My patches extend the search in several ways:

  • no matter what you type, you get only the matching revisions (querying for an exact revision in current hg works like a goto to the place in log, which is less intuitive)
  • full revset expressions syntax is supported (with a configurable restriction of certain functions, e.g. heavyweight ‘contains()’)
  • the current search mode (exact revision, keyword, or revset) is shown along with the results, and you can always force using literal keyword matching, which is useful to search literally for strings like ‘abc’, ‘1234’, or ‘keyword(a)’

As usual, all the patches can be found at hg.aplavin.ru/hg_fork, and they are actually enabled there so you can see all the new features in action.

My commits list

2013-07-12T12:47:09Z Mercurial, GSoC

From now you can see all my commits to Mercurial (both accepted and not yet) grouped by repo they are currently in at cistats.aplavin.ru.

Revset search syntax in hgweb

2013-07-09T10:36:50Z Mercurial, GSoC

Another part of my summer project is improving hgweb search by adding revset syntax to it, which is extensively used in Mercurial CLI commands. According to the feedback at ML, I’m going to change the search behaviour to use revset syntax, if the query string can be parsed as a revset tree.

Another obligatory thing here is to deny usage of some heavy revset functions. The whitelist of them, used at BitBucket seems reasonable here too.

Hgweb source views

2013-07-06T12:05:01Z Mercurial, GSoC

First part of my plan is improving source display and code cut&paste all over the hgweb, and it is going to be finished. The implementation strategy is accepted by the community, and I’ve patchbombed versions of several patches, which modify single file, diff and changeset views.

About the highlight extension

2013-06-27T15:39:08Z Mercurial

Mercurial has a nice highlight extension, which provides syntax highlighting for many languages at hgweb (example in Python).

While its output looks nice, there is quite an ugly hack in the implementation. The extension needs to intercept into the process of generating HTML page from templates, and it approaches this by defining an extra template filter called highlight (nothing bad so far), and then replacing (as a string) line|escape with line|highlight in the template. And here is the problem: if you change line|escape to e.g. line|process|escape or even just to line | escape – the highlighting will not work! Because of this it’s not that easy to change some aspects of file source display, without losing compatibility with the extension.

Actually, the extension has another, less important issue: when the actual source line is just a space or multiple spaces, the highlight’ed version of it is just empty.

Start of development

2013-05-31T20:49:57Z Mercurial, GSoC

I’ve started implementing proposed features from the beginning and the first item is improving the way hgweb display file content. By this I mean allowing to select code without line numbers and with consistent indents, and highlighting the lines which were linked at (as the hash part of the URL). Actually, these things are already partly implemented, and I’m going to tidy up, organize them and patchbomb to Mercurial.

You can always see how the code performs at hg.aplavin.ru (it usually runs the version of code which is in the last patchbombed patch), and of course at the official Mercurial repo after corresponding patches are accepted into upstream.

GSoC has started

2013-05-29T13:05:10Z Mercurial, GSoC

As I’m selected for Google Summer of Code 2013 at Mercurial project, I’m going to publish short posts here related to my coding. Now there is community bonding period on the timeline, until the June 17.

My latest development (even what is not yet accepted to upstream) will hopefully be always available as a Mercurial repo hg.aplavin.ru/hg_fork. The whole hg.aplavin.ru is running the last code from this repository.