mirror of
https://github.com/cupcakearmy/markdown-it-import.git
synced 2024-12-21 15:56:26 +00:00
trim content by default
This commit is contained in:
parent
7bb8db420f
commit
a6c56e536a
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@nicco.io/markdown-it-import",
|
"name": "@nicco.io/markdown-it-import",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"description": "Markdown-it plugin which adds the ability to include markdown fragment files.",
|
"description": "Markdown-it plugin which adds the ability to include markdown fragment files.",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"markdown-it-plugin",
|
"markdown-it-plugin",
|
||||||
|
@ -6,6 +6,7 @@ function defaultOptions() {
|
|||||||
return {
|
return {
|
||||||
matcher: /@import\((?<file>.+)\)(\s*?\[(?<range>\d+-\d+)\])?/g,
|
matcher: /@import\((?<file>.+)\)(\s*?\[(?<range>\d+-\d+)\])?/g,
|
||||||
root: process.cwd(),
|
root: process.cwd(),
|
||||||
|
trim: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,6 +41,9 @@ export function importPlugin(md: any, options: Options = {}) {
|
|||||||
const exists = fs.existsSync(filename)
|
const exists = fs.existsSync(filename)
|
||||||
if (!exists) throw new Error(`cannot locate file "${filename}"`)
|
if (!exists) throw new Error(`cannot locate file "${filename}"`)
|
||||||
let contents = fs.readFileSync(filename, 'utf-8')
|
let contents = fs.readFileSync(filename, 'utf-8')
|
||||||
|
if (o.trim) {
|
||||||
|
contents = contents.trim()
|
||||||
|
}
|
||||||
|
|
||||||
// Apply line range
|
// Apply line range
|
||||||
if (range) {
|
if (range) {
|
||||||
|
@ -34,7 +34,6 @@ exports[`base single import 1`] = `
|
|||||||
<pre><code class="language-ts">export function sum(a: number, b: number): number {
|
<pre><code class="language-ts">export function sum(a: number, b: number): number {
|
||||||
return a + b
|
return a + b
|
||||||
}
|
}
|
||||||
|
|
||||||
</code></pre>
|
</code></pre>
|
||||||
"
|
"
|
||||||
`;
|
`;
|
||||||
@ -44,7 +43,6 @@ exports[`base multiple imports 1`] = `
|
|||||||
<pre><code class="language-ts">export function sum(a: number, b: number): number {
|
<pre><code class="language-ts">export function sum(a: number, b: number): number {
|
||||||
return a + b
|
return a + b
|
||||||
}
|
}
|
||||||
|
|
||||||
</code></pre>
|
</code></pre>
|
||||||
<blockquote>
|
<blockquote>
|
||||||
<p>This is some amazing quote</p>
|
<p>This is some amazing quote</p>
|
||||||
|
@ -38,3 +38,13 @@ exports[`options empty options 1`] = `
|
|||||||
</table>
|
</table>
|
||||||
"
|
"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`options do not trim 1`] = `
|
||||||
|
"<p>Here is a typescript snippet</p>
|
||||||
|
<pre><code class="language-ts">export function sum(a: number, b: number): number {
|
||||||
|
return a + b
|
||||||
|
}
|
||||||
|
|
||||||
|
</code></pre>
|
||||||
|
"
|
||||||
|
`;
|
||||||
|
@ -9,7 +9,6 @@ exports[`base import different files 1`] = `
|
|||||||
<pre><code class="language-ts">export function sum(a: number, b: number): number {
|
<pre><code class="language-ts">export function sum(a: number, b: number): number {
|
||||||
return a + b
|
return a + b
|
||||||
}
|
}
|
||||||
|
|
||||||
</code></pre>
|
</code></pre>
|
||||||
"
|
"
|
||||||
`;
|
`;
|
||||||
|
@ -30,4 +30,8 @@ describe('options', () => {
|
|||||||
expect(() => render('matcher-a.md', { matcher })).toThrow('Regexp must expose a named group "file"')
|
expect(() => render('matcher-a.md', { matcher })).toThrow('Regexp must expose a named group "file"')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('do not trim', async () => {
|
||||||
|
expect(await render('whole.md', { trim: false })).toMatchSnapshot()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user