paste in document links code; cut down for re-use in mark's thing