Extracted out the link building logic to make it more testable.
Added some tests for the regexp matching.