| 83 | }, |
| 84 | |
| 85 | codeBlock(node: MdNode) { |
| 86 | const { fenceLength, info } = node as CodeBlockMdNode; |
| 87 | const infoWords = info ? info.split(/\s+/) : []; |
| 88 | const preClasses = []; |
| 89 | const codeAttrs: TokenAttrs = {}; |
| 90 | |
| 91 | if (fenceLength > 3) { |
| 92 | codeAttrs['data-backticks'] = fenceLength; |
| 93 | } |
| 94 | if (infoWords.length > 0 && infoWords[0].length > 0) { |
| 95 | const [lang] = infoWords; |
| 96 | |
| 97 | preClasses.push(`lang-${lang}`); |
| 98 | codeAttrs['data-language'] = lang; |
| 99 | } |
| 100 | |
| 101 | return [ |
| 102 | { type: 'openTag', tagName: 'pre', classNames: preClasses }, |
| 103 | { type: 'openTag', tagName: 'code', attributes: codeAttrs }, |
| 104 | { type: 'text', content: node.literal! }, |
| 105 | { type: 'closeTag', tagName: 'code' }, |
| 106 | { type: 'closeTag', tagName: 'pre' }, |
| 107 | ]; |
| 108 | }, |
| 109 | |
| 110 | customInline(node: MdNode, { origin, entering, skipChildren }: Context) { |
| 111 | const { info } = node as CustomInlineMdNode; |