mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-09-28 04:32:58 +00:00
fit in 300 lines
This commit is contained in:
@@ -53,7 +53,6 @@ export async function formatCSS(view) {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error formatting css: ', err);
|
console.error('Error formatting css: ', err);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,7 +98,6 @@ const wrapSelection = (prefix, suffix)=>(view)=>forEachSelection(view, (state, r
|
|||||||
}
|
}
|
||||||
|
|
||||||
const hasWrapper = selected.startsWith(prefix) && selected.endsWith(suffix);
|
const hasWrapper = selected.startsWith(prefix) && selected.endsWith(suffix);
|
||||||
|
|
||||||
if(hasWrapper) {
|
if(hasWrapper) {
|
||||||
return {
|
return {
|
||||||
changes : [
|
changes : [
|
||||||
@@ -119,18 +117,10 @@ const wrapSelection = (prefix, suffix)=>(view)=>forEachSelection(view, (state, r
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
changes : {
|
changes : { from, to, insert: prefix + selected + suffix },
|
||||||
from,
|
range : EditorSelection.range(from, to + prefix.length + suffix.length)
|
||||||
to,
|
|
||||||
insert : prefix + selected + suffix
|
|
||||||
},
|
|
||||||
range : EditorSelection.range(
|
|
||||||
from,
|
|
||||||
to + prefix.length + suffix.length
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
const makeNbsp = (view)=>forEachSelection(view, (state, range)=>{
|
const makeNbsp = (view)=>forEachSelection(view, (state, range)=>{
|
||||||
const { from, to } = range;
|
const { from, to } = range;
|
||||||
@@ -177,7 +167,6 @@ const makeLink = (view)=>forEachSelection(view, (state, range)=>{
|
|||||||
|
|
||||||
// If the selection is already a Markdown link, unwrap it
|
// If the selection is already a Markdown link, unwrap it
|
||||||
const existingLink = /^\[(.*)\]\((.*)\)$/.exec(selected);
|
const existingLink = /^\[(.*)\]\((.*)\)$/.exec(selected);
|
||||||
|
|
||||||
if(existingLink) {
|
if(existingLink) {
|
||||||
const [, text, url] = existingLink;
|
const [, text, url] = existingLink;
|
||||||
const insert = `${text} ${url}`;
|
const insert = `${text} ${url}`;
|
||||||
@@ -194,7 +183,6 @@ const makeLink = (view)=>forEachSelection(view, (state, range)=>{
|
|||||||
const isUrl =
|
const isUrl =
|
||||||
/^(https?:\/\/|www\.)\S+$/i.test(selected) ||
|
/^(https?:\/\/|www\.)\S+$/i.test(selected) ||
|
||||||
/^[a-z0-9-]+(\.[a-z0-9-]+)+([/?#]\S*)?$/i.test(selected);
|
/^[a-z0-9-]+(\.[a-z0-9-]+)+([/?#]\S*)?$/i.test(selected);
|
||||||
|
|
||||||
if(isUrl) {
|
if(isUrl) {
|
||||||
const domain = selected
|
const domain = selected
|
||||||
.replace(/^https?:\/\//i, '')
|
.replace(/^https?:\/\//i, '')
|
||||||
@@ -215,8 +203,7 @@ const makeLink = (view)=>forEachSelection(view, (state, range)=>{
|
|||||||
changes : { from, to, insert },
|
changes : { from, to, insert },
|
||||||
range : EditorSelection.range(from, from + insert.length),
|
range : EditorSelection.range(from, from + insert.length),
|
||||||
};
|
};
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
const makeList = (prefix)=>(view)=>forEachSelection(view, (state, selectionRange)=>{
|
const makeList = (prefix)=>(view)=>forEachSelection(view, (state, selectionRange)=>{
|
||||||
const { from, to } = selectionRange;
|
const { from, to } = selectionRange;
|
||||||
@@ -240,7 +227,6 @@ const makeList = (prefix)=>(view)=>forEachSelection(view, (state, selectionRange
|
|||||||
insert : shouldRemovePrefix ? '' : prefix,
|
insert : shouldRemovePrefix ? '' : prefix,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
const changeSet = ChangeSet.of(changes, state.doc.length);
|
const changeSet = ChangeSet.of(changes, state.doc.length);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user