1
0
forked from cory/tildefriends
Files
apps
cory
apps
docs
index
app.js
commonmark.min.js
index.html
material-icons.css
roboto.css
tf-message.js
tf-shared.js
tf-user.js
tf.js
vue-material-theme-default-dark.css
vue-material.js
vue-material.min.css
vue.js
ssb
apps.json
docs.json
index.json
ssb.json
core
deps
docs
src
tools
.dockerignore
Dockerfile
LICENSE
Makefile
README.md
tildefriends/apps/cory/index/tf-shared.js
2022-02-25 18:24:48 +00:00

28 lines
810 B
JavaScript

"use strict";
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.type == 'image') {
if (node.destination.startsWith('&')) {
node.destination = '/' + node.destination + '/view';
}
}
}
}
return writer.render(parsed);
}