Skip to content

Commit

Permalink
Merge branch 'next'
Browse files Browse the repository at this point in the history
  • Loading branch information
kellyjosephprice committed Sep 12, 2023
2 parents 6ddf062 + a4db15f commit 1089890
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion __tests__/flavored-compilers/break.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mdast, md } from '../..';
import { mdast, md } from '../../index';

describe('break compiler', () => {
it('uses two spaces with `correctnewlines: false`', () => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ test('it should have the proper utils exports', () => {
spacedTable: true,
paddedTable: true,
},
normalize: true,
reusableContent: {},
safeMode: false,
settings: { position: false },
Expand Down
38 changes: 38 additions & 0 deletions __tests__/normalize.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { mdast } from '../index';

describe('normalize option', () => {
it('normalizes magic block newlines', () => {
const doc = `
> blockquote
>
[block:image]
{
"images": [
{
"image": [
"https://owlbertsio-resized.s3.amazonaws.com/This-Is-Fine.jpg.full.png",
"",
""
],
"align": "center"
}
]
}
[/block]
`;
const tree = mdast(doc);

expect(tree.children[1].type).toBe('image');
});

it('does not normalize nested magic blocks', () => {
const doc = `
> blockquote
>
> [block:image]{ "images": [ { "image": [ "https://owlbertsio-resized.s3.amazonaws.com/This-Is-Fine.jpg.full.png", "", "" ], "align": "center" } ]}[/block]
`;
const tree = mdast(doc, { normalize: false });

expect(tree.children[0].children[1].type).toBe('image');
});
});
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export function setup(blocks, opts = {}) {
Object.values(Components).forEach(Component => Component.sanitize && Component.sanitize(opts.sanitize));
}

// normalize magic block linebreaks
if (opts.normalize && blocks) {
blocks = blocks.replace(/^\[block:/gm, '\n[block:').replace(/^\[\/block\]/gm, '[/block]\n');
}

return [`${blocks}\n\n `, opts];
}

Expand Down
1 change: 1 addition & 0 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const options = {
spacedTable: true,
paddedTable: true,
},
normalize: true,
lazyImages: true,
reusableContent: {},
safeMode: false,
Expand Down

0 comments on commit 1089890

Please sign in to comment.