This repository has been archived on 2022-08-14. You can view files and clone it, but cannot push or open issues or pull requests.
outline/server/utils/parseDocumentIds.js
Tom Moor 14cb3a36c1
perf: Reduce initial bundle size / async bundle loading (#1456)
* feat: Move to React.lazy

* perf: Remove duplicate babel/runtime

* fix: Run yarn-deduplicate

* Further attempts to remove rich-markdown-editor from initial chunk

* perf: Lazy loading of authenticated routes

* perf: Move color picker to async loading
fix: Display placeholder when loading rich editor

* fix: Cache bust on auto reload
2020-08-14 17:23:58 -07:00

40 lines
988 B
JavaScript

// @flow
import { parser } from "rich-markdown-editor";
export default function parseDocumentIds(text: string): string[] {
const value = parser.parse(text);
let links = [];
function findLinks(node) {
// get text nodes
if (node.type.name === "text") {
// get marks for text nodes
node.marks.forEach((mark) => {
// any of the marks links?
if (mark.type.name === "link") {
const { href } = mark.attrs;
// any of the links to other docs?
if (href.startsWith("/doc")) {
const tokens = href.replace(/\/$/, "").split("/");
const lastToken = tokens[tokens.length - 1];
// don't return the same link more than once
if (!links.includes(lastToken)) {
links.push(lastToken);
}
}
}
});
}
if (!node.content.size) {
return;
}
node.content.descendants(findLinks);
}
findLinks(value);
return links;
}