@imtk/md-links-graph
v1.3.0
Published
Markdown Links Graph
Downloads
45
Maintainers
Readme
md-links-graph
Create a graph data structure based on Markdown content and links.
Install
With yarn:
yarn add @imtk/md-links-graph
With npm:
npm add @imtk/md-links-graph
Usage
import { createGraph } from '@imtk/md-links-graph';
const posts = [
{
url: '/post-1',
title: 'Post 1',
content: 'Markdown content for post 1'
},
{
url: '/post-2',
title: 'Post 2',
content: 'Post 2 linked to [post 1](/post-1)'
}
];
const graph = createGraph(posts);
graph.nodes;
// [
// {
// url: '/post-1',
// text: 'Post 1',
// id: 0
// },
// {
// url: '/post-2',
// text: 'Post 2',
// id: 1
// }
// ]
graph.edges;
// [
// {
// source: '1',
// target: '0'
// }
// ];
Types
Node
type Url = string;
type Node = {
id: number;
text: string;
url: Url;
};
Edge
type Edge = {
source: string;
target: string;
};
Post input
type PostMarkdown = {
url: string;
title: string;
content: string;
};