-
-
Notifications
You must be signed in to change notification settings - Fork 479
Enabling Markdown for GristDocTour #1653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -10,6 +10,9 @@ import {IconList, IconName} from 'app/client/ui2018/IconList'; | |||
import {DocData} from 'app/common/DocData'; | ||||
import {dom} from 'grainjs'; | ||||
import sortBy = require('lodash/sortBy'); | ||||
import {marked} from "marked"; | ||||
import {renderer} from 'app/client/ui/DocTutorialRenderer'; | ||||
import {sanitizeTourHTML} from "app/client/ui/sanitizeHTML"; | ||||
|
||||
const t = makeT('DocTour'); | ||||
|
||||
|
@@ -44,17 +47,22 @@ async function makeDocTour(docData: DocData, docComm: DocComm): Promise<IOnBoard | |||
return String(tableData.getValue(rowId, colId) || ""); | ||||
} | ||||
const title = getValue("Title"); | ||||
let body: HTMLElement | string = getValue("Body"); | ||||
const bodyValue = getValue("Body"); | ||||
|
||||
if (!title && !(bodyValue.trim()) ) { | ||||
return null; | ||||
} | ||||
//const bodyHtmlContent | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
const element = sanitizeTourHTML(marked.parse(bodyValue, { | ||||
async: false, renderer | ||||
})); | ||||
|
||||
const linkText = getValue("Link_Text"); | ||||
const linkUrl = getValue("Link_URL"); | ||||
const linkIcon = getValue("Link_Icon") as IconName; | ||||
const locationValue = getValue("Location"); | ||||
let placement = getValue("Placement"); | ||||
|
||||
if (!(title || body)) { | ||||
return null; | ||||
} | ||||
|
||||
const urlState = sameDocumentUrlState(locationValue); | ||||
if (isNarrowScreen() || !placements.includes(placement as Placement)) { | ||||
placement = "auto"; | ||||
|
@@ -67,10 +75,12 @@ async function makeDocTour(docData: DocData, docComm: DocComm): Promise<IOnBoard | |||
validLinkUrl = false; | ||||
} | ||||
|
||||
let body: HTMLElement = dom('div', element); | ||||
|
||||
if (validLinkUrl && linkText) { | ||||
body = dom( | ||||
'div', | ||||
dom('p', body), | ||||
body, | ||||
dom('p', | ||||
cssButtons(cssLinkBtn( | ||||
IconList.includes(linkIcon) ? cssLinkIcon(linkIcon) : null, | ||||
|
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,8 @@ | ||||
import {constructUrl} from 'app/client/models/gristUrlState'; | ||||
import {gristIconLink} from 'app/client/ui2018/links'; | ||||
import {marked} from 'marked'; | ||||
|
||||
export const renderer = new marked.Renderer(); | ||||
|
||||
renderer.link = ({href, text}) => | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that the default What do you think about reusing the renderer from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used ALLOWED_TAGS with marked.Renderer in app/client/ui/sanitizeHTML.ts to limit abuse and only allow those HTML elements that have been tested (+ table).
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ogui11aume, what if we disallowed HTML for the time being? renderer.html = ({raw}) => escape(raw); Would there be an immediate need for tours to support arbitrary HTML? Having a robust and shared sanitization approach across different UI components like tutorials, tours, etc. seems desirable, but could perhaps be reconciled later. (Tutorials in particular should probably also disallow HTML outside of the specific iframe that's permitted, but that's unrelated to your proposed changes.) |
||||
gristIconLink(constructUrl(href), text).outerHTML; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DocTourRenderer
isn't being imported here.