mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-06-22 00:38:38 +00:00
@@ -86,8 +86,8 @@ export function tokenizeCustomMarkdown(text) {
|
||||
if(/\~/.test(lineText)) {
|
||||
const strikethroughRegex = /~(?!\s)(.+?)(?<!\s)~/g;
|
||||
|
||||
let match = strikethroughRegex.exec(lineText);
|
||||
let type = customTags.strikethrough;
|
||||
const match = strikethroughRegex.exec(lineText);
|
||||
const type = customTags.strikethrough;
|
||||
|
||||
if(match) {
|
||||
tokens.push({
|
||||
|
||||
@@ -3,15 +3,15 @@ import { keymap } from '@codemirror/view';
|
||||
import { undo, redo, indentMore, deleteLine } from '@codemirror/commands';
|
||||
import { Prec } from '@codemirror/state';
|
||||
|
||||
const insertTab = (view) => {
|
||||
const { from, to } = view.state.selection.main;
|
||||
const insertTab = (view)=>{
|
||||
const { from, to } = view.state.selection.main;
|
||||
|
||||
view.dispatch({
|
||||
changes: { from, to, insert: ' ' },
|
||||
selection: { anchor: from + 2 }
|
||||
});
|
||||
view.dispatch({
|
||||
changes : { from, to, insert: ' ' },
|
||||
selection : { anchor: from + 2 }
|
||||
});
|
||||
|
||||
return true;
|
||||
return true;
|
||||
};
|
||||
|
||||
const indentLess = (view)=>{
|
||||
@@ -28,20 +28,18 @@ const indentLess = (view)=>{
|
||||
return true;
|
||||
};
|
||||
|
||||
const wrapSelection = (prefix, suffix) => (view) => {
|
||||
const wrapSelection = (prefix, suffix)=>(view)=>{
|
||||
const changes = [];
|
||||
|
||||
for(const range of view.state.selection.ranges) {
|
||||
for (const range of view.state.selection.ranges) {
|
||||
const { from, to } = range;
|
||||
const selected = view.state.doc.sliceString(from, to);
|
||||
|
||||
let text;
|
||||
|
||||
if(from === to) { text = prefix + suffix }
|
||||
else if(selected.startsWith(prefix) && selected.endsWith(suffix)) {
|
||||
if(from === to) { text = prefix + suffix; } else if(selected.startsWith(prefix) && selected.endsWith(suffix)) {
|
||||
text = selected.slice(prefix.length, -suffix.length);
|
||||
}
|
||||
else {text = `${prefix}${selected}${suffix}`}
|
||||
} else {text = `${prefix}${selected}${suffix}`;}
|
||||
|
||||
changes.push({ from, to, insert: text });
|
||||
}
|
||||
@@ -53,21 +51,21 @@ const wrapSelection = (prefix, suffix) => (view) => {
|
||||
return true;
|
||||
};
|
||||
|
||||
const makeNbsp = (view) => {
|
||||
const { from } = view.state.selection.main;
|
||||
const makeNbsp = (view)=>{
|
||||
const { from } = view.state.selection.main;
|
||||
|
||||
const prev2 = from >= 2
|
||||
? view.state.doc.sliceString(from - 2, from)
|
||||
: '';
|
||||
const prev2 = from >= 2
|
||||
? view.state.doc.sliceString(from - 2, from)
|
||||
: '';
|
||||
|
||||
const insert = (prev2 === ':>' || prev2 === '>>') ? '>' : ':>';
|
||||
const insert = (prev2 === ':>' || prev2 === '>>') ? '>' : ':>';
|
||||
|
||||
view.dispatch({
|
||||
changes : { from, to: from, insert },
|
||||
selection : { anchor: from + insert.length },
|
||||
});
|
||||
view.dispatch({
|
||||
changes : { from, to: from, insert },
|
||||
selection : { anchor: from + insert.length },
|
||||
});
|
||||
|
||||
return true;
|
||||
return true;
|
||||
};
|
||||
|
||||
const makeSpace = (view)=>{
|
||||
|
||||
@@ -30,18 +30,17 @@ import cm5Themes from 'codemirror-5-themes';
|
||||
const themes = { default: defaultCM5Theme, ...cm5Themes, darkbrewery };
|
||||
|
||||
const themeNames = Object.entries(themes)
|
||||
.filter(([name, value]) =>
|
||||
Array.isArray(value) &&
|
||||
.filter(([name, value])=>Array.isArray(value) &&
|
||||
!name.endsWith('Init') &&
|
||||
!name.endsWith('Style')
|
||||
)
|
||||
.map(([name]) => name);
|
||||
.map(([name])=>name);
|
||||
|
||||
const EditorThemes = [
|
||||
'default',
|
||||
...themeNames
|
||||
.filter(name => name !== 'default')
|
||||
.sort((a, b) => a.localeCompare(b))
|
||||
'default',
|
||||
...themeNames
|
||||
.filter((name)=>name !== 'default')
|
||||
.sort((a, b)=>a.localeCompare(b))
|
||||
];
|
||||
|
||||
const execute = function(val, props){
|
||||
|
||||
@@ -32,20 +32,20 @@ const isStaticTheme = (renderer, themeName)=>{
|
||||
// };
|
||||
|
||||
|
||||
const migrateSystemsToTags = (brew) => {
|
||||
if (!('systems' in brew)) return brew;
|
||||
const migrateSystemsToTags = (brew)=>{
|
||||
if(!('systems' in brew)) return brew;
|
||||
|
||||
if (!Array.isArray(brew.systems) || brew.systems.length === 0) {
|
||||
if(!Array.isArray(brew.systems) || brew.systems.length === 0) {
|
||||
brew.systems = undefined;
|
||||
return brew;
|
||||
}
|
||||
const systemMap = {
|
||||
'5e': 'system:D&D 5e',
|
||||
'4e': 'system:D&D 4e',
|
||||
'3.5e': 'system:D&D 3.5e',
|
||||
'Pathfinder': 'system:Pathfinder 2e'
|
||||
'5e' : 'system:D&D 5e',
|
||||
'4e' : 'system:D&D 4e',
|
||||
'3.5e' : 'system:D&D 3.5e',
|
||||
'Pathfinder' : 'system:Pathfinder 2e'
|
||||
};
|
||||
const systemTags = brew.systems.map(s => systemMap[s]);
|
||||
const systemTags = brew.systems.map((s)=>systemMap[s]);
|
||||
brew.tags = _.uniq([...(brew.tags || []), ...systemTags]);
|
||||
|
||||
brew.systems = undefined;
|
||||
@@ -188,7 +188,7 @@ const api = {
|
||||
stub.renderer = stub.renderer || undefined; // Clear empty strings
|
||||
stub = _.defaults(stub, DEFAULT_BREW_LOAD); // Fill in blank fields
|
||||
|
||||
|
||||
|
||||
|
||||
const fixedStub = migrateSystemsToTags(stub);
|
||||
req.brew = fixedStub;
|
||||
|
||||
@@ -15,7 +15,7 @@ const HomebrewSchema = mongoose.Schema({
|
||||
|
||||
description : { type: String, default: '' },
|
||||
tags : { type: [String], index: true },
|
||||
systems : { type: [String], default: undefined },
|
||||
systems : { type: [String], default: undefined },
|
||||
lang : { type: String, default: 'en', index: true },
|
||||
renderer : { type: String, default: '', index: true },
|
||||
authors : { type: [String], index: true },
|
||||
|
||||
@@ -16,17 +16,17 @@ export default {
|
||||
edge : (side = 'bottom')=>{
|
||||
const styles = ()=>{
|
||||
switch (side) {
|
||||
case 'bottom':
|
||||
return `{width:100%,bottom:0%}`
|
||||
break;
|
||||
case 'top':
|
||||
return `{width:100%,top:0%}`
|
||||
break;
|
||||
default:
|
||||
return `{height:100%}`
|
||||
break;
|
||||
case 'bottom':
|
||||
return `{width:100%,bottom:0%}`;
|
||||
break;
|
||||
case 'top':
|
||||
return `{width:100%,top:0%}`;
|
||||
break;
|
||||
default:
|
||||
return `{height:100%}`;
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const rotation = {
|
||||
'bottom' : 0,
|
||||
|
||||
@@ -93,7 +93,7 @@ export default EditorView.theme({
|
||||
'.cm-strong' : { color: '#309dd2', fontWeight: 'bold' },
|
||||
'.cm-em' : { fontStyle: 'italic' },
|
||||
'.cm-keyword' : { color: '#fff' },
|
||||
'.cm-atom, .cm-value, .cm-color' : { color: '#c1939a' },
|
||||
'.cm-atom, .cm-value, .cm-color' : { color: '#c1939a' },
|
||||
'.cm-number' : { color: '#2986cc' },
|
||||
'.cm-def' : { color: '#2986cc' },
|
||||
'.cm-list' : { color: '#3cbf30' },
|
||||
|
||||
Reference in New Issue
Block a user