update the code block page, add tests
This commit is contained in:
@@ -1,5 +1,48 @@
|
|||||||
context('/api/extensions/code-block', () => {
|
context('/api/extensions/code-block', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
cy.visit('/api/extensions/code-block')
|
cy.visit('/api/extensions/code-block')
|
||||||
|
|
||||||
|
cy.get('.ProseMirror').window().then(window => {
|
||||||
|
const { editor } = window
|
||||||
|
editor.setContent('<p>Example Text</p>')
|
||||||
|
editor.focus().selectAll()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('code-block', () => {
|
||||||
|
it('the button should make the selected line a code block', () => {
|
||||||
|
cy.get('.demo__preview button:first').click({ force: true })
|
||||||
|
cy.get('.ProseMirror').contains('pre', 'Example Text')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('the button should toggle the code block', () => {
|
||||||
|
cy.get('.demo__preview button:first').click({ force: true })
|
||||||
|
cy.get('.ProseMirror').contains('pre', 'Example Text')
|
||||||
|
cy.get('.demo__preview button:first').click({ force: true })
|
||||||
|
cy.get('.ProseMirror pre').should('not.exist')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('the keyboard shortcut should make the selected line a code block', () => {
|
||||||
|
cy.get('.ProseMirror').type('{control}{shift}\\', {force: true})
|
||||||
|
cy.get('.ProseMirror').contains('pre', 'Example Text')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('the keyboard shortcut should toggle the code block', () => {
|
||||||
|
cy.get('.ProseMirror').type('{control}{shift}\\', {force: true})
|
||||||
|
cy.get('.ProseMirror').contains('pre', 'Example Text')
|
||||||
|
cy.get('.ProseMirror').type('{control}{shift}\\', {force: true})
|
||||||
|
cy.get('.ProseMirror pre').should('not.exist')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should make a code block from markdown shortcuts', () => {
|
||||||
|
cy.get('.ProseMirror').window().then(window => {
|
||||||
|
const { editor } = window
|
||||||
|
editor.clearContent()
|
||||||
|
|
||||||
|
cy.get('.ProseMirror')
|
||||||
|
.type('``` {enter}Code', {force: true})
|
||||||
|
.contains('pre', 'Code')
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -36,8 +36,19 @@ export default {
|
|||||||
CodeBlock(),
|
CodeBlock(),
|
||||||
],
|
],
|
||||||
content: `
|
content: `
|
||||||
<p>This is a code block:</p>
|
<p>That’s a boring paragraph followed by a fenced code block:</p>
|
||||||
<pre><code>const foo = 'bar'</code></pre>
|
<pre><code>for (var i=1; i <= 20; i++)
|
||||||
|
{
|
||||||
|
if (i % 15 == 0)
|
||||||
|
console.log("FizzBuzz");
|
||||||
|
else if (i % 3 == 0)
|
||||||
|
console.log("Fizz");
|
||||||
|
else if (i % 5 == 0)
|
||||||
|
console.log("Buzz");
|
||||||
|
else
|
||||||
|
console.log(i);
|
||||||
|
}</code></pre>
|
||||||
|
<p>Press Command/Ctrl + Enter to leave the fenced code block and continue typing in boring paragraphs.
|
||||||
`,
|
`,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
# CodeBlock
|
# CodeBlock
|
||||||
Enables you to use the `<pre>` HTML tag in the editor.
|
With the CodeBlock extension you can add fenced code blocks to your documents. It’ll wrap the code in `<pre>` and `<code>` HTML tags.
|
||||||
|
|
||||||
|
Type three backticks and a space (`\`` ) and a code block is instantly added for you.
|
||||||
|
|
||||||
|
::: warning Restrictions
|
||||||
|
The CodeBlock extension doesn’t come with styling and has no syntax highlighting built-in. It’s on our roadmap though.
|
||||||
|
:::
|
||||||
|
|
||||||
## Options
|
## Options
|
||||||
| Option | Type | Default | Description |
|
| Option | Type | Default | Description |
|
||||||
|
|||||||
@@ -124,7 +124,6 @@
|
|||||||
link: /api/extensions/code
|
link: /api/extensions/code
|
||||||
- title: CodeBlock
|
- title: CodeBlock
|
||||||
link: /api/extensions/code-block
|
link: /api/extensions/code-block
|
||||||
draft: true
|
|
||||||
# - title: CodeBlockHighlight
|
# - title: CodeBlockHighlight
|
||||||
# link: /api/extensions/code-block-highlight
|
# link: /api/extensions/code-block-highlight
|
||||||
# draft: true
|
# draft: true
|
||||||
|
|||||||
Reference in New Issue
Block a user