Skip to content

Commit

Permalink
🐛 Output HTML as div instead of p
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Output is now a `div` in order to allow nesting
  • Loading branch information
leonardfactory committed Mar 12, 2019
1 parent 3537f48 commit 38d36bb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
24 changes: 12 additions & 12 deletions src/parser.spec.ts
Expand Up @@ -18,9 +18,9 @@ describe('parser', () => {
:::
`)
).toMatchInlineSnapshot(`
"<p class=\\"callout callout-info\\"><p>Info
"<div class=\\"callout callout-info\\"><p>Info
:::</p>
</p>"
</div>"
`);
});

Expand All @@ -35,9 +35,9 @@ describe('parser', () => {
Normal paragraph
`)
).toMatchInlineSnapshot(`
"<p class=\\"callout callout-info\\"><p>Info
"<div class=\\"callout callout-info\\"><p>Info
:::</p>
</p><p>Normal paragraph</p>
</div><p>Normal paragraph</p>
"
`);
});
Expand All @@ -54,9 +54,9 @@ describe('parser', () => {
`)
).toMatchInlineSnapshot(`
"<p>Normal paragraph</p>
<p class=\\"callout callout-info\\"><p>Info
<div class=\\"callout callout-info\\"><p>Info
:::</p>
</p>"
</div>"
`);
});

Expand All @@ -73,10 +73,10 @@ describe('parser', () => {
:::
`)
).toMatchInlineSnapshot(`
"<p class=\\"callout callout-caution\\"><p><em>Alert!</em></p>
"<div class=\\"callout callout-caution\\"><p><em>Alert!</em></p>
<pre><code>this is my code block
</code></pre>
</p>"
</div>"
`);
});

Expand All @@ -88,8 +88,8 @@ describe('parser', () => {
*Alert!*
`)
).toMatchInlineSnapshot(`
"<p class=\\"callout callout-caution\\"><p><em>Alert!</em></p>
</p>"
"<div class=\\"callout callout-caution\\"><p><em>Alert!</em></p>
</div>"
`);
});

Expand All @@ -102,9 +102,9 @@ describe('parser', () => {
:art:
`)
).toMatchInlineSnapshot(`
"<p class=\\"callout callout-caution\\"><p>Message
"<div class=\\"callout callout-caution\\"><p>Message
:art:</p>
</p>"
</div>"
`);
});
});
6 changes: 3 additions & 3 deletions src/parser.ts
Expand Up @@ -31,7 +31,7 @@ export const parser: Remarkable.BlockParsingRule = (
while (nextLine < endLine) {
nextLine++;

const nextPos = state.bMarks[nextLine] + state.tShift[nextLine];
const nextPos = state.bMarks[nextLine] + state.blkIndent;
const nextMax = state.eMarks[nextLine];

if (state.src.charCodeAt(nextPos) !== marker) continue;
Expand All @@ -46,14 +46,14 @@ export const parser: Remarkable.BlockParsingRule = (
// Let register token and progress
state.tokens.push({
type: TOKENS.CALLOUT_OPEN,
level: state.level++,
level: state.level,
lines: [startLine, nextLine + (hasEnding ? 1 : 0)],
calloutType
} as any);
state.parser.tokenize(state, startLine + 1, nextLine);
state.tokens.push({
type: TOKENS.CALLOUT_CLOSE,
level: state.level--
level: state.level
} as any);
state.line = nextLine + (hasEnding ? 1 : 0);
return true;
Expand Down
4 changes: 2 additions & 2 deletions src/renderer.ts
Expand Up @@ -10,7 +10,7 @@ export const calloutOpenRenderer: Remarkable.Rule = (
env
) => {
const token = tokens[idx] as any;
return `<p class="callout callout-${token.calloutType}">`;
return `<div class="callout callout-${token.calloutType}">`;
};

/**
Expand All @@ -22,5 +22,5 @@ export const calloutCloseRenderer: Remarkable.Rule = (
options,
env
) => {
return `</p>`;
return `</div>`;
};

0 comments on commit 38d36bb

Please sign in to comment.