import { stripIndent } from 'common-tags'; import docsifyInit from '../helpers/docsify-init.js'; import { waitForText } from '../helpers/wait-for.js'; // Suite // ----------------------------------------------------------------------------- describe('render', function () { // Helpers // --------------------------------------------------------------------------- describe('callouts', () => { beforeEach(async () => { await docsifyInit(); }); test('caution', () => { const output = window.marked('> [!CAUTION]\n> Text'); expect(output).toMatchInlineSnapshot(` "

Text

" `); }); test('important', () => { const output = window.marked('> [!IMPORTANT]\n> Text'); expect(output).toMatchInlineSnapshot(` "

Text

" `); }); test('note', () => { const output = window.marked('> [!NOTE]\n> Text'); expect(output).toMatchInlineSnapshot(` "

Text

" `); }); test('tip', () => { const output = window.marked('> [!TIP]\n> Text'); expect(output).toMatchInlineSnapshot(` "

Text

" `); }); test('warning', () => { const output = window.marked('> [!WARNING]\n> Text'); expect(output).toMatchInlineSnapshot(` "

Text

" `); }); test('important (legacy)', () => { const output = window.marked('!> Important content'); expect(output).toMatchInlineSnapshot( `"

Important content

"`, ); }); test('tip (legacy)', () => { const output = window.marked('?> General tip'); expect(output).toMatchInlineSnapshot( `"

General tip

"`, ); }); }); // Lists // --------------------------------------------------------------------------- describe('lists', function () { beforeEach(async () => { await docsifyInit(); }); test('as unordered task list', async function () { const output = window.marked(stripIndent` - [x] Task 1 - [ ] Task 2 - [ ] Task 3 `); expect(output).toMatchInlineSnapshot( '""', ); }); test('as ordered task list', async function () { const output = window.marked(stripIndent` 1. [ ] Task 1 2. [x] Task 2 `); expect(output).toMatchInlineSnapshot( '"
"', ); }); test('normal unordered', async function () { const output = window.marked(stripIndent` - [linktext](link) - just text `); expect(output).toMatchInlineSnapshot( '""', ); }); test('unordered with custom start', async function () { const output = window.marked(stripIndent` 1. first 2. second text 3. third `); expect(output).toMatchInlineSnapshot( '"
  1. first
  2. second

text

  1. third
"', ); }); test('nested', async function () { const output = window.marked(stripIndent` - 1 - 2 - 2 a - 2 b - 3 `); expect(output).toMatchInlineSnapshot( '""', ); }); }); // Images // --------------------------------------------------------------------------- describe('images', function () { beforeEach(async () => { await docsifyInit(); }); test('regular', async function () { const output = window.marked('![alt text](http://imageUrl)'); expect(output).toMatchInlineSnapshot( '"

alt text

"', ); }); test('class', async function () { const output = window.marked( "![alt text](http://imageUrl ':class=someCssClass')", ); expect(output).toMatchInlineSnapshot( '"

alt text

"', ); }); test('id', async function () { const output = window.marked( "![alt text](http://imageUrl ':id=someCssID')", ); expect(output).toMatchInlineSnapshot( '"

alt text

"', ); }); test('no-zoom', async function () { const output = window.marked("![alt text](http://imageUrl ':no-zoom')"); expect(output).toMatchInlineSnapshot( '"

alt text

"', ); }); test('width and height', async function () { const output = window.marked( "![alt text](http://imageUrl ':size=WIDTHxHEIGHT')", ); expect(output).toMatchInlineSnapshot( '"

alt text

"', ); }); test('width', async function () { const output = window.marked("![alt text](http://imageUrl ':size=50')"); expect(output).toMatchInlineSnapshot( '"

alt text

"', ); }); }); // Headings // --------------------------------------------------------------------------- describe('headings', function () { beforeEach(async () => { await docsifyInit(); }); test('h1', async function () { const output = window.marked('# h1 tag'); expect(output).toMatchInlineSnapshot( '"

h1 tag

"', ); }); test('h2', async function () { const output = window.marked('## h2 tag'); expect(output).toMatchInlineSnapshot( '"

h2 tag

"', ); }); test('h3', async function () { const output = window.marked('### h3 tag'); expect(output).toMatchInlineSnapshot( '"

h3 tag

"', ); }); test('h4', async function () { const output = window.marked('#### h4 tag'); expect(output).toMatchInlineSnapshot( '"

h4 tag

"', ); }); test('h5', async function () { const output = window.marked('##### h5 tag'); expect(output).toMatchInlineSnapshot( '"
h5 tag
"', ); }); test('h6', async function () { const output = window.marked('###### h6 tag'); expect(output).toMatchInlineSnapshot( '"
h6 tag
"', ); }); }); // Links // --------------------------------------------------------------------------- describe('link', function () { beforeEach(async () => { await docsifyInit(); }); test('regular', async function () { const output = window.marked('[alt text](http://url)'); expect(output).toMatchInlineSnapshot( `"

alt text

"`, ); }); test('linkrel', async function () { // const { docsify } = await init('default', { // externalLinkTarget: '_blank', // externalLinkRel: 'noopener', // }); const output = window.marked('[alt text](http://www.example.com)'); expect(output).toMatchInlineSnapshot( `"

alt text

"`, ); }); test('disabled', async function () { const output = window.marked("[alt text](http://url ':disabled')"); expect(output).toMatchInlineSnapshot( `"

alt text

"`, ); }); test('target for absolute path', async function () { const output = window.marked("[alt text](http://url ':target=_self')"); expect(output).toMatchInlineSnapshot( `"

alt text

"`, ); }); test('target for relative path', async function () { const output = window.marked("[alt text](/url ':target=_blank')"); expect(output).toMatchInlineSnapshot( '"

alt text

"', ); }); test('class', async function () { const output = window.marked( "[alt text](http://url ':class=someCssClass')", ); expect(output).toMatchInlineSnapshot( `"

alt text

"`, ); }); test('multi class config', async function () { const output = window.marked( "[alt text](http://url ':class=someCssClass :class=anotherCssClass')", ); expect(output).toMatchInlineSnapshot( `"

alt text

"`, ); }); test('id', async function () { const output = window.marked("[alt text](http://url ':id=someCssID')"); expect(output).toMatchInlineSnapshot( `"

alt text

"`, ); }); }); // Skip Link // --------------------------------------------------------------------------- describe('skip link', () => { test('renders default skip link and label', async () => { await docsifyInit(); const elm = document.getElementById('skip-to-content'); const expectText = 'Skip to main content'; expect(elm.textContent).toBe(expectText); expect(elm.outerHTML).toMatchInlineSnapshot( `""`, ); }); test('renders custom label from config string', async () => { const expectText = 'test'; await docsifyInit({ config: { skipLink: expectText, }, }); const elm = document.getElementById('skip-to-content'); expect(elm.textContent).toBe(expectText); }); test('renders custom label from config object', async () => { const getSkipLinkText = () => document.getElementById('skip-to-content').textContent; await docsifyInit({ config: { skipLink: { '/dir1/dir2/': 'baz', '/dir1/': 'bar', }, }, }); window.location.hash = '/dir1/dir2/'; await waitForText('#skip-to-content', 'baz'); expect(getSkipLinkText()).toBe('baz'); window.location.hash = '/dir1/'; await waitForText('#skip-to-content', 'bar'); expect(getSkipLinkText()).toBe('bar'); // Fallback to default window.location.hash = ''; await waitForText('#skip-to-content', 'Skip to main content'); expect(getSkipLinkText()).toBe('Skip to main content'); }); test('does not render skip link when false', async () => { await docsifyInit({ config: { skipLink: false, }, }); const elm = document.getElementById('skip-to-content') || false; expect(elm).toBe(false); }); }); });