Cards with browser support (WIP)

This commit is contained in:
Angelos Chalaris
2019-08-23 14:11:46 +03:00
parent d12e35a5c8
commit 1c0fa2c624
4 changed files with 76 additions and 20 deletions

View File

@ -22,6 +22,36 @@ const getTextualContent = (str, noExplain = false) => {
return results[1];
};
// Gets the explanation for a snippet file.
const getExplanation = str => {
const regex = /<h4>\s*Explanation\s*<\/h4>([\s\S]*)<h4>/g;
const results = [];
let m = null;
while ((m = regex.exec(str)) !== null) {
if (m.index === regex.lastIndex) regex.lastIndex += 1;
m.forEach((match, groupIndex) => {
results.push(match);
});
}
return results[1].replace(/\r\n/g, '\n');
};
// Gets the browser support for a snippet file.
const getBrowserSupport = str => {
const regex = /<h4>\s*Browser [s|S]upport\s*<\/h4>([\s\S]*)/g;
const results = [];
let m = null;
while ((m = regex.exec(str)) !== null) {
if (m.index === regex.lastIndex) regex.lastIndex += 1;
m.forEach((match, groupIndex) => {
results.push(match);
});
}
return results[1].replace(/\r\n/g, '\n');
};
// Gets the code blocks in a gatsby page
const getCodeBlocks = str => {
const regex = /<pre[.\S\s]*?<\/pre>/g;
@ -131,5 +161,7 @@ module.exports = {
getCodeBlocks,
optimizeNodes,
optimizeAllNodes,
getExplanation,
getRawCodeBlocks,
getBrowserSupport
};