Skip to content

Commit

Permalink
🐛 Fix title parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardfactory committed Mar 12, 2019
1 parent ceb228b commit 1af4f14
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
21 changes: 21 additions & 0 deletions src/parser.spec.ts
Expand Up @@ -136,6 +136,27 @@ describe('parser', () => {
<p>Message
:art:</p>
</div></div>"
`);
});

test('should render title', () => {
md.use(plugin());
expect(
md.render(dedent`
:::caution With a title!
Message
:art:
`)
).toMatchInlineSnapshot(`
"
<div class=\\"admonition admonition-caution\\">
<div class=\\"admonition-heading\\">
<h5><div class=\\"admonition-icon\\">🔥</div> With a title!</h5>
</div>
<div class=\\"admonition-content\\">
<p>Message
:art:</p>
</div></div>"
`);
});
});
10 changes: 6 additions & 4 deletions src/parser.ts
Expand Up @@ -28,10 +28,12 @@ export const parser: Remarkable.BlockParsingRule = (
// We need exactly 3 `:`
if (pos - mem !== 3) return false;

const [admonition, title] = state.src
.slice(pos, max)
.trim()
.split(' ', 2);
const line = state.src.slice(pos, max).trim();

let sep = line.indexOf(' ');
if (sep === -1) sep = line.length;
const admonition = line.slice(0, sep);
const title = line.slice(sep);

if (admonition === '') return false;

Expand Down

0 comments on commit 1af4f14

Please sign in to comment.