decodeEntities function
text with every reference in it decoded. Used for link destinations and
titles, where CommonMark decodes references too.
Implementation
String decodeEntities(String text) {
if (!text.contains('&')) {
return text;
}
final out = StringBuffer();
var i = 0;
while (i < text.length) {
if (text.codeUnitAt(i) == _amp) {
final entity = entityAt(text, i);
if (entity != null) {
out.write(entity.value);
i = entity.next;
continue;
}
}
out.writeCharCode(text.codeUnitAt(i));
i += 1;
}
return out.toString();
}