Skip to content

Commit 391b30b

Browse files
author
Guillaume Olivrin (Lab)
committed
Enabling Markdown for GristDocTour
1 parent 98de676 commit 391b30b

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

app/client/ui/DocTour.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import {IconList, IconName} from 'app/client/ui2018/IconList';
1010
import {DocData} from 'app/common/DocData';
1111
import {dom} from 'grainjs';
1212
import sortBy = require('lodash/sortBy');
13+
import {marked} from "marked";
14+
import {renderer} from 'app/client/ui/DocTutorialRenderer';
15+
import {sanitizeTutorialHTML} from "./sanitizeHTML";
16+
1317

1418
const t = makeT('DocTour');
1519

@@ -44,7 +48,17 @@ async function makeDocTour(docData: DocData, docComm: DocComm): Promise<IOnBoard
4448
return String(tableData.getValue(rowId, colId) || "");
4549
}
4650
const title = getValue("Title");
47-
let body: HTMLElement | string = getValue("Body");
51+
52+
const bodyHtmlContent = sanitizeTutorialHTML(marked.parse(getValue("Body"), {
53+
async: false, renderer
54+
}));
55+
const element = document.createElement('div');
56+
element.innerHTML = bodyHtmlContent;
57+
58+
59+
let body: HTMLElement = element;
60+
61+
4862
const linkText = getValue("Link_Text");
4963
const linkUrl = getValue("Link_URL");
5064
const linkIcon = getValue("Link_Icon") as IconName;

app/client/ui/DocTourRenderer.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {marked} from 'marked';
2+
3+
export const renderer = new marked.Renderer();
4+
5+
renderer.link = ({href, text}) => {
6+
return `<a href="${href}" target="_blank">${text}</a>`;
7+
};

0 commit comments

Comments
 (0)