refactor link-generating code

linkto and resolveLinks now rely on shared functions instead of
reimplementing one another
rework type extraction and inline tag parsing

- brace-counting logic now lives in the type code, which is where it's
needed
- we now replace (and return) ALL instances of an inline tag, not just
the first one
use inline tag module in templateHelper; allow inline tag replacers to operate on the entire string

the latter change undoes part of
9de918ab942c3d9a5c2883130d5b9b1a965b2bb2