export const wrapLines = (content, language) => { const isValidLanguage = /^[a-z\d\-_]+$/.test(language); // To prevent the possibility of a vulnerability we only allow languages that contain alphanumeric characters ([a-z\d), dashes (-) or underscores (_). return ( content && content .split('\n') .map((line, i) => { let formattedLine; const attributes = `id="LC${i + 1}" lang="${isValidLanguage ? language : ''}"`; if (line.includes('```bash * example (after): ```bash */ formattedLine = line.replace(/(?=class="hljs)/, `${attributes} `); } else { formattedLine = `${line}`; } return formattedLine; }) .join('\n') ); };