MCPcopy
hub / github.com/foambubble/foam / createMarkdownParser

Function createMarkdownParser

packages/foam-core/src/services/markdown-parser.ts:75–277  ·  view source on GitHub ↗
(
  extraPlugins: ParserPlugin[] = [],
  cache?: ParserCache
)

Source from the content-addressed store, hash-verified

73}
74
75export function createMarkdownParser(
76 extraPlugins: ParserPlugin[] = [],
77 cache?: ParserCache
78): ResourceParser {
79 const plugins = [
80 titlePlugin,
81 wikilinkPlugin,
82 tagsPlugin,
83 aliasesPlugin,
84 sectionsPlugin,
85 blocksPlugin,
86 ...extraPlugins,
87 ];
88
89 for (const plugin of plugins) {
90 try {
91 plugin.onDidInitializeParser?.(parser);
92 } catch (e) {
93 handleError(plugin, 'onDidInitializeParser', undefined, e);
94 }
95 }
96
97 const foamParser: ResourceParser = {
98 parse: (uri: URI, markdown: string): Resource => {
99 Logger.debug('Parsing:', uri.toString());
100 for (const plugin of plugins) {
101 try {
102 plugin.onWillParseMarkdown?.(markdown);
103 } catch (e) {
104 handleError(plugin, 'onWillParseMarkdown', uri, e);
105 }
106 }
107 const tree = parser.parse(markdown);
108
109 const note: Resource = {
110 uri: uri,
111 type: 'note',
112 properties: {},
113 title: '',
114 sections: [],
115 blocks: [],
116 tags: [],
117 aliases: [],
118 links: [],
119 footnotes: [],
120 };
121
122 const localDefinitions: NoteLinkDefinition[] = [];
123
124 for (const plugin of plugins) {
125 try {
126 plugin.onWillVisitTree?.(tree, note);
127 } catch (e) {
128 handleError(plugin, 'onWillVisitTree', uri, e);
129 }
130 }
131 visit(tree, node => {
132 if (node.type === 'yaml') {

Callers 15

withMcpServerFunction · 0.90
activateFunction · 0.90
bootstrapMethod · 0.90
createWorkspaceFunction · 0.90

Calls 15

hashFunction · 0.90
isSomeFunction · 0.90
handleErrorFunction · 0.85
astPositionToFoamRangeFunction · 0.85
pushMethod · 0.80
findMethod · 0.80
debugMethod · 0.65
toStringMethod · 0.65
warnMethod · 0.65
forEachMethod · 0.65
filterMethod · 0.65
matchMethod · 0.65

Tested by 2

createWorkspaceFunction · 0.72
setupFoamEngineFunction · 0.72