From 3ee9fe1c3fa5322d9617c8c87f894568b5203f0a Mon Sep 17 00:00:00 2001 From: David Bolack Date: Tue, 6 Feb 2024 22:13:44 -0600 Subject: [PATCH] Update tests. Prune no lionger valid cases. --- client/homebrew/editor/editor.jsx | 22 +++++----- client/homebrew/editor/editor.less | 10 +++++ tests/markdown/marked-extensions.test.js | 53 +++++++----------------- 3 files changed, 36 insertions(+), 49 deletions(-) diff --git a/client/homebrew/editor/editor.jsx b/client/homebrew/editor/editor.jsx index ad773c25a..0d1378439 100644 --- a/client/homebrew/editor/editor.jsx +++ b/client/homebrew/editor/editor.jsx @@ -151,21 +151,21 @@ const Editor = createClass({ // definition lists if(line.includes('::')){ - // const regex = /^([^\n]*?)::([^\n]*)(?:\n|$)/ym; - const regex = /^([^\n:]*?)::(.*)(?:\n|$)/ym; + if(/^:*$/.test(line) == true){ return }; + const regex = /^([^\n:]*?)(::[^\n]*)(?:\n|$)/ymd; // the `d` flag, for match indices, throws an ESLint error. let match; while ((match = regex.exec(line)) != null){ - - codeMirror.markText({ line: lineNumber, ch: line.indexOf(match[0]) }, { line: lineNumber, ch: line.indexOf(match[0]) + match[0].length }, { className: 'define' }); - codeMirror.markText({ line: lineNumber, ch: line.indexOf(match[1]) }, { line: lineNumber, ch: line.indexOf(match[1]) + match[1].length }, { className: 'term' }); - const matches = match[2].split('::').map((s)=>(s.trim())); - matches.forEach((m)=>{ - codeMirror.markText({ line: lineNumber, ch: line.indexOf(m) }, { line: lineNumber, ch: line.indexOf(m) + m.length }, { className: 'definition' }); - }); - // codeMirror.markText({ line: lineNumber, ch: line.indexOf(match[2]) }, { line: lineNumber, ch: line.indexOf(match[2]) + match[2].length }, { className: 'definition' }); + codeMirror.markText({ line: lineNumber, ch: match.indices[0][0] }, { line: lineNumber, ch: match.indices[0][1] }, { className: 'dl-highlight' }); + codeMirror.markText({ line: lineNumber, ch: match.indices[1][0] }, { line: lineNumber, ch: match.indices[1][1] }, { className: 'dt-highlight' }); + codeMirror.markText({ line: lineNumber, ch: match.indices[2][0] }, { line: lineNumber, ch: match.indices[2][1] }, { className: 'dd-highlight' }); + const ddIndex = match.indices[2][0]; + let colons = /::/g; + let colonMatches; + while((colonMatches = colons.exec(match[2])) !== null){ + codeMirror.markText({ line: lineNumber, ch: colonMatches.index + ddIndex }, { line: lineNumber, ch: colonMatches.index + colonMatches[0].length + ddIndex }, { className: 'dl-colon-highlight'} ) + } } } - // Superscript if(line.includes('\^')) { const regex = /\^(?!\s)(?=([^\n\^]*[^\s\^]))\1\^/g; diff --git a/client/homebrew/editor/editor.less b/client/homebrew/editor/editor.less index b165f91db..d7950ead3 100644 --- a/client/homebrew/editor/editor.less +++ b/client/homebrew/editor/editor.less @@ -55,6 +55,16 @@ vertical-align : sub; font-size : 0.9em; } + .dl-highlight { + &.dl-colon-highlight { + font-weight : bold; + color : #949494; + background : #E5E5E5; + border-radius : 3px; + } + &.dt-highlight { color : rgb(96, 117, 143); } + &.dd-highlight { color : rgb(97, 57, 178); } + } } .brewJump { diff --git a/tests/markdown/marked-extensions.test.js b/tests/markdown/marked-extensions.test.js index 814aea993..5a8603ab8 100644 --- a/tests/markdown/marked-extensions.test.js +++ b/tests/markdown/marked-extensions.test.js @@ -6,49 +6,13 @@ 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('
My term
My First Definition
'); - }); - - 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('
My term
My First Definition
My Second Definition
'); - }); - - 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('
My term
My First Definition
My Second Definition
My Third Definition
'); - }); - - test('Multiline Definitions', function() { - const source = '**Example** :: V3 uses HTML *definition lists* to create "lists" with hanging indents.\n::Two\n::Three\n::Four\n\n'; - const rendered = Markdown.render(source); - expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('
Example
\n
V3 uses HTML definition lists to create “lists” with hanging indents.
\n
Two
\n
Three
\n
Four
'); + expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('
My term
My First Definition
'); }); test('Multiple Definition Terms, single line, single definition', function() { const source = 'Term 1::Definition of Term 1\nTerm 2::Definition of Term 2\n\n'; const rendered = Markdown.render(source); - expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('
Term 1
Definition of Term 1
\n
Term 2
Definition of Term 2
'); - }); - - test('Multiple Definition Terms, single line, multiple definitions', function() { - const source = 'Term 1::Definition 1 of Term 1::Definition 2 of Term 1\nTerm 2::Definition 1 of Term 2::Definition 2 of Term 2\n\n'; - const rendered = Markdown.render(source); - expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('
Term 1
Definition 1 of Term 1
Definition 2 of Term 1
\n
Term 2
Definition 1 of Term 2
Definition 2 of Term 2
'); - }); - - test('Multiple Definition Terms, single definitions, multiple lines', function() { - const source = 'Term 1::Definition 1 of Term 1\n::Definition 2 of Term 1\nTerm 2::Definition of Term 2\n\n'; - const rendered = Markdown.render(source); - expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('
Term 1
\n
Definition 1 of Term 1
\n
Definition 2 of Term 1
\n
Term 2
Definition of Term 2
'); - }); - - 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\n\n'; - const rendered = Markdown.render(source); - expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('
Term 1
\n
Definition 1 of Term 1
\n
Definition 2 of Term 1
Definition 3 of Term 1
\n
Term 2
Definition of Term 2
'); + expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('
Term 1
Definition of Term 1
\n
Term 2
Definition of Term 2
'); }); test('PANdoc style list - Single Term, Single Definition', function() { @@ -75,5 +39,18 @@ describe('Dictionary Terms', ()=>{ expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('
Term 1
\n
Definition 1
\n
Definition 2
\n
Term 2
\n
Definition 1
\n
Definition 2
'); }); + test('PANdoc style list - Single Term, Single multiple line definition', function() { + const source = 'Term 1\n::Definition 1\nand more and\nmore and more\n\n'; + const rendered = Markdown.render(source); + expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('
Term 1
Definition 1 and more and more and more
'); + + }); + + test('PANdoc style list - Multiple Term, Single multiple line definition', function() { + const source = 'Term 1\n::Definition 1\nand more and\nmore and more\n\n::Definition 2\n\n::Definition 3\n\n'; + const rendered = Markdown.render(source); + expect(rendered, `Input:\n${source}`, { showPrefix: false }).toBe('
Term 1
\n
Definition 1 and more and more and more
\n
Definition 2
\n
Definition 3
'); + + }); });