Merge branch 'main' into dev/t-andreamah/markdown-static-preview-scroll-state

This commit is contained in:
Andrea Mah
2021-05-19 17:25:56 -06:00
62 changed files with 1296 additions and 718 deletions

View File

@@ -5,35 +5,23 @@
const MarkdownIt = require('markdown-it');
export async function activate(ctx: {
dependencies: ReadonlyArray<{ entrypoint: string }>
}) {
export function activate() {
let markdownIt = new MarkdownIt({
html: true
});
// Should we load the deps before this point?
// Also could we await inside `renderMarkup`?
await Promise.all(ctx.dependencies.map(async (dep) => {
try {
const api = await import(dep.entrypoint);
if (api?.extendMarkdownIt) {
markdownIt = api.extendMarkdownIt(markdownIt);
}
} catch (e) {
console.error('Could not load markdown entryPoint', e);
}
}));
return {
renderMarkup: (context: { element: HTMLElement, content: string }) => {
const rendered = markdownIt.render(context.content);
renderCell: (_id: string, context: { element: HTMLElement, value: string }) => {
const rendered = markdownIt.render(context.value);
context.element.innerHTML = rendered;
// Insert styles into markdown preview shadow dom so that they are applied
for (const markdownStyleNode of document.getElementsByClassName('markdown-style')) {
context.element.insertAdjacentElement('beforebegin', markdownStyleNode.cloneNode(true) as Element);
}
},
extendMarkdownIt: (f: (md: typeof markdownIt) => void) => {
f(markdownIt);
}
};
}