-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(widget-markdown): allow multiline shortcodes (#3066)
- Loading branch information
Showing
2 changed files
with
54 additions
and
2 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
packages/netlify-cms-widget-markdown/src/serializers/__tests__/remarkShortcodes.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { stripIndent } from 'common-tags'; | ||
import { remarkParseShortcodes } from '../remarkShortcodes'; | ||
|
||
// Stub of Remark Parser | ||
function process(value, plugins, processEat = () => {}) { | ||
const eat = () => processEat; | ||
function Parser() {} | ||
Parser.prototype.blockTokenizers = {}; | ||
Parser.prototype.blockMethods = []; | ||
remarkParseShortcodes.call({ Parser }, { plugins }); | ||
Parser.prototype.blockTokenizers.shortcode(eat, value); | ||
} | ||
|
||
describe('remarkParseShortcodes', () => { | ||
let editorComponent; | ||
|
||
beforeEach(() => { | ||
editorComponent = { | ||
id: 'foo', | ||
pattern: /bar/, | ||
fromBlock: jest.fn(), | ||
}; | ||
}); | ||
it('should parse shortcodes', () => { | ||
process('foo bar', [editorComponent]); | ||
expect(editorComponent.fromBlock).toHaveBeenCalledWith(expect.arrayContaining(['bar'])); | ||
}); | ||
it('should parse multiline shortcodes', () => { | ||
const value = stripIndent` | ||
foo | ||
bar | ||
`; | ||
process(value, [{ ...editorComponent, pattern: /^foo\nbar$/ }]); | ||
expect(editorComponent.fromBlock).toHaveBeenCalledWith(expect.arrayContaining(['foo\nbar'])); | ||
}); | ||
it('should parse multiline shortcodes with empty lines', () => { | ||
const value = stripIndent` | ||
foo | ||
bar | ||
`; | ||
process(value, [{ ...editorComponent, pattern: /^foo\n\nbar$/ }]); | ||
expect(editorComponent.fromBlock).toHaveBeenCalledWith(expect.arrayContaining(['foo\n\nbar'])); | ||
}); | ||
it('should produce shortcode node', () => { | ||
const processEat = jest.fn(); | ||
const shortcodeData = { bar: 'baz' }; | ||
const expectedNode = { type: 'shortcode', data: { shortcode: 'foo', shortcodeData } }; | ||
editorComponent.fromBlock = () => shortcodeData; | ||
process('foo bar', [editorComponent], processEat); | ||
expect(processEat).toHaveBeenCalledWith(expectedNode); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters