mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-16 16:14:43 -04:00
Move markdown split into redux (#1681)
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
71e668cd17
commit
6594e1bb86
30 changed files with 217 additions and 226 deletions
|
@ -10,47 +10,47 @@ import type { PresentFrontmatterExtractionResult } from './types'
|
|||
describe('frontmatter extraction', () => {
|
||||
describe('isPresent property', () => {
|
||||
it('is false when note does not contain three dashes at all', () => {
|
||||
const testNote = 'abcdef\nmore text'
|
||||
const testNote = ['abcdef', 'more text']
|
||||
const extraction = extractFrontmatter(testNote)
|
||||
expect(extraction.isPresent).toBe(false)
|
||||
})
|
||||
it('is false when note does not start with three dashes', () => {
|
||||
const testNote = '\n---\nthis is not frontmatter'
|
||||
const testNote = ['', '---', 'this is not frontmatter']
|
||||
const extraction = extractFrontmatter(testNote)
|
||||
expect(extraction.isPresent).toBe(false)
|
||||
})
|
||||
it('is false when note start with less than three dashes', () => {
|
||||
const testNote = '--\nthis is not frontmatter'
|
||||
const testNote = ['--', 'this is not frontmatter']
|
||||
const extraction = extractFrontmatter(testNote)
|
||||
expect(extraction.isPresent).toBe(false)
|
||||
})
|
||||
it('is false when note starts with three dashes but contains other characters in the same line', () => {
|
||||
const testNote = '--- a\nthis is not frontmatter'
|
||||
const testNote = ['--- a', 'this is not frontmatter']
|
||||
const extraction = extractFrontmatter(testNote)
|
||||
expect(extraction.isPresent).toBe(false)
|
||||
})
|
||||
it('is false when note has no ending marker for frontmatter', () => {
|
||||
const testNote = '---\nthis is not frontmatter\nbecause\nthere is no\nend marker'
|
||||
const testNote = ['---', 'this is not frontmatter', 'because', 'there is no', 'end marker']
|
||||
const extraction = extractFrontmatter(testNote)
|
||||
expect(extraction.isPresent).toBe(false)
|
||||
})
|
||||
it('is false when note end marker is present but with not the same amount of dashes as start marker', () => {
|
||||
const testNote = '---\nthis is not frontmatter\n----\ncontent'
|
||||
const testNote = ['---', 'this is not frontmatter', '----', 'content']
|
||||
const extraction = extractFrontmatter(testNote)
|
||||
expect(extraction.isPresent).toBe(false)
|
||||
})
|
||||
it('is true when note end marker is present with the same amount of dashes as start marker', () => {
|
||||
const testNote = '---\nthis is frontmatter\n---\ncontent'
|
||||
const testNote = ['---', 'this is frontmatter', '---', 'content']
|
||||
const extraction = extractFrontmatter(testNote)
|
||||
expect(extraction.isPresent).toBe(true)
|
||||
})
|
||||
it('is true when note end marker is present with the same amount of dashes as start marker but without content', () => {
|
||||
const testNote = '---\nthis is frontmatter\n---'
|
||||
const testNote = ['---', 'this is frontmatter', '---']
|
||||
const extraction = extractFrontmatter(testNote)
|
||||
expect(extraction.isPresent).toBe(true)
|
||||
})
|
||||
it('is true when note end marker is present with the same amount of dots as start marker', () => {
|
||||
const testNote = '---\nthis is frontmatter\n...\ncontent'
|
||||
const testNote = ['---', 'this is frontmatter', '...', 'content']
|
||||
const extraction = extractFrontmatter(testNote)
|
||||
expect(extraction.isPresent).toBe(true)
|
||||
})
|
||||
|
@ -58,22 +58,22 @@ describe('frontmatter extraction', () => {
|
|||
|
||||
describe('lineOffset property', () => {
|
||||
it('is correct for single line frontmatter without content', () => {
|
||||
const testNote = '---\nsingle line frontmatter\n...'
|
||||
const testNote = ['---', 'single line frontmatter', '...']
|
||||
const extraction = extractFrontmatter(testNote) as PresentFrontmatterExtractionResult
|
||||
expect(extraction.lineOffset).toEqual(3)
|
||||
})
|
||||
it('is correct for single line frontmatter with content', () => {
|
||||
const testNote = '---\nsingle line frontmatter\n...\ncontent'
|
||||
const testNote = ['---', 'single line frontmatter', '...', 'content']
|
||||
const extraction = extractFrontmatter(testNote) as PresentFrontmatterExtractionResult
|
||||
expect(extraction.lineOffset).toEqual(3)
|
||||
})
|
||||
it('is correct for multi-line frontmatter without content', () => {
|
||||
const testNote = '---\nabc\n123\ndef\n...'
|
||||
const testNote = ['---', 'abc', '123', 'def', '...']
|
||||
const extraction = extractFrontmatter(testNote) as PresentFrontmatterExtractionResult
|
||||
expect(extraction.lineOffset).toEqual(5)
|
||||
})
|
||||
it('is correct for multi-line frontmatter with content', () => {
|
||||
const testNote = '---\nabc\n123\ndef\n...\ncontent'
|
||||
const testNote = ['---', 'abc', '123', 'def', '...', 'content']
|
||||
const extraction = extractFrontmatter(testNote) as PresentFrontmatterExtractionResult
|
||||
expect(extraction.lineOffset).toEqual(5)
|
||||
})
|
||||
|
@ -81,12 +81,12 @@ describe('frontmatter extraction', () => {
|
|||
|
||||
describe('rawText property', () => {
|
||||
it('contains single-line frontmatter text', () => {
|
||||
const testNote = '---\nsingle-line\n...\ncontent'
|
||||
const testNote = ['---', 'single-line', '...', 'content']
|
||||
const extraction = extractFrontmatter(testNote) as PresentFrontmatterExtractionResult
|
||||
expect(extraction.rawText).toEqual('single-line')
|
||||
})
|
||||
it('contains multi-line frontmatter text', () => {
|
||||
const testNote = '---\nmulti\nline\n...\ncontent'
|
||||
const testNote = ['---', 'multi', 'line', '...', 'content']
|
||||
const extraction = extractFrontmatter(testNote) as PresentFrontmatterExtractionResult
|
||||
expect(extraction.rawText).toEqual('multi\nline')
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue