Backport some refactoring from master:

Single place for adding values to link map, and code-block mode only
triggers if previous line is empty.
(cherry picked from commits df236ecc98d4b41d02254dffcbdee1ee315a1af3,
cd68a3972f64cb0ecfb64474069bcbe6462b9ef7 and 80218a2b34fe8894991ad7a9642ff459f8fc606d)