mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-02 19:22:47 +00:00
Clean up
This commit is contained in:
@@ -77,22 +77,8 @@ const BrewPage = (props)=>{
|
|||||||
centerObserver.disconnect();
|
centerObserver.disconnect();
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
// Extract any page styles from `\page{cssProp:value}`
|
|
||||||
if(cleanText.match(/^<pagebreak/)) {
|
|
||||||
const injectedTags = Markdown.extractHTMLStyleTags(cleanText.substring(0, cleanText.indexOf('\n')));
|
|
||||||
const styleObject = injectedTags.styles?.split(';').reduce((acc, curr) => {
|
|
||||||
const [key, value] = curr.split(':').map(item => item.trim());
|
|
||||||
const camelCaseKey = key.replace(/-([a-z])/g, g => g[1].toUpperCase()); //Convert to camelCase for React
|
|
||||||
acc[camelCaseKey] = value;
|
|
||||||
return acc;
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
props.style = {...props.style, ...styleObject};
|
|
||||||
cleanText = cleanText.substring(cleanText.indexOf('\n'));
|
|
||||||
}
|
|
||||||
|
|
||||||
return <div className={props.className} id={`p${props.index + 1}`} data-index={props.index} ref={pageRef} style={props.style}>
|
return <div className={props.className} id={`p${props.index + 1}`} data-index={props.index} ref={pageRef} style={props.style} {...props.attributes}>
|
||||||
<div className='columnWrapper' dangerouslySetInnerHTML={{ __html: cleanText }} />
|
<div className='columnWrapper' dangerouslySetInnerHTML={{ __html: cleanText }} />
|
||||||
</div>;
|
</div>;
|
||||||
};
|
};
|
||||||
@@ -187,25 +173,32 @@ const BrewRenderer = (props)=>{
|
|||||||
|
|
||||||
const renderPage = (pageText, index)=>{
|
const renderPage = (pageText, index)=>{
|
||||||
|
|
||||||
const styles = {
|
let styles = {
|
||||||
...(!displayOptions.pageShadows ? { boxShadow: 'none' } : {})
|
...(!displayOptions.pageShadows ? { boxShadow: 'none' } : {})
|
||||||
// Add more conditions as needed
|
// Add more conditions as needed
|
||||||
};
|
};
|
||||||
|
let attributes = {};
|
||||||
|
|
||||||
if(props.renderer == 'legacy') {
|
if(props.renderer == 'legacy') {
|
||||||
const html = MarkdownLegacy.render(pageText);
|
const html = MarkdownLegacy.render(pageText);
|
||||||
|
|
||||||
return <BrewPage className='page phb' index={index} key={index} contents={html} style={styles} onVisibilityChange={handlePageVisibilityChange} />;
|
return <BrewPage className='page phb' index={index} key={index} contents={html} style={styles} onVisibilityChange={handlePageVisibilityChange} />;
|
||||||
} else {
|
} else {
|
||||||
let pageText2 = pageText.substring(0, pageText.indexOf('\n'));
|
if(pageText.startsWith('\\page')) {
|
||||||
let butt = Markdown.marked.lexer(pageText2);
|
let firstLineTokens = Markdown.marked.lexer(pageText.split('\n', 1)[0])[0].tokens;
|
||||||
console.log(butt)
|
let injectedTags = firstLineTokens.find(obj => obj.injectedTags !== undefined)?.injectedTags;
|
||||||
|
if(injectedTags) {
|
||||||
|
styles = {...styles, ...injectedTags.styles};
|
||||||
|
styles = _.mapKeys(styles, (v, k) => _.camelCase(k)); // Convert CSS to camelCase for React
|
||||||
|
attributes = injectedTags.attributes;
|
||||||
|
}
|
||||||
|
pageText = pageText.includes('\n') ? pageText.substring(pageText.indexOf('\n') + 1) : ''; // Remove the \page line
|
||||||
|
}
|
||||||
|
|
||||||
pageText += `\n\n \n\\column\n `; //Artificial column break at page end to emulate column-fill:auto (until `wide` is used, when column-fill:balance will reappear)
|
pageText += `\n\n \n\\column\n `; //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);
|
const html = Markdown.render(pageText, index);
|
||||||
|
|
||||||
return <BrewPage className='page' index={index} key={index} contents={html} style={styles} onVisibilityChange={handlePageVisibilityChange} />;
|
return <BrewPage className='page' index={index} key={index} contents={html} style={styles} attributes={attributes} onVisibilityChange={handlePageVisibilityChange} />;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -527,21 +527,6 @@ const definitionListsMultiLine = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const pageBreak = {
|
|
||||||
name : 'pageBreak',
|
|
||||||
level : 'block',
|
|
||||||
start(src) { return src.match(/\n\\page/m)?.index; }, // Hint to Marked.js to stop and check for a match
|
|
||||||
tokenizer(src) {
|
|
||||||
const regex = /^\\page(?:$|(?={[^\n{}]+}$))/m;
|
|
||||||
const match = regex.exec(src);
|
|
||||||
if(match?.length)
|
|
||||||
return { type : 'pageBreak', raw : match[0] };
|
|
||||||
},
|
|
||||||
renderer(token) {
|
|
||||||
return `<pagebreak></pagebreak>\n`;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
//v=====--------------------< Variable Handling >-------------------=====v// 242 lines
|
//v=====--------------------< Variable Handling >-------------------=====v// 242 lines
|
||||||
const replaceVar = function(input, hoist=false, allowUnresolved=false) {
|
const replaceVar = function(input, hoist=false, allowUnresolved=false) {
|
||||||
const regex = /([!$]?)\[((?!\s*\])(?:\\.|[^\[\]\\])+)\]/g;
|
const regex = /([!$]?)\[((?!\s*\])(?:\\.|[^\[\]\\])+)\]/g;
|
||||||
@@ -810,7 +795,7 @@ const tableTerminators = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
Marked.use(MarkedVariables());
|
Marked.use(MarkedVariables());
|
||||||
Marked.use({ extensions : [pageBreak, justifiedParagraphs, definitionListsMultiLine, definitionListsSingleLine, forcedParagraphBreaks,
|
Marked.use({ extensions : [justifiedParagraphs, definitionListsMultiLine, definitionListsSingleLine, forcedParagraphBreaks,
|
||||||
nonbreakingSpaces, superSubScripts, mustacheSpans, mustacheDivs, mustacheInjectInline] });
|
nonbreakingSpaces, superSubScripts, mustacheSpans, mustacheDivs, mustacheInjectInline] });
|
||||||
Marked.use(mustacheInjectBlock);
|
Marked.use(mustacheInjectBlock);
|
||||||
Marked.use({ renderer: renderer, tokenizer: tokenizer, mangle: false });
|
Marked.use({ renderer: renderer, tokenizer: tokenizer, mangle: false });
|
||||||
@@ -1017,9 +1002,7 @@ const Markdown = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return errors;
|
return errors;
|
||||||
},
|
}
|
||||||
|
|
||||||
extractHTMLStyleTags : extractHTMLStyleTags
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Markdown;
|
export default Markdown;
|
||||||
|
|||||||
Reference in New Issue
Block a user