gristlabs_grist-core/app/client/ui/DocTutorialRenderer.ts
George Gevoian b15ae98349 (core) Fix browser history bug with tutorials
Summary:
History wasn't being replaced in some cases, which was
causing a bug where trying to leave a tutorial fork via the
browser's back button would navigate back to the trunk, and
trigger forking again. This effectively made it impossible to
leave a tutorial.

Also adds support for specifying custom CSS classes for
tutorial Markdown images.

Test Plan: Browser test.

Reviewers: JakubSerafin

Reviewed By: JakubSerafin

Differential Revision: https://phab.getgrist.com/D3866
2023-04-19 00:22:42 -04:00

23 lines
722 B
TypeScript

import {marked} from 'marked';
export const renderer = new marked.Renderer();
renderer.image = (href: string | null, title: string | null, _text: string) => {
let classes = 'doc-tutorial-popup-thumbnail';
const hash = href?.split('#')?.[1];
if (hash) {
const extraClass = `doc-tutorial-popup-thumbnail-${hash}`;
classes += ` ${extraClass}`;
}
return `<div class="${classes}">
<img src="${href}" title="${title ?? ''}" />
<div class="doc-tutorial-popup-thumbnail-icon-wrapper">
<div class="doc-tutorial-popup-thumbnail-icon"></div>
</div>
</div>`;
};
renderer.link = (href: string | null, _title: string | null, text: string) => {
return `<a href="${href}" target="_blank">${text}</a>`;
};