mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-29 15:32:40 +00:00
Updated rendering to follow input line breaks
Updated and additional tests.
This commit is contained in:
@@ -257,9 +257,12 @@ const definitionLists = {
|
||||
} else if(_.isEmpty(currentDefinition)) {
|
||||
return;
|
||||
}
|
||||
currentDefinition.dd = currentDefinition.dd.concat(match[2].split('::').filter((item)=>item).map((s)=>this.lexer.inlineTokens(s.trim())));
|
||||
if(!currentDefinition.dd?.length) {
|
||||
currentDefinition.dd = [this.lexer.inlineTokens('')];
|
||||
const newDefinitions = match[2].split('::').filter((item)=>item).map((s)=>this.lexer.inlineTokens(s.trim()));
|
||||
console.log(newDefinitions);
|
||||
if(newDefinitions?.length) {
|
||||
currentDefinition.dd.push(newDefinitions);
|
||||
} else {
|
||||
currentDefinition.dd.push([this.lexer.inlineTokens('')]);
|
||||
}
|
||||
}
|
||||
if(currentDefinition.hasOwnProperty('dt')) { allDefinitions.push(currentDefinition); }
|
||||
@@ -274,8 +277,10 @@ const definitionLists = {
|
||||
renderer(token) {
|
||||
let returnVal = `<dl>`;
|
||||
token.definitions.forEach((def)=>{
|
||||
const dds = def.dd.map((s)=>`<dd>${this.parser.parseInline(s)}</dd>`).join('\n');
|
||||
returnVal += `<dt>${this.parser.parseInline(def.dt)}</dt>\n${dds}\n`;
|
||||
const dds = def.dd.map((ddef)=>{
|
||||
return ddef.map((s)=>`<dd>${this.parser.parseInline(s)}</dd>`).join('');
|
||||
}).join('\n');
|
||||
returnVal += `<dt>${this.parser.parseInline(def.dt)}</dt>${dds.indexOf('\n') > -1 ? '\n' : ''}${dds}\n`;
|
||||
});
|
||||
return `${returnVal}</dl>`;
|
||||
}
|
||||
|
||||
@@ -6,25 +6,24 @@ describe('Dictionary Terms', ()=>{
|
||||
test('Single Definition', function() {
|
||||
const source = 'My term :: My First Definition\n\n';
|
||||
const rendered = Markdown.render(source);
|
||||
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<dl><dt>My term</dt>\n<dd>My First Definition</dd>\n</dl>');
|
||||
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<dl><dt>My term</dt><dd>My First Definition</dd>\n</dl>');
|
||||
});
|
||||
|
||||
test('Two Definitions', function() {
|
||||
const source = 'My term :: My First Definition :: My Second Definition\n\n';
|
||||
const rendered = Markdown.render(source);
|
||||
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<dl><dt>My term</dt>\n<dd>My First Definition</dd>\n<dd>My Second Definition</dd>\n</dl>');
|
||||
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<dl><dt>My term</dt><dd>My First Definition</dd><dd>My Second Definition</dd>\n</dl>');
|
||||
});
|
||||
|
||||
test('Three Definitions', function() {
|
||||
const source = 'My term :: My First Definition :: My Second Definition :: My Third Definition\n\n';
|
||||
const rendered = Markdown.render(source);
|
||||
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<dl><dt>My term</dt>\n<dd>My First Definition</dd>\n<dd>My Second Definition</dd>\n<dd>My Third Definition</dd>\n</dl>');
|
||||
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<dl><dt>My term</dt><dd>My First Definition</dd><dd>My Second Definition</dd><dd>My Third Definition</dd>\n</dl>');
|
||||
});
|
||||
|
||||
test('Multiline Definitions', function() {
|
||||
const source = '**Example** :: V3 uses HTML *definition lists* to create "lists" with hanging indents.\n::Three\n::Four\n\nHello::I\'m a different\n::List\n\n';
|
||||
test('Multiple Definition Terms, multiple mixed-line definitions', function() {
|
||||
const source = 'Term 1::Definition 1 of Term 1\n::Definition 2 of Term 1::Definition 3 of Term 1\nTerm 2::Definition of Term 2';
|
||||
const rendered = Markdown.render(source);
|
||||
expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('<dl><dt><strong>Example</strong></dt>\n<dd>V3 uses HTML <em>definition lists</em> to create “lists” with hanging indents.</dd>\n<dd>Three</dd>\n<dd>Four</dd>\n</dl><dl><dt>Hello</dt>\n<dd>I\’m a different</dd>\n<dd>List</dd>\n</dl>');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user