render method
Implementation
String render(String markdown) {
final values = <String, String>{
'APP_NAME': appName,
'CONTROLLER_NAME': controllerName,
'CONTACT_EMAIL': contactEmail,
'UPDATED_AT': updatedAt,
'SITE_URL': origin.toString().replaceFirst(RegExp(r'/$'), ''),
'PRIVACY_URL': privacyUrl.toString(),
'TERMS_URL': termsUrl.toString(),
'ACCOUNT_DELETION_URL': deletionUrl.toString(),
};
// Braces are reserved for template tokens. Match lone braces too so that
// truncated or nested tokens cannot silently appear in a public document.
// Replacements are checked as data and never parsed as another template.
return markdown.replaceAllMapped(RegExp(r'\{\{[^{}]*\}\}|[{}]'), (match) {
final token = match.group(0)!;
if (!token.startsWith('{{') || !token.endsWith('}}')) {
throw const FormatException('Malformed legal placeholder');
}
final value = values[token.substring(2, token.length - 2)];
if (value == null) {
throw const FormatException('Unsupported legal placeholder');
}
if (RegExp(r'[{}]').hasMatch(value)) {
throw const FormatException('Nested legal placeholder');
}
return value;
});
}