0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-26 13:52:38 +00:00

Near complete

This commit is contained in:
David Bolack
2023-11-08 00:49:39 -06:00
parent d390d518a3
commit f1ca6eeee2
4 changed files with 71 additions and 31 deletions

View File

@@ -112,6 +112,10 @@ const CodeEditor = createClass({
'Shift-Tab' : this.dedent,
'Ctrl-B' : this.makeBold,
'Cmd-B' : this.makeBold,
'Ctrl-6' : this.makeSuper,
'Cmd-6' : this.makeSuper,
'Ctrl-7' : this.makeSub,
'Cmd-7' : this.makeSub,
'Ctrl-I' : this.makeItalic,
'Cmd-I' : this.makeItalic,
'Ctrl-U' : this.makeUnderline,
@@ -219,6 +223,25 @@ const CodeEditor = createClass({
}
},
makeSuper : function() {
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 2) === '^^' && selection.slice(-2) === '^^';
this.codeMirror.replaceSelection(t ? selection.slice(2, -2) : `^^${selection}^^`, 'around');
if(selection.length === 0){
const cursor = this.codeMirror.getCursor();
this.codeMirror.setCursor({ line: cursor.line, ch: cursor.ch - 2 });
}
},
makeSub : function() {
const selection = this.codeMirror.getSelection(), t = selection.slice(0, 3) === '^^^' && selection.slice(-3) === '^^^';
this.codeMirror.replaceSelection(t ? selection.slice(3, -3) : `^^^${selection}^^^`, 'around');
if(selection.length === 0){
const cursor = this.codeMirror.getCursor();
this.codeMirror.setCursor({ line: cursor.line, ch: cursor.ch - 3 });
}
},
makeNbsp : function() {
this.codeMirror.replaceSelection(' ', 'end');
},

View File

@@ -206,47 +206,38 @@ const mustacheInjectBlock = {
}
};
const superScripts = {
name : 'superScriptsInjectInline',
const superSubScripts = {
name : 'superSubScripts',
level : 'inline',
start(src) { return src.match(/.*\^\^(.+)\^\^/)?.index; }, // Hint to Marked.js to stop and check for a match
tokenizer(src, tokens) {
const inlineRegex = /.*\^\^(.+)\^\^/y;
const match = inlineRegex.exec(src);
if(match) {
const tags = ` ${processStyleTags(match[1])}`;
return {
type : 'text', // Should match "name" above
raw : match[0], // Text to consume from the source
text : '',
tags
};
const superRegex = /.*\^\^(.+)\^\^/y;
const subRegex = /.*\^\^\^(.+)\^\^\^/y;
let isSuper = false;
let match = subRegex.exec(src);
if(!match){
match = superRegex.exec(src);
if(match) {
isSuper = true;
}
} else {
console.log(src);
}
},
renderer(token) {
return `<sup>${token.tags}</sup>`;
}
};
const subScripts = {
name : 'subScriptsInjectInline',
level : 'inline',
start(src) { return src.match(/.*\^\^\^(.+)\^\^\^/)?.index; }, // Hint to Marked.js to stop and check for a match
tokenizer(src, tokens) {
const inlineRegex = /.*\^\^\^(.+)\^\^\^/y;
const match = inlineRegex.exec(src);
if(match) {
const tags = ` ${processStyleTags(match[1])}`;
if(match?.length) {
const tags = this.lexer.inlineTokens(match[1]);
return {
type : 'text', // Should match "name" above
raw : match[0], // Text to consume from the source
text : '',
type : 'superSubScripts', // Should match "name" above
raw : match[0], // Text to consume from the source
text : src,
super : isSuper,
tags
};
}
},
renderer(token) {
return `<sub>${token.tags}</sub>`;
const tag = token.super ? 'sup' : 'sub';
return `<${tag}>${this.parser.parseInline(token.tags)}</${tag}>`;
}
};
@@ -282,7 +273,7 @@ const definitionLists = {
}
};
Marked.use({ extensions: [mustacheSpans, mustacheDivs, mustacheInjectInline, definitionLists, subScripts, superScripts] });
Marked.use({ extensions: [mustacheSpans, mustacheDivs, mustacheInjectInline, definitionLists, superSubScripts] });
Marked.use(mustacheInjectBlock);
Marked.use({ renderer: renderer, mangle: false });
Marked.use(MarkedExtendedTables(), MarkedGFMHeadingId(), MarkedSmartypantsLite());