Skip to content

Commit

Permalink
fix: should only listen for 4 spaces to make code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
mesqueeb committed May 26, 2023
1 parent 8e43fa2 commit c636884
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parsers/poetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import { encodeAttr, wrap } from '../utils'

export const poetry: ParserDef = {
name: 'poetry',
regex: /(?:^|\n+)(?:\t| {2,})(?<content>.+)+\n*/,
regex: /(?:^|\n+)(?:\t| {4})(?<content>.+)+\n*/,
handler: ({ content }) => `<pre class="code poetry">${wrap('code', encodeAttr(content))}</pre>`,
}
22 changes: 22 additions & 0 deletions test/codeQuotes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,28 @@ describe('code & quotes', () => {
)
})

test('parses tabs as a code poetry block & retains inner tabs', () => {
expect(starkdown('\t\tvar a = 1')).toEqual(
'<pre class="code poetry"><code>\tvar a = 1</code></pre>'
)
})

test('does not parses two spaces as a code poetry block', () => {
expect(starkdown(' var a = 1')).toEqual('<p>var a = 1</p>')
})

test('parses four spaces as a code poetry block', () => {
expect(starkdown(' var a = 1')).toEqual(
'<pre class="code poetry"><code>var a = 1</code></pre>'
)
})

test('parses four spaces as a code poetry block & retains inner spaces', () => {
expect(starkdown(' var a = 1')).toEqual(
'<pre class="code poetry"><code> var a = 1</code></pre>'
)
})

test('escapes code/quote blocks', () => {
expect(starkdown('```\n<foo>\n```')).toEqual(
'<pre class="code "><code>&lt;foo&gt;</code></pre>'
Expand Down

0 comments on commit c636884

Please sign in to comment.