Support for shortlinks?

Doing this at the rendering system is likely impossible. Instead, I’ve added a couple of links to toggle the prefix (this is slightly hacky, but, hey, tinkerware, right?)

silverbullet.registerCommand({name: "Linkify: Add http://"}, async() => {
  let text = await editor.getText();
  matches = text.matchAll(/([\s^])((bug|change)\/[A-Za-z0-9_\-]+)/g);
  let changes = [];
  for (match of matches) {
    let from = match.index + match[1].length;
    let to = from + match[2].length;
    changes.push({from:from, to:to, insert: "http://" + match[2]});
  }
  console.log(changes);
  editor.dispatch({changes});
})

silverbullet.registerCommand({name: "Linkify: Drop http://"}, async() => {
  let text = await editor.getText();
  matches = text.matchAll(/\bhttp:\/\/((bug|change)\/[A-Za-z0-9_\-]+)/g);
  let changes = [];
  for (match of matches) {
    let from = match.index;
    let to = match.index + match[0].length;
    changes.push({from:from, to:to, insert: match[1]});
  }
  console.log(changes);
  editor.dispatch({changes});
})
2 Likes