Skip to content

Commit

Permalink
Updating dependencies (#6679)
Browse files Browse the repository at this point in the history
* Updating dependencies

* test code
  • Loading branch information
riknoll committed Mar 9, 2020
1 parent 9f66138 commit aa58b88
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ file('built/web/main.js', ["built/web/pxtapp.js", "built/webapp/src/app.js"], {

ju.catFiles('built/web/pxtapp.js', [
"node_modules/lzma/src/lzma_worker-min.js",
"node_modules/dompurify/dist/purify.min.js",
"built/web/pxtlib.js",
"built/web/pxtwinrt.js",
"built/web/pxteditor.js",
Expand All @@ -452,13 +453,15 @@ ju.catFiles('built/web/pxtworker.js', [
"built/web/typescript.js",
"node_modules/fuse.js/dist/fuse.min.js",
"node_modules/lzma/src/lzma_worker-min.js",
"node_modules/dompurify/dist/purify.min.js",
"built/web/pxtlib.js",
"built/web/pxtcompiler.js"
], `"use strict";`, ["built/webapp/src/app.js"]);

ju.catFiles('built/web/pxtembed.js', [
"built/web/typescript.js",
"node_modules/lzma/src/lzma_worker-min.js",
"node_modules/dompurify/dist/purify.min.js",
"built/web/pxtlib.js",
"built/web/pxtcompiler.js",
"built/web/pxtblockly.js",
Expand Down
2 changes: 2 additions & 0 deletions cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import * as gitfs from './gitfs';

const rimraf: (f: string, opts: any, cb: (err: any, res: any) => void) => void = require('rimraf');

pxt.docs.requireDOMSanitizer = () => require("sanitize-html");

let forceCloudBuild = process.env["KS_FORCE_CLOUD"] !== "no";
let forceLocalBuild = process.env["PXT_FORCE_LOCAL"] === "yes"

Expand Down
3 changes: 3 additions & 0 deletions localtypings/dompurify.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
declare namespace DOMPurify {
function sanitize(dirty: string): string;
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@
"rtlcss": "2.2.1",
"cssnano": "3.10.0",
"less": "2.7.3",
"semantic-ui-less": "2.2.14"
"semantic-ui-less": "2.2.14",
"dompurify": "2.0.8",
"sanitize-html": "1.22.0"
},
"lazyDependencies": {
"keytar": "4.2.1",
Expand Down
14 changes: 13 additions & 1 deletion pxtlib/docsrender.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// <reference path='../localtypings/pxtarget.d.ts' />
/// <reference path='../localtypings/dompurify.d.ts' />
/// <reference path="commonutil.ts"/>

namespace pxt.docs {
Expand Down Expand Up @@ -80,6 +81,12 @@ namespace pxt.docs {
return require("marked") as typeof marked;
}

export let requireDOMSanitizer = () => {
if (typeof DOMPurify !== "undefined") return DOMPurify.sanitize;
if (typeof require === "undefined") return undefined;
return (require("DOMPurify") as typeof DOMPurify).sanitize;
}

export interface RenderData {
html: string;
theme: AppTheme;
Expand Down Expand Up @@ -469,13 +476,16 @@ namespace pxt.docs {
const html = linkRenderer.call(renderer, href, title, text);
return html.replace(/^<a /, `<a ${target ? `target="${target}"` : ''} rel="nofollow noopener" `);
};

let sanitizer = requireDOMSanitizer();
markedInstance.setOptions({
renderer: renderer,
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: true,
sanitizer: sanitizer,
smartLists: true,
smartypants: true
});
Expand Down Expand Up @@ -789,13 +799,15 @@ ${opts.repo.name.replace(/^pxt-/, '')}=github:${opts.repo.fullName}#${opts.repo.
return null

const markedInstance = pxt.docs.requireMarked();
const sanitizer = requireDOMSanitizer();
const options = {
renderer: new markedInstance.Renderer(),
gfm: true,
tables: false,
breaks: false,
pedantic: false,
sanitize: false,
sanitize: true,
sanitizer: sanitizer,
smartLists: false,
smartypants: false
};
Expand Down
4 changes: 3 additions & 1 deletion webapp/src/marked.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// <reference path='../../localtypings/dompurify.d.ts' />

import * as React from "react";
import * as ReactDOM from "react-dom";
Expand Down Expand Up @@ -118,7 +119,8 @@ export class MarkedContent extends data.Component<MarkedContentProps, MarkedCont
// Set markdown options
marked.setOptions({
renderer: renderer,
sanitize: true
sanitize: true,
sanitizer: pxt.docs.requireDOMSanitizer()
})

// Render the markdown and add it to the content div
Expand Down

0 comments on commit aa58b88

Please sign in to comment.