forked from cory/tildefriends
Cory McWilliams
fc9c3982c2
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3957 ed5197a5-7fde-0310-b194-c3ffbd925b24
31 lines
988 B
JavaScript
31 lines
988 B
JavaScript
import * as tf from './tf.js';
|
|
|
|
export function markdown(md) {
|
|
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);
|
|
} |