fix bug where reference followed by a comment wouldn't get completed with the right end index
include refs that are inside conditional comments

closes #1