(block)
| 15 | * @return {string|null} |
| 16 | */ |
| 17 | export function getLanguageForBlock(block) { |
| 18 | |
| 19 | // If this doesn't have a language but the parent does then use that. |
| 20 | // |
| 21 | // This means if for example you have: <pre data-language="php"> |
| 22 | // with a bunch of <code> blocks inside then you do not have |
| 23 | // to specify the language for each block. |
| 24 | let language = block.getAttribute('data-language') || block.parentNode.getAttribute('data-language'); |
| 25 | |
| 26 | // This adds support for specifying language via a CSS class. |
| 27 | // |
| 28 | // You can use the Google Code Prettify style: <pre class="lang-php"> |
| 29 | // or the HTML5 style: <pre><code class="language-php"> |
| 30 | if (!language) { |
| 31 | const pattern = /\blang(?:uage)?-(\w+)/; |
| 32 | const match = block.className.match(pattern) || block.parentNode.className.match(pattern); |
| 33 | |
| 34 | if (match) { |
| 35 | language = match[1]; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | if (language) { |
| 40 | return language.toLowerCase(); |
| 41 | } |
| 42 | |
| 43 | return null; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Determines if two different matches have complete overlap with each other |
no outgoing calls
no test coverage detected