1234567891011121314151617 |
- const extractCodeBlocks = (str) => {
- if (!str) {
- return [];
- }
-
- const matches = str.match(/```[\s\S]*?\n([\s\S]*?)\n```/g);
-
- return matches
- ? matches.map((match) =>
- match.replace(/```[\s\S]*?\n([\s\S]*?)\n```/, "$1").trim()
- )
- : [];
- };
- module.exports = { extractCodeBlocks };
|