0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-08-06 08:57:38 +00:00

Merge remote-tracking branch 'upstream/master'

This commit is contained in:
Gazook89
2026-04-30 21:25:21 -05:00
8 changed files with 67 additions and 145 deletions
@@ -137,14 +137,14 @@ export function tokenizeCustomMarkdown(text) {
for (let i = lineNumber + 1; i < lines.length; i++) { for (let i = lineNumber + 1; i < lines.length; i++) {
const nextLine = lines[i]; const nextLine = lines[i];
const onlyColonsMatch = /^:*$/.test(nextLine); const onlyColonsMatch = /^:*$/.test(nextLine);
const defMatch = /^(::)(.*\S.*)?\s*$/.exec(nextLine); const defMatch = /^(::)(.+)$/.exec(nextLine);
if(!onlyColonsMatch && defMatch) { if(!onlyColonsMatch && defMatch) {
defs.push({ colons: defMatch[1], desc: defMatch[2], line: i }); defs.push({ colons: defMatch[1], desc: defMatch[2], line: i });
endLine = i; endLine = i;
} else break; } else break;
} }
if(defs.length > 0) { if(defs.length > 0 && lineText.trim().length > 0) {
tokens.push({ tokens.push({
line : startLine, line : startLine,
type : customTags.definitionList, type : customTags.definitionList,
@@ -175,7 +175,7 @@ export function tokenizeCustomMarkdown(text) {
line : d.line, line : d.line,
type : customTags.definitionDesc, type : customTags.definitionDesc,
from : d.colons.length, from : d.colons.length,
to : d.colons.length + d.desc.length, to : d.colons.length + d.desc?.length,
}); });
}); });
} }
+37 -134
View File
@@ -17,125 +17,28 @@ const indentLess = (view)=>{
return true; return true;
}; };
const makeBold = (view)=>{ const wrapSelection = (prefix, suffix) => (view) => {
const { from, to } = view.state.selection.main; const { from, to } = view.state.selection.main;
const selected = view.state.doc.sliceString(from, to); const selected = view.state.doc.sliceString(from, to);
let text, cursor; let text, selection;
if(from === to) { if(from === to) {
text = '****'; text = prefix + suffix;
cursor = from + 2; selection = { anchor: from + prefix.length, head: from + prefix.length };
} else if(selected.startsWith('**') && selected.endsWith('**')) { }
text = selected.slice(2, -2); else if(selected.startsWith(prefix) && selected.endsWith(suffix)) {
cursor = from + text.length; text = selected.slice(prefix.length, -suffix.length);
} else { selection = { anchor: from, head: from + text.length };
text = `**${selected}**`; }
cursor = from + text.length; else {
text = `${prefix}${selected}${suffix}`;
selection = { anchor: from, head: from + text.length };
} }
view.dispatch({ view.dispatch({
changes : { from, to, insert: text }, changes : { from, to, insert: text },
selection : { anchor: cursor }, selection
});
return true;
};
const makeItalic = (view)=>{
const { from, to } = view.state.selection.main;
const selected = view.state.doc.sliceString(from, to);
let text, cursor;
if(from === to) {
text = '**';
cursor = from + 1;
} else if(selected.startsWith('*') && selected.endsWith('*')) {
text = selected.slice(2, -2);
cursor = from + text.length;
} else {
text = `*${selected}*`;
cursor = from + text.length;
}
view.dispatch({
changes : { from, to, insert: text },
selection : { anchor: cursor },
});
return true;
};
const makeUnderline = (view)=>{
const { from, to } = view.state.selection.main;
const selected = view.state.doc.sliceString(from, to);
let text, cursor;
if(from === to) {
text = '<u></u>';
cursor = from + 3;
} else if(selected.startsWith('<u>') && selected.endsWith('</u>')) {
text = selected.slice(3, -4);
cursor = from + text.length;
} else {
text = `<u>${selected}</u>`;
cursor = from + text.length;
}
view.dispatch({
changes : { from, to, insert: text },
selection : { anchor: cursor },
});
return true;
};
const makeSuper = (view)=>{
const { from, to } = view.state.selection.main;
const selected = view.state.doc.sliceString(from, to);
let text, cursor;
if(from === to) {
text = '^^';
cursor = from + 1;
} else if(selected.startsWith('^') && selected.endsWith('^')) {
text = selected.slice(1, -1);
cursor = from + text.length;
} else {
text = `^${selected}^`;
cursor = from + text.length;
}
view.dispatch({
changes : { from, to, insert: text },
selection : { anchor: cursor },
});
return true;
};
const makeSub = (view)=>{
const { from, to } = view.state.selection.main;
const selected = view.state.doc.sliceString(from, to);
let text, cursor;
if(from === to) {
text = '^^^^';
cursor = from + 2;
} else if(selected.startsWith('^^') && selected.endsWith('^^')) {
text = selected.slice(2, -2);
cursor = from + text.length;
} else {
text = `^^${selected}^^`;
cursor = from + text.length;
}
view.dispatch({
changes : { from, to, insert: text },
selection : { anchor: cursor },
}); });
return true; return true;
@@ -151,8 +54,8 @@ const makeNbsp = (view) => {
const insert = (prev2 === ':>' || prev2 === '>>') ? '>' : ':>'; const insert = (prev2 === ':>' || prev2 === '>>') ? '>' : ':>';
view.dispatch({ view.dispatch({
changes: { from, to: from, insert }, changes : { from, to: from, insert },
selection: { anchor: from + insert.length }, selection : { anchor: from + insert.length },
}); });
return true; return true;
@@ -268,27 +171,27 @@ export const generalKeymap = Prec.high(keymap.of([
export const markdownKeymap = Prec.highest(keymap.of([ export const markdownKeymap = Prec.highest(keymap.of([
//{ key: 'Shift-Tab', run: indentMore }, //{ key: 'Shift-Tab', run: indentMore },
{ key: 'Shift-Tab', run: indentLess }, { key: 'Shift-Tab', run: indentLess },
{ key: 'Mod-b', run: makeBold }, { key: 'Mod-b', run: wrapSelection('**', '**') }, // makeBold
{ key: 'Mod-i', run: makeItalic }, { key: 'Mod-i', run: wrapSelection('*', '*') }, // makeItalic
{ key: 'Mod-u', run: makeUnderline }, { key: 'Mod-u', run: wrapSelection('<u>', '</u>') }, // makeUnderline
{ key: 'Shift-Mod-=', run: makeSuper }, { key: 'Shift-Mod-=', run: wrapSelection('^', '^') }, // makeSuper
{ key: 'Mod-=', run: makeSub }, { key: 'Mod-=', run: wrapSelection('^^', '^^') }, // makeSub
{ key: 'Mod-.', run: makeNbsp }, { key: 'Mod-.', run: makeNbsp },
{ key: 'Shift-Mod-.', run: makeSpace }, { key: 'Shift-Mod-.', run: makeSpace },
{ key: 'Shift-Mod-,', run: removeSpace }, { key: 'Shift-Mod-,', run: removeSpace },
{ key: 'Mod-m', run: makeSpan }, { key: 'Mod-m', run: makeSpan },
{ key: 'Shift-Mod-m', run: makeDiv }, { key: 'Shift-Mod-m', run: makeDiv },
{ key: 'Mod-/', run: makeComment }, { key: 'Mod-/', run: makeComment },
{ key: 'Mod-k', run: makeLink }, { key: 'Mod-k', run: makeLink },
{ key: 'Mod-l', run: makeList('UL') }, { key: 'Mod-l', run: makeList('UL') },
{ key: 'Shift-Mod-l', run: makeList('OL') }, { key: 'Shift-Mod-l', run: makeList('OL') },
{ key: 'Shift-Mod-1', run: makeHeader(1) }, { key: 'Shift-Mod-1', run: makeHeader(1) },
{ key: 'Shift-Mod-2', run: makeHeader(2) }, { key: 'Shift-Mod-2', run: makeHeader(2) },
{ key: 'Shift-Mod-3', run: makeHeader(3) }, { key: 'Shift-Mod-3', run: makeHeader(3) },
{ key: 'Shift-Mod-4', run: makeHeader(4) }, { key: 'Shift-Mod-4', run: makeHeader(4) },
{ key: 'Shift-Mod-5', run: makeHeader(5) }, { key: 'Shift-Mod-5', run: makeHeader(5) },
{ key: 'Shift-Mod-6', run: makeHeader(6) }, { key: 'Shift-Mod-6', run: makeHeader(6) },
{ key: 'Mod-Enter', run: newPage },
{ key: 'Shift-Mod-Enter', run: newColumn }, { key: 'Shift-Mod-Enter', run: newColumn },
{ key: 'Mod-Enter', run: newPage },
])); ]));
@@ -170,7 +170,7 @@ const Snippetbar = createReactClass({
this.props.updateEditorTheme(e.target.value); this.props.updateEditorTheme(e.target.value);
this.setState({ this.setState({
showThemeSelector : false, themeSelector : false,
}); });
}, },
+7 -1
View File
@@ -17,7 +17,7 @@ const getRedditLink = (brew)=>{
return `https://www.reddit.com/r/UnearthedArcana/submit?title=${encodeURIComponent(brew.title.toWellFormed())}&text=${encodeURIComponent(text)}`; return `https://www.reddit.com/r/UnearthedArcana/submit?title=${encodeURIComponent(brew.title.toWellFormed())}&text=${encodeURIComponent(text)}`;
}; };
export default ({ brew })=>( export default ({ brew, currentPage })=>(
<Nav.dropdown> <Nav.dropdown>
<Nav.item color='teal' icon='fas fa-share-alt'> <Nav.item color='teal' icon='fas fa-share-alt'>
share share
@@ -28,6 +28,12 @@ export default ({ brew })=>(
<Nav.item color='blue' onClick={()=>{navigator.clipboard.writeText(`${global.config.baseUrl}/share/${getShareId(brew)}`);}}> <Nav.item color='blue' onClick={()=>{navigator.clipboard.writeText(`${global.config.baseUrl}/share/${getShareId(brew)}`);}}>
copy url copy url
</Nav.item> </Nav.item>
{currentPage > 1 &&
<Nav.item
color='blue'
onClick={()=>{navigator.clipboard.writeText(`${global.config.baseUrl}/share/${getShareId(brew)}#p${currentPage}`);}}>
copy url (page {currentPage})
</Nav.item>}
<Nav.item color='blue' href={getRedditLink(brew)} newTab rel='noopener noreferrer'> <Nav.item color='blue' href={getRedditLink(brew)} newTab rel='noopener noreferrer'>
post to reddit post to reddit
</Nav.item> </Nav.item>
+1 -1
View File
@@ -365,7 +365,7 @@ const EditPage = (props)=>{
<PrintNavItem /> <PrintNavItem />
<HelpNavItem /> <HelpNavItem />
<VaultNavItem /> <VaultNavItem />
<ShareNavItem brew={currentBrew} /> <ShareNavItem brew={currentBrew} currentPage={currentBrewRendererPageNum} />
<RecentNavItem brew={currentBrew} storageKey='edit' /> <RecentNavItem brew={currentBrew} storageKey='edit' />
<AccountNavItem/> <AccountNavItem/>
</Nav.section> </Nav.section>
@@ -92,6 +92,19 @@ const SharePage = (props)=>{
<Nav.item color='blue' icon='fas fa-clone' href={`/new/${processShareId()}`}> <Nav.item color='blue' icon='fas fa-clone' href={`/new/${processShareId()}`}>
clone to new clone to new
</Nav.item> </Nav.item>
<Nav.item
color='blue'
icon='fas fa-link'
onClick={()=>{navigator.clipboard.writeText(`${global.config.baseUrl}/share/${processShareId()}`);}}>
copy url
</Nav.item>
{currentBrewRendererPageNum > 1 &&
<Nav.item
color='blue'
icon='fas fa-hashtag'
onClick={()=>{navigator.clipboard.writeText(`${global.config.baseUrl}/share/${processShareId()}#p${currentBrewRendererPageNum}`);}}>
copy url (page {currentBrewRendererPageNum})
</Nav.item>}
</Nav.dropdown> </Nav.dropdown>
</> </>
)} )}
+4 -4
View File
@@ -33,7 +33,7 @@
"@vitejs/plugin-react": "^5.1.2", "@vitejs/plugin-react": "^5.1.2",
"body-parser": "^2.2.0", "body-parser": "^2.2.0",
"classnames": "^2.5.1", "classnames": "^2.5.1",
"codemirror-5-themes": "^1.4.0", "codemirror-5-themes": "^1.5.1",
"cookie-parser": "^1.4.7", "cookie-parser": "^1.4.7",
"core-js": "^3.49.0", "core-js": "^3.49.0",
"cors": "^2.8.5", "cors": "^2.8.5",
@@ -6094,9 +6094,9 @@
} }
}, },
"node_modules/codemirror-5-themes": { "node_modules/codemirror-5-themes": {
"version": "1.4.0", "version": "1.5.1",
"resolved": "https://registry.npmjs.org/codemirror-5-themes/-/codemirror-5-themes-1.4.0.tgz", "resolved": "https://registry.npmjs.org/codemirror-5-themes/-/codemirror-5-themes-1.5.1.tgz",
"integrity": "sha512-3WKAmpTLqcE1MXFLHdNtwQYaxlWZXS69MY79UiNsFpW9KedMkf/vBYBjUAmacDXPKAJjdPSNMGmCPIZi21yoXA==", "integrity": "sha512-vHUyvOYy8yhqCDkps5LwoUFXHXIuKjE32n6EPP5v004fXmkZkrAC9mUsr+anNyOniaixE1W+xwcM4lgnbYfWsQ==",
"dependencies": { "dependencies": {
"@codemirror/view": "^6.41.1" "@codemirror/view": "^6.41.1"
} }
+1 -1
View File
@@ -109,7 +109,7 @@
"@vitejs/plugin-react": "^5.1.2", "@vitejs/plugin-react": "^5.1.2",
"body-parser": "^2.2.0", "body-parser": "^2.2.0",
"classnames": "^2.5.1", "classnames": "^2.5.1",
"codemirror-5-themes": "^1.4.0", "codemirror-5-themes": "^1.5.1",
"cookie-parser": "^1.4.7", "cookie-parser": "^1.4.7",
"core-js": "^3.49.0", "core-js": "^3.49.0",
"cors": "^2.8.5", "cors": "^2.8.5",