Created
January 21, 2023 09:14
-
-
Save hochan222/825bd401fd4a032be0ea704cc846424b to your computer and use it in GitHub Desktop.
replace macro to tag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// {{ARIARole("button")}} => <a href='/ko/docs/Web/Accessibility/ARIA/Roles/button_role'><code>button</code></a> | |
const fs = require("fs"); | |
const path = require("path"); | |
const replaceInFile = (file) => { | |
const data = fs.readFileSync(file, "utf8"); | |
const result = data.replace(/\{\{\s*ARIARole\s*\(\s*['"]([^'"]+)['"]\s*\)\s*\}\}/g, "<a href='/ko/docs/Web/Accessibility/ARIA/Roles/$1_role'><code>$1</code></a>"); | |
fs.writeFileSync(file, result, "utf8"); | |
} | |
const walkSync = (dir, filelist = []) => { | |
fs.readdirSync(dir).forEach(file => { | |
if (path.extname(file) === '.md') { | |
filelist = filelist.concat(path.join(dir, file)); | |
} else if (fs.statSync(path.join(dir, file)).isDirectory()) { | |
filelist = walkSync(path.join(dir, file), filelist); | |
} | |
}); | |
return filelist; | |
}; | |
const files = walkSync("."); | |
files.forEach(file => { | |
replaceInFile(file); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment