diff --git a/src/code-block/transforms.js b/src/code-block/transforms.js index fc1a42a..8da9c09 100644 --- a/src/code-block/transforms.js +++ b/src/code-block/transforms.js @@ -21,6 +21,16 @@ export default { node.children.length === 1 && node.firstChild.nodeName === 'CODE' ), + transform( node ) { + const content = node.firstChild.textContent; + const [ startingMatch, language ] = content.match( /^```(\w+)?\n/ ) || [ null, null ]; + const attributes = language ? { language } : {}; + + // Extract content without backticks and (optionally) language. + attributes.content = startingMatch ? content.replace( startingMatch, '' ).replace( /```\s*$/, '' ) : content; + + return createBlock( 'syntaxhighlighter/code', attributes ); + }, schema: { pre: { children: {