2022-01-18 21:37:39 -05:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
function markdown(md) {
|
|
|
|
var reader = new commonmark.Parser({safe: true});
|
|
|
|
var writer = new commonmark.HtmlRenderer();
|
2022-01-23 15:49:36 -05:00
|
|
|
var parsed = reader.parse(md || '');
|
2022-01-18 21:37:39 -05:00
|
|
|
var walker = parsed.walker();
|
|
|
|
var event, node;
|
|
|
|
while ((event = walker.next())) {
|
|
|
|
node = event.node;
|
2022-02-25 13:24:48 -05:00
|
|
|
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.type == 'image') {
|
|
|
|
if (node.destination.startsWith('&')) {
|
|
|
|
node.destination = '/' + node.destination + '/view';
|
|
|
|
}
|
2022-01-18 21:37:39 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return writer.render(parsed);
|
|
|
|
}
|