diff --git a/client/homebrew/brewRenderer/brewRenderer.jsx b/client/homebrew/brewRenderer/brewRenderer.jsx index 6bcfc87ec..7a101e9f9 100644 --- a/client/homebrew/brewRenderer/brewRenderer.jsx +++ b/client/homebrew/brewRenderer/brewRenderer.jsx @@ -39,8 +39,8 @@ const BrewPage = (props)=>{ index : 0, ...props }; - const pageRef = useRef(null); - const cleanText = safeHTML(`${props.contents}\n
\n`); + const pageRef = useRef(null); + const cleanText = safeHTML(props.contents); useEffect(()=>{ if(!pageRef.current) return; diff --git a/client/homebrew/editor/editor.jsx b/client/homebrew/editor/editor.jsx index fc20f2be4..8d331e46e 100644 --- a/client/homebrew/editor/editor.jsx +++ b/client/homebrew/editor/editor.jsx @@ -12,7 +12,7 @@ const MetadataEditor = require('./metadataEditor/metadataEditor.jsx'); const EDITOR_THEME_KEY = 'HOMEBREWERY-EDITOR-THEME'; -const PAGEBREAK_REGEX_V3 = /^(?=\\page(?:break)?(?: *{[^\n]*})?$)/m; +const PAGEBREAK_REGEX_V3 = /^(?=\\page(?:break)?(?: *{[^\n{}]*})?$)/m; const SNIPPETBREAK_REGEX_V3 = /^\\snippet\ .*$/; const DEFAULT_STYLE_TEXT = dedent` /*=======--- Example CSS styling ---=======*/ diff --git a/client/homebrew/navbar/error-navitem.jsx b/client/homebrew/navbar/error-navitem.jsx index ec72ace7d..6d9bec444 100644 --- a/client/homebrew/navbar/error-navitem.jsx +++ b/client/homebrew/navbar/error-navitem.jsx @@ -1,157 +1,138 @@ require('./error-navitem.less'); const React = require('react'); const Nav = require('naturalcrit/nav/nav.jsx'); -const createClass = require('create-react-class'); -const ErrorNavItem = createClass({ - getDefaultProps : function() { - return { - error : '', - parent : null - }; - }, - render : function() { - const clearError = ()=>{ - const state = { - error : null - }; - if(this.props.parent.state.isSaving) { - state.isSaving = false; - } - this.props.parent.setState(state); - }; +const ErrorNavItem = ({error = '', clearError})=>{ + const response = error.response; + const errorCode = error.code + const status = response?.status; + const HBErrorCode = response?.body?.HBErrorCode; + const message = response?.body?.message; - const error = this.props.error; - const response = error.response; - const status = response?.status; - const errorCode = error.code - const HBErrorCode = response?.body?.HBErrorCode; - const message = response?.body?.message; - let errMsg = ''; - try { - errMsg += `${error.toString()}\n\n`; - errMsg += `\`\`\`\n${error.stack}\n`; - errMsg += `${JSON.stringify(response?.error, null, ' ')}\n\`\`\``; - console.log(errMsg); - } catch (e){} - - if(status === 409) { - return - Oops! -
- {message ?? 'Conflict: please refresh to get latest changes'} -
-
; - } - - if(status === 412) { - return - Oops! -
- {message ?? 'Your client is out of date. Please save your changes elsewhere and refresh.'} -
-
; - } - - if(HBErrorCode === '04') { - return - Oops! -
- You are no longer signed in as an author of - this brew! Were you signed out from a different - window? Visit our log in page, then try again! -

- -
- Sign In -
-
-
- Not Now -
-
-
; - } - - if(response?.body?.errors?.[0].reason == 'storageQuotaExceeded') { - return - Oops! -
- Can't save because your Google Drive seems to be full! -
-
; - } - - if(response?.req.url.match(/^\/api.*Google.*$/m)){ - return - Oops! -
- Looks like your Google credentials have - expired! Visit our log in page to sign out - and sign back in with Google, - then try saving again! -

- -
- Sign In -
-
-
- Not Now -
-
-
; - } - - if(HBErrorCode === '09') { - return - Oops! -
- Looks like there was a problem retreiving - the theme, or a theme that it inherits, - for this brew. Verify that brew - {response.body.brewId} still exists! -
-
; - } - - if(HBErrorCode === '10') { - return - Oops! -
- Looks like the brew you have selected - as a theme is not tagged for use as a - theme. Verify that - brew - {response.body.brewId} has the meta:theme tag! -
-
; - } - - if(errorCode === 'ECONNABORTED') { - return - Oops! -
- The request to the server was interrupted or timed out. - This can happen due to a network issue, or if - trying to save a particularly large brew. - Please check your internet connection and try again. -
-
; - } + let errMsg = ''; + try { + errMsg += `${error.toString()}\n\n`; + errMsg += `\`\`\`\n${error.stack}\n`; + errMsg += `${JSON.stringify(response?.error, null, ' ')}\n\`\`\``; + console.log(errMsg); + } catch (e){} + if(status === 409) { return Oops! -
- Looks like there was a problem saving.
- Report the issue - here - . +
+ {message ?? 'Conflict: please refresh to get latest changes'}
; } -}); + + if(status === 412) { + return + Oops! +
+ {message ?? 'Your client is out of date. Please save your changes elsewhere and refresh.'} +
+
; + } + + if(HBErrorCode === '04') { + return + Oops! +
+ You are no longer signed in as an author of + this brew! Were you signed out from a different + window? Visit our log in page, then try again! +

+ +
+ Sign In +
+
+
+ Not Now +
+
+
; + } + + if(response?.body?.errors?.[0].reason == 'storageQuotaExceeded') { + return + Oops! +
+ Can't save because your Google Drive seems to be full! +
+
; + } + + if(response?.req.url.match(/^\/api.*Google.*$/m)){ + return + Oops! +
+ Looks like your Google credentials have + expired! Visit our log in page to sign out + and sign back in with Google, + then try saving again! +

+ +
+ Sign In +
+
+
+ Not Now +
+
+
; + } + + if(HBErrorCode === '09') { + return + Oops! +
+ Looks like there was a problem retreiving + the theme, or a theme that it inherits, + for this brew. Verify that brew + {response.body.brewId} still exists! +
+
; + } + + if(HBErrorCode === '10') { + return + Oops! +
+ Looks like the brew you have selected + as a theme is not tagged for use as a + theme. Verify that + brew + {response.body.brewId} has the meta:theme tag! +
+
; + } + + if(errorCode === 'ECONNABORTED') { + return + Oops! +
+ The request to the server was interrupted or timed out. + This can happen due to a network issue, or if + trying to save a particularly large brew. + Please check your internet connection and try again. +
+
; + } + + return + Oops! +
+ Looks like there was a problem saving.
+ Report the issue + here + . +
+
; +}; module.exports = ErrorNavItem; diff --git a/client/homebrew/pages/editPage/editPage.jsx b/client/homebrew/pages/editPage/editPage.jsx index d1f0ed21c..51196a444 100644 --- a/client/homebrew/pages/editPage/editPage.jsx +++ b/client/homebrew/pages/editPage/editPage.jsx @@ -97,7 +97,7 @@ const EditPage = createClass({ htmlErrors : Markdown.validate(prevState.brew.text) })); - fetchThemeBundle(this, this.props.brew.renderer, this.props.brew.theme); + fetchThemeBundle((err)=>{this.setState({ error: err })}, (theme)=>{this.setState({ themeBundle: theme })}, this.props.brew.renderer, this.props.brew.theme); document.addEventListener('keydown', this.handleControlKeys); }, @@ -173,7 +173,7 @@ const EditPage = createClass({ handleMetaChange : function(metadata, field=undefined){ if(field == 'theme' || field == 'renderer') // Fetch theme bundle only if theme or renderer was changed - fetchThemeBundle(this, metadata.renderer, metadata.theme); + fetchThemeBundle((err)=>{this.setState({ error: err })}, (theme)=>{this.setState({ themeBundle: theme })}, metadata.renderer, metadata.theme); this.setState((prevState)=>({ brew : { @@ -438,6 +438,13 @@ const EditPage = createClass({ return `https://www.reddit.com/r/UnearthedArcana/submit?title=${encodeURIComponent(title.toWellFormed())}&text=${encodeURIComponent(text)}`; }, + clearError : function(){ + setState({ + error : null, + isSaving : false + }) + }, + renderNavbar : function(){ const shareLink = this.processShareId(); @@ -449,7 +456,7 @@ const EditPage = createClass({ {this.renderGoogleDriveIcon()} {this.state.error ? - : + : {this.renderSaveButton()} {this.renderAutoSaveButton()} diff --git a/client/homebrew/pages/homePage/homePage.jsx b/client/homebrew/pages/homePage/homePage.jsx index c8a66e732..ab1eee122 100644 --- a/client/homebrew/pages/homePage/homePage.jsx +++ b/client/homebrew/pages/homePage/homePage.jsx @@ -77,11 +77,18 @@ const HomePage =(props)=>{ })); }; - const renderNavbar = ()=>{ + const clearError = ()=>{ + setState({ + error : null, + isSaving : false + }) + }; + + renderNavbar : function(){ return {this.state.error ? - : + : null } diff --git a/client/homebrew/pages/newPage/newPage.jsx b/client/homebrew/pages/newPage/newPage.jsx index ab7c22541..c24128a93 100644 --- a/client/homebrew/pages/newPage/newPage.jsx +++ b/client/homebrew/pages/newPage/newPage.jsx @@ -80,7 +80,7 @@ const NewPage = createClass({ saveGoogle : (saveStorage == 'GOOGLE-DRIVE' && this.state.saveGoogle) }); - fetchThemeBundle(this, this.props.brew.renderer, this.props.brew.theme); + fetchThemeBundle((err)=>{this.setState({ error: err })}, (theme)=>{this.setState({ themeBundle: theme })}, this.props.brew.renderer, this.props.brew.theme); localStorage.setItem(BREWKEY, brew.text); if(brew.style) @@ -154,7 +154,7 @@ const NewPage = createClass({ handleMetaChange : function(metadata, field=undefined){ if(field == 'theme' || field == 'renderer') // Fetch theme bundle only if theme or renderer was changed - fetchThemeBundle(this, metadata.renderer, metadata.theme); + fetchThemeBundle((err)=>{this.setState({ error: err })}, (theme)=>{this.setState({ themeBundle: theme })}, metadata.renderer, metadata.theme); this.setState((prevState)=>({ brew : { ...prevState.brew, ...metadata }, @@ -211,6 +211,13 @@ const NewPage = createClass({ } }, + clearError : function(){ + setState({ + error : null, + isSaving : false + }) + }, + renderNavbar : function(){ return @@ -220,7 +227,7 @@ const NewPage = createClass({ {this.state.error ? - : + : this.renderSaveButton() } diff --git a/client/homebrew/pages/sharePage/sharePage.jsx b/client/homebrew/pages/sharePage/sharePage.jsx index e9c5540a2..50104a665 100644 --- a/client/homebrew/pages/sharePage/sharePage.jsx +++ b/client/homebrew/pages/sharePage/sharePage.jsx @@ -17,15 +17,11 @@ const { printCurrentBrew, fetchThemeBundle } = require('../../../../shared/helpe const SharePage = (props)=>{ const { brew = DEFAULT_BREW_LOAD, disableMeta = false } = props; - const [state, setState] = useState({ - themeBundle : {}, - currentBrewRendererPageNum : 1, - }); + const [themeBundle, setThemeBundle] = useState({}); + const [currentBrewRendererPageNum, setCurrentBrewRendererPageNum] = useState(1); const handleBrewRendererPageChange = useCallback((pageNumber)=>{ - setState((prevState)=>({ - currentBrewRendererPageNum : pageNumber, - ...prevState })); + setCurrentBrewRendererPageNum(pageNumber); }, []); const handleControlKeys = (e)=>{ @@ -40,11 +36,7 @@ const SharePage = (props)=>{ useEffect(()=>{ document.addEventListener('keydown', handleControlKeys); - fetchThemeBundle( - { setState }, - brew.renderer, - brew.theme - ); + fetchThemeBundle(undefined, setThemeBundle, brew.renderer, brew.theme); return ()=>{ document.removeEventListener('keydown', handleControlKeys); @@ -114,9 +106,9 @@ const SharePage = (props)=>{ lang={brew.lang} renderer={brew.renderer} theme={brew.theme} - themeBundle={state.themeBundle} + themeBundle={themeBundle} onPageChange={handleBrewRendererPageChange} - currentBrewRendererPageNum={state.currentBrewRendererPageNum} + currentBrewRendererPageNum={currentBrewRendererPageNum} allowPrint={true} />
diff --git a/client/homebrew/pages/userPage/userPage.jsx b/client/homebrew/pages/userPage/userPage.jsx index f6fae639d..e4a8b0b4e 100644 --- a/client/homebrew/pages/userPage/userPage.jsx +++ b/client/homebrew/pages/userPage/userPage.jsx @@ -39,10 +39,14 @@ const UserPage = (props)=>{ }] : []) ]; + const clearError = ()=>{ + setError(null); + }; + const navItems = ( - {error && ()} + {error && ()} diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index c07d879ec..78107dcf4 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -185,7 +185,7 @@ const mustacheSpans = { start(src) { return src.match(/{{[^{]/)?.index; }, // Hint to Marked.js to stop and check for a match tokenizer(src, tokens) { const completeSpan = /^{{[^\n]*}}/; // Regex for the complete token - const inlineRegex = /{{(?=((?:[:=](?:"['\w,\-()#%=?. \&\:\!\@\$\^\*\<\>\;\:\[\]\{\}\-\_\+\=]*"|[\w\-()#%.]*)|[^"=':{}\s]*)*))\1 *|}}/g; + const inlineRegex = /{{(?=((?:[:=](?:"['\w,\-+*/()#%=?. ]*"|[\w\-+*/()#%.]*)|[^"=':{}\s]*)*))\1 *|}}/g; const match = completeSpan.exec(src); if(match) { //Find closing delimiter @@ -241,8 +241,8 @@ const mustacheDivs = { level : 'block', start(src) { return src.match(/\n *{{[^{]/m)?.index; }, // Hint to Marked.js to stop and check for a match tokenizer(src, tokens) { - const completeBlock = /^ *{{[^\n]* *\n.*\n *}}/s; // Regex for the complete token - const blockRegex = /^ *{{(?=((?:[:=](?:"['\w,\-()#%=?.\&\:\!\@\$\^\*\<\>\;\:\[\]\{\}\-\_\+\= ]*"|[\w\-()#%. ]*)|[^"=':{}\s]*)*))\1 *$|^ *}}$/gm; + const completeBlock = /^ *{{[^\n}]* *\n.*\n *}}/s; // Regex for the complete token + const blockRegex = /^ *{{(?=((?:[:=](?:"['\w,\-+*/()#%=?. ]*"|[\w\-+*/()#%.]*)|[^"=':{}\s]*)*))\1 *$|^ *}}$/gm; const match = completeBlock.exec(src); if(match) { //Find closing delimiter @@ -297,7 +297,7 @@ const mustacheInjectInline = { level : 'inline', start(src) { return src.match(/ *{[^{\n]/)?.index; }, // Hint to Marked.js to stop and check for a match tokenizer(src, tokens) { - const inlineRegex = /^ *{(?=((?:[:=](?:"['\w,\-()#%=?.\&\:\!\@\$\^\*\<\>\;\:\[\]\{\}\-\_\+\= ]*"|[\w\-()#%.]*)|[^"=':{}\s]*)*))\1}/g; + const inlineRegex = /^ *{(?=((?:[:=](?:"['\w,\-+*/()#%=?. ]*"|[\w\-+*/()#%.]*)|[^"=':{}\s]*)*))\1}/g; const match = inlineRegex.exec(src); if(match) { const lastToken = tokens[tokens.length - 1]; @@ -343,7 +343,7 @@ const mustacheInjectBlock = { level : 'block', start(src) { return src.match(/\n *{[^{\n]/m)?.index; }, // Hint to Marked.js to stop and check for a match tokenizer(src, tokens) { - const inlineRegex = /^ *{(?=((?:[:=](?:"['\w,\-()#%=?.& ]*"|[\w\-()#%.]*)|[^"=':{}\s]*)*))\1}/ym; + const inlineRegex = /^ *{(?=((?:[:=](?:"['\w,\-+*/()#%=?. ]*"|[\w\-+*/()#%.]*)|[^"=':{}\s]*)*))\1}/ym; const match = inlineRegex.exec(src); if(match) { const lastToken = tokens[tokens.length - 1]; @@ -735,17 +735,6 @@ const voidTags = new Set([ 'input', 'keygen', 'link', 'meta', 'param', 'source' ]); -const notInside = (string, stringMatch1, stringMatch2)=> { - const pos1 = string.indexOf(stringMatch1); - const pos2 = string.indexOf(stringMatch2); - - if(((pos1 > 0) && (pos2 == -1)) || - ((pos1 > 0) && (pos2 > 0) && (pos2 > pos1))) { - return true; - } - return false; -}; - const processStyleTags = (string)=>{ //split tags up. quotes can only occur right after : or =. //TODO: can we simplify to just split on commas? @@ -753,7 +742,7 @@ const processStyleTags = (string)=>{ const id = _.remove(tags, (tag)=>tag.startsWith('#')).map((tag)=>tag.slice(1))[0] || null; const classes = _.remove(tags, (tag)=>(!tag.includes(':')) && (!tag.includes('='))).join(' ') || null; - const attributes = _.remove(tags, (tag)=>(notInside(tag, '=', ':'))).map((tag)=>tag.replace(/="?([^"]*)"?/g, '="$1"')) + const attributes = _.remove(tags, (tag)=>(tag.includes('='))).map((tag)=>tag.replace(/="?([^"]*)"?/g, '="$1"')) ?.filter((attr)=>!attr.startsWith('class="') && !attr.startsWith('style="') && !attr.startsWith('id="')) .reduce((obj, attr)=>{ const index = attr.indexOf('=');