Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 4 space code block not render correctly #34

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/__tests__/mocks/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,25 @@ export const CODE_WITH_DECORATION = [
},
];

export const CODE_WITH_4_SPACES = [
{
id: '479c7b34-6c22-4f2d-b947-8f47d02b48d6',
type: 'code',
properties: { language: 'Python' },
format: {},
children: [] as Block[],
decorableTexts: [
{
text: `def print_pattern():
size = 4
for i in range(size):
print("*" * size)`,
decorations: [],
},
],
},
];

export const QUOTE = [
{
id: 'e0a0cfa3-1f64-438b-ac79-95e5c7ad4565',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class CodeBlockToHtml implements ToHtml {
const languageClass = this._language ? `class="language-${this._language}"` : '';

return Promise.resolve(
`<pre><code ${languageClass}>${blockToInnerText(this._block).replace(/(\s{4}|\t)/g, ' ')}</code></pre>`,
`<pre><code ${languageClass}>${blockToInnerText(this._block).replace(/\t/g, ' ')}</code></pre>`,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,19 @@ describe('#convert', () => {
);
});
});

describe('When there is 4 space indent code', () => {
it('correctly preserve the 4 spaces and return html with pre tag and code tag inside', async () => {
const html = await makeSut(BlockMocks.CODE_WITH_4_SPACES).convert();

expect(html).toBe(
`<pre><code class="language-python">def print_pattern():
size = 4
for i in range(size):
print("*" * size)</code></pre>`
)
})
})
});

describe('When single quote block is given', () => {
Expand Down