Skip to content

Commit

Permalink
fix: replace() throws Error if empty ReplaceRules array is given
Browse files Browse the repository at this point in the history
  • Loading branch information
AyumuTakai committed Jan 12, 2021
1 parent c4bbb79 commit b0cfb6a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/plugins/replace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface ReplaceRule {
}

export function replace({ rules }: { rules?: ReplaceRule[] } = {}) {
if (!rules) return;
if (!rules || rules.length == 0) return;
const search = rules.map(
(rule) =>
[
Expand Down
28 changes: 28 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ it('reject incorrect fences', () => {
});

it('handle fenced block', () => {
const result = partial(`
:::foos
# foo
foovar
:::
`);

expect(result).toBe(
`<div class="foos"><section id="foo"><h1>foo</h1><p>foovar</p></section></div>`,
);

expect(
partial(`
:::appendix
Expand Down Expand Up @@ -195,3 +206,20 @@ it('replace', () => {
.toBe(`<p><div class="balloon"><img src="./img/icon1.png"><span>Notice</span></div></p>
<p><div class="balloon"><img src="./img/person.png"><span>Nod nod</span></div></p>`);
});

it('empty replace', () => {
const rules = [] as ReplaceRule[];
expect(
lib.stringify(
`
[icon1][Notice]
[person][Nod nod]`,
{
partial: true,
replace: rules,
},
),
).toBe(`<p>[icon1][Notice]</p>
<p>[person][Nod nod]</p>`);
});

0 comments on commit b0cfb6a

Please sign in to comment.