2022-06-19 18:08:15 -04:00
|
|
|
export function markdown(md) {
|
2022-02-26 21:30:11 -05:00
|
|
|
var reader = new commonmark.Parser({safe: true});
|
|
|
|
var writer = new commonmark.HtmlRenderer();
|
|
|
|
var parsed = reader.parse(md || '');
|
|
|
|
var walker = parsed.walker();
|
|
|
|
var event, node;
|
|
|
|
while ((event = walker.next())) {
|
|
|
|
node = event.node;
|
|
|
|
if (event.entering) {
|
|
|
|
if (node.type == 'link') {
|
|
|
|
if (node.destination.startsWith('@') &&
|
|
|
|
node.destination.endsWith('.ed25519')) {
|
|
|
|
node.destination = '#' + node.destination;
|
|
|
|
} else if (node.destination.startsWith('%') &&
|
|
|
|
node.destination.endsWith('.sha256')) {
|
|
|
|
node.destination = '#' + node.destination;
|
|
|
|
} else if (node.destination.startsWith('&') &&
|
|
|
|
node.destination.endsWith('.sha256')) {
|
|
|
|
node.destination = '/' + node.destination + '/view';
|
|
|
|
}
|
|
|
|
} else if (node.type == 'image') {
|
|
|
|
if (node.destination.startsWith('&')) {
|
|
|
|
node.destination = '/' + node.destination + '/view';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return writer.render(parsed);
|
|
|
|
}
|