Initial pointers:
Diff visualizing code is to be find around the following methods:
LexemeDiffVisualizer::visualizeEntityDiff LexemeDiff::getLexicalCategoryDiff LexemeDiff::lexicalCategory
The "correct" formatter seems to be the one that WikibaseRepo::getEntityIdHtmlLinkFormatterFactory returns