From fe3bb8d4a12b194615fd40b1bd5ca6fda0e6dc5b Mon Sep 17 00:00:00 2001 From: mbehzad Date: Fri, 5 Apr 2024 12:51:44 +0200 Subject: [PATCH] fix(pv-stylemark): fix regex extracting css code block the regexes where expecting always an empty space after .css which is only the case when a hidden attribute is used, it allowed for the info string to come on the next line as the code fence, only allowed ../ but not ./ --- packages/pv-stylemark/tasks/lsg/getLsgData.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/pv-stylemark/tasks/lsg/getLsgData.js b/packages/pv-stylemark/tasks/lsg/getLsgData.js index 4719a0e..ab58bb5 100644 --- a/packages/pv-stylemark/tasks/lsg/getLsgData.js +++ b/packages/pv-stylemark/tasks/lsg/getLsgData.js @@ -8,11 +8,11 @@ const { resolveApp, getAppConfig } = require("../../helper/paths"); const getStylesData = stylesMatch => { const exampleKeys = stylesMatch - .match(/^\s*[a-zA-Z\-\d_]+.css/g) - .map(match => match.replace(/\s/g, "").replace(/.css$/g, "")); + .match(/^ *[\w\-]+\.css/) + .map(match => match.replace(/ /g, "").replace(/\.css$/g, "")); if (exampleKeys.length === 0) return null; - const styleContent = stylesMatch.replace(/^\s*[a-zA-Z\-\d_]+.css\s+(hidden)?\s+/g, "").trim(); + const styleContent = stylesMatch.replace(/^ *[\w\-]+\.css( +hidden)?\s+/g, "").trim(); return { exampleKey: exampleKeys[0], styleContent, @@ -59,14 +59,14 @@ const getLsgDataForPath = async (path, componentsSrc) => { const { attributes: frontmatterData, body: fileContentBody } = frontmatter(fileContent); - const stylesRegex = new RegExp(/```\s*([a-zA-Z\-\d_]+\.css (hidden)?)\s*[^```]+```/g); + const stylesRegex = new RegExp(/``` *[\w\-]+\.css( +hidden)? *\n+[^```]+```/g); const stylesMatches = fileContentBody.match(stylesRegex) || []; const styles = stylesMatches.map(match => match.replace(/```/g, "")); const stylesList = styles.map(getStylesData); - const exampleRegex = new RegExp(/```\s*[a-zA-Z\-\d_]+:(\.\.\/)*[a-zA-Z\-\d_/]+\.[a-z]+\s*```/g); + const exampleRegex = new RegExp(/``` *[\w\-]+:(\.?\.\/)*[\w\-/]+\.[a-z]+\s*\n```/g); const exampleMatches = fileContentBody.match(exampleRegex) || []; const examples = exampleMatches.map(match => match.replace(/```/g, "").replace(/\s/g, ""));