0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-30 13:12:40 +00:00

Merge branch 'master' into brew_themes_user_selection

This commit is contained in:
David Bolack
2024-05-20 17:56:21 -05:00
7 changed files with 987 additions and 1655 deletions

View File

@@ -14,7 +14,14 @@ const NotificationPopup = require('./notificationPopup/notificationPopup.jsx');
const Frame = require('react-frame-component').default;
const dedent = require('dedent-tabs').default;
<<<<<<< HEAD
const staticThemes = require('themes/themes.json');
=======
const DOMPurify = require('dompurify');
const purifyConfig = { FORCE_BODY: true, SANITIZE_DOM: false };
const Themes = require('themes/themes.json');
>>>>>>> master
const PAGE_HEIGHT = 1056;
@@ -33,8 +40,9 @@ const BrewPage = (props)=>{
index : 0,
...props
};
const cleanText = DOMPurify.sanitize(props.contents, purifyConfig);
return <div className={props.className} id={`p${props.index + 1}`} >
<div className='columnWrapper' dangerouslySetInnerHTML={{ __html: props.contents }} />
<div className='columnWrapper' dangerouslySetInnerHTML={{ __html: cleanText }} />
</div>;
};
@@ -102,13 +110,6 @@ const BrewRenderer = (props)=>{
return false;
};
const sanitizeScriptTags = (content)=>{
return content
?.replace(/<script/ig, '&lt;script')
.replace(/<\/script>/ig, '&lt;/script&gt;')
|| '';
};
const renderPageInfo = ()=>{
return <div className='pageInfo' ref={mainRef}>
<div>
@@ -128,19 +129,18 @@ const BrewRenderer = (props)=>{
const renderStyle = ()=>{
if(!props.style) return;
const cleanStyle = sanitizeScriptTags(props.style);
const cleanStyle = DOMPurify.sanitize(props.style, purifyConfig);
//return <div style={{ display: 'none' }} dangerouslySetInnerHTML={{ __html: `<style>@layer styleTab {\n${sanitizeScriptTags(props.style)}\n} </style>` }} />;
return <div style={{ display: 'none' }} dangerouslySetInnerHTML={{ __html: `<style> ${cleanStyle} </style>` }} />;
};
const renderPage = (pageText, index)=>{
let cleanPageText = sanitizeScriptTags(pageText);
if(props.renderer == 'legacy') {
const html = MarkdownLegacy.render(cleanPageText);
const html = MarkdownLegacy.render(pageText);
return <BrewPage className='page phb' index={index} key={index} contents={html} />;
} else {
cleanPageText += `\n\n&nbsp;\n\\column\n&nbsp;`; //Artificial column break at page end to emulate column-fill:auto (until `wide` is used, when column-fill:balance will reappear)
const html = Markdown.render(cleanPageText, index);
pageText += `\n\n&nbsp;\n\\column\n&nbsp;`; //Artificial column break at page end to emulate column-fill:auto (until `wide` is used, when column-fill:balance will reappear)
const html = Markdown.render(pageText, index);
return <BrewPage className='page' index={index} key={index} contents={html} />;
}
};
@@ -234,11 +234,11 @@ const BrewRenderer = (props)=>{
<RenderWarnings />
<NotificationPopup />
</div>
<link href={`/css/${blankRendererPath}/Blank`} rel='stylesheet'/>
<link href={`/css/${blankRendererPath}/Blank`} type='text/css' rel='stylesheet'/>
{baseThemePath &&
<link href={staticOrUserParent} rel='stylesheet'/>
<link href={staticOrUserParent} type='text/css' rel='stylesheet'/>
}
<link href={`/css/${rendererPath}${themePath}`} rel='stylesheet'/>
<link href={`/css/${rendererPath}${themePath}`} type='text/css' rel='stylesheet'/>
{/* Apply CSS from Style tab and render pages from Markdown tab */}
{state.isMounted