mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-06 23:02:45 +00:00
I think I have all the desired modes in place.
I feel like this is ugly code and maybe there are prettier ways to do it, but it functions as I *believe* is currently desired.
This commit is contained in:
@@ -300,12 +300,23 @@ const blockDefinitionLists = {
|
|||||||
let currentDefinition = {};
|
let currentDefinition = {};
|
||||||
let inList = false;
|
let inList = false;
|
||||||
let lastEmpty = false;
|
let lastEmpty = false;
|
||||||
|
let inlineDefinitions = false;
|
||||||
while (match = regex.exec(src)) {
|
while (match = regex.exec(src)) {
|
||||||
|
// If we aren't actively in a DL and we match just text, bail.
|
||||||
|
// If the last loop bailed with lastEmpty and we match just text, bail
|
||||||
|
if(((!inList) || (lastEmpty)) && (typeof match[1] == 'undefined') && (typeof match[2] == 'undefined')) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
endIndex += match[0].length;
|
endIndex += match[0].length;
|
||||||
if(match[0].indexOf(':') > -1) {
|
// Check to see if this a match containing the start of a DD.
|
||||||
|
if(match[0].indexOf('::') > -1) {
|
||||||
inList = true;
|
inList = true;
|
||||||
if(match[1].trim()?.length) {
|
// Check for a DT value.
|
||||||
|
if(match[1]?.trim()?.length>0) {
|
||||||
if(currentDefinition?.dt?.length) {
|
if(currentDefinition?.dt?.length) {
|
||||||
|
currentDefinition.dd.forEach((dd)=>{
|
||||||
|
currentDefinition.ddo.push(this.lexer.inlineTokens(dd));
|
||||||
|
});
|
||||||
allDefinitions.push(currentDefinition);
|
allDefinitions.push(currentDefinition);
|
||||||
currentDefinition = {};
|
currentDefinition = {};
|
||||||
}
|
}
|
||||||
@@ -317,23 +328,42 @@ const blockDefinitionLists = {
|
|||||||
} else if(_.isEmpty(currentDefinition)) {
|
} else if(_.isEmpty(currentDefinition)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const newDefinitions = _.flatten(match[2].split('::').filter((item)=>item).map((s)=>s.trim()));
|
// Test for a DD value.
|
||||||
if(newDefinitions?.length) {
|
if(match[2].trim().length>0) {
|
||||||
currentDefinition.dd = currentDefinition.dd.concat(newDefinitions);
|
if((match[1]?.length > 0) && (match[0].indexOf('\n') > match[1]?.length)) { // Inline Style DD
|
||||||
|
currentDefinition.dd = currentDefinition.dd.concat([match[2].trim()]);
|
||||||
|
currentDefinition.dd.forEach((dd)=>{
|
||||||
|
currentDefinition.ddo.push(this.lexer.inlineTokens(dd));
|
||||||
|
});
|
||||||
|
allDefinitions.push(currentDefinition);
|
||||||
|
inlineDefinitions = true;
|
||||||
|
currentDefinition = {};
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Multi-line style DDs
|
||||||
|
const newDefinitions = _.flatten(match[2].split('::').filter((item)=>item).map((s)=>s.trim()));
|
||||||
|
if(newDefinitions?.length) {
|
||||||
|
currentDefinition.dd = currentDefinition.dd.concat(newDefinitions);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
currentDefinition.dd.push('');
|
currentDefinition.dd.push('');
|
||||||
}
|
}
|
||||||
lastEmpty = false;
|
lastEmpty = false;
|
||||||
} else if(inList) {
|
} else if(inList) { // Regular line that might mark the end of a line.
|
||||||
|
if(inlineDefinitions) {
|
||||||
|
endIndex -= match[0].length;
|
||||||
|
break;
|
||||||
|
}
|
||||||
if(match[0].trim().length == 0) {
|
if(match[0].trim().length == 0) {
|
||||||
if(lastEmpty) {
|
if(lastEmpty) {
|
||||||
break;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
lastEmpty = true;
|
lastEmpty = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
lastEmpty = false;
|
lastEmpty = false;
|
||||||
currentDefinition.dd[currentDefinition.dd.length - 1] = `${currentDefinition.dd[ currentDefinition.dd.length - 1 ]} ${match[0].trim()}`;
|
const lastPos = typeof currentDefinition.dd.length !== 'undefined' ? currentDefinition.dd.length - 1 : 0;
|
||||||
|
currentDefinition.dd[lastPos] = `${currentDefinition.dd[lastPos]} ${match[0].trim()}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -347,22 +377,20 @@ const blockDefinitionLists = {
|
|||||||
return {
|
return {
|
||||||
type : 'blockDefinitionLists',
|
type : 'blockDefinitionLists',
|
||||||
raw : src.slice(0, endIndex),
|
raw : src.slice(0, endIndex),
|
||||||
|
inlineDefinitions,
|
||||||
definitions : allDefinitions
|
definitions : allDefinitions
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
renderer(token) {
|
renderer(token) {
|
||||||
let returnVal = `<dl>`;
|
let returnVal = `<dl${token.inlineDefinitions ? ' class="inlineDL"' : ''}>`;
|
||||||
token.definitions.forEach((def)=>{
|
token.definitions.forEach((def)=>{
|
||||||
console.log(def.ddo);
|
|
||||||
let dds = def.ddo.map((s)=>{
|
let dds = def.ddo.map((s)=>{
|
||||||
return `<dd>${this.parser.parseInline(s)}</dd>`;
|
return `<dd>${this.parser.parseInline(s)}</dd>`;
|
||||||
}).join('\n');
|
}).join('\n');
|
||||||
dds = dds.trim();
|
|
||||||
returnVal += `<dt>${this.parser.parseInline(def.dt)}</dt>${dds.indexOf('\n') > -1 ? '\n' : ''}${dds}\n`;
|
returnVal += `<dt>${this.parser.parseInline(def.dt)}</dt>${dds.indexOf('\n') > -1 ? '\n' : ''}${dds}\n`;
|
||||||
});
|
});
|
||||||
returnVal = returnVal.trim();
|
returnVal = returnVal.trim();
|
||||||
console.log(returnVal);
|
|
||||||
return `${returnVal}</dl>`;
|
return `${returnVal}</dl>`;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -896,7 +896,13 @@
|
|||||||
white-space: normal !important;
|
white-space: normal !important;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dd {
|
||||||
|
display: block
|
||||||
|
}
|
||||||
|
|
||||||
p + dl { margin-top : 0.17cm; }
|
p + dl { margin-top : 0.17cm; }
|
||||||
|
|
||||||
dt {
|
dt {
|
||||||
display : inline;
|
display : inline;
|
||||||
margin-right : 5px;
|
margin-right : 5px;
|
||||||
@@ -904,6 +910,19 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// *****************************
|
||||||
|
// * Inline Definition Lists
|
||||||
|
// *****************************/
|
||||||
|
.inlineDL dd {
|
||||||
|
display: inline !important
|
||||||
|
}
|
||||||
|
|
||||||
|
.inlineDL dd:after{
|
||||||
|
display: block;
|
||||||
|
content: '';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// *****************************
|
// *****************************
|
||||||
// * WIDE
|
// * WIDE
|
||||||
// *****************************/
|
// *****************************/
|
||||||
|
|||||||
Reference in New Issue
Block a user