fenceOpen function
The fence trimmed (an already left-trimmed line) opens, or null.
CommonMark: a backtick fence's info string may not contain a backtick.
That is what keeps a one-line ```code``` an inline code span
instead of a fence that swallows the rest of the document.
Implementation
FenceOpen? fenceOpen(String trimmed) {
if (trimmed.length < 3) {
return null;
}
final c = trimmed.codeUnitAt(0);
if (c != _backtickUnit && c != _tildeUnit) {
return null;
}
var run = 1;
while (run < trimmed.length && trimmed.codeUnitAt(run) == c) {
run += 1;
}
if (run < 3) {
return null;
}
final info = trimmed.substring(run).trim();
if (c == _backtickUnit && info.contains('`')) {
return null;
}
return (fenceChar: c, length: run, info: info);
}