| 73 | } |
| 74 | |
| 75 | export 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') { |