|
| 1 | +const path = require('path'); |
1 | 2 | const { expect } = require('chai');
|
2 | 3 | const { init, expectSameDom } = require('../_helper');
|
3 | 4 |
|
@@ -104,6 +105,23 @@ describe('render', function() {
|
104 | 105 | );
|
105 | 106 | });
|
106 | 107 |
|
| 108 | + it('relative image url', async function() { |
| 109 | + const { docsify } = await init(); |
| 110 | + const output = docsify.compiler.compile( |
| 111 | + '' |
| 112 | + ); |
| 113 | + const expectedCompiledPath = path.posix.join( |
| 114 | + // must use posix here because if run on windows, paths are joined using backslash (\) |
| 115 | + __dirname, |
| 116 | + '../fixtures/default', |
| 117 | + 'some-path/image.png' |
| 118 | + ); |
| 119 | + expectSameDom( |
| 120 | + output, |
| 121 | + `<p><img src="${expectedCompiledPath}" data-origin="some-path/image.png" alt="alt text"></p>` |
| 122 | + ); |
| 123 | + }); |
| 124 | + |
107 | 125 | it('class', async function() {
|
108 | 126 | const { docsify } = await init();
|
109 | 127 | const output = docsify.compiler.compile(
|
@@ -165,6 +183,53 @@ describe('render', function() {
|
165 | 183 | );
|
166 | 184 | });
|
167 | 185 | });
|
| 186 | + |
| 187 | + describe('compiling root-relative image src path', async function() { |
| 188 | + it('behaves normally if config.rootRelativeImageURL is set to false', async function() { |
| 189 | + const { docsify } = await init('default', { |
| 190 | + rootRelativeImageURL: false, |
| 191 | + }); |
| 192 | + const rootRelativePathOutput = docsify.compiler.compile( |
| 193 | + '' |
| 194 | + ); |
| 195 | + const expectedCompiledPath = path.posix.join( |
| 196 | + // must use posix here because if run on windows, file paths use backslash (\) |
| 197 | + __dirname, |
| 198 | + '../fixtures/default', |
| 199 | + 'some-path/image.png' |
| 200 | + ); |
| 201 | + expectSameDom( |
| 202 | + rootRelativePathOutput, |
| 203 | + `<p><img src="${expectedCompiledPath}" data-origin="/some-path/image.png" alt="alt text"></p>` |
| 204 | + ); |
| 205 | + }); |
| 206 | + |
| 207 | + it('only uses the image href if config.rootRelativeImageURL is set to true', async function() { |
| 208 | + const { docsify } = await init('default', { |
| 209 | + rootRelativeImageURL: true, |
| 210 | + }); |
| 211 | + const rootRelativePathOutput = docsify.compiler.compile( |
| 212 | + '' |
| 213 | + ); |
| 214 | + expectSameDom( |
| 215 | + rootRelativePathOutput, |
| 216 | + `<p><img src="/some-path/image.png" data-origin="/some-path/image.png" alt="alt text"></p>` |
| 217 | + ); |
| 218 | + }); |
| 219 | + |
| 220 | + it('uses config.rootRelativeImageURL as a prefix for the compiled image path, if passed as a string', async function() { |
| 221 | + const { docsify } = await init('default', { |
| 222 | + rootRelativeImageURL: 'docs', |
| 223 | + }); |
| 224 | + const rootRelativePathOutput = docsify.compiler.compile( |
| 225 | + '' |
| 226 | + ); |
| 227 | + expectSameDom( |
| 228 | + rootRelativePathOutput, |
| 229 | + `<p><img src="/docs/some-path/image.png" data-origin="/some-path/image.png" alt="alt text"></p>` |
| 230 | + ); |
| 231 | + }); |
| 232 | + }); |
168 | 233 | });
|
169 | 234 |
|
170 | 235 | describe('heading', function() {
|
|
0 commit comments