yamh_str function
Converts a string with Markdown to either a string of HTML or a HTML file.
Throws an ArgumentError if either the input or output is mentioned, but left empty. If no output is defined, the HTML is returned as a String. If an output is defined and is successfully saved to, a string saying « SAVED » is returned.
Implementation
Future<String> yamh_str(String input, String? output) async {
if (input == '') {
throw ArgumentError(
'[YAMH] You specified an input, however left the value blank.');
}
var parsed = markdownToHtml(input, inlineSyntaxes: [InlineHtmlSyntax()]);
if (output != null) {
await _saveFile(parsed, output);
return 'SAVED'; // Need to return something; so we used 'SAVED' to also allow simple callbacks with strings
} else {
return parsed;
}
}