Skip to content

Instantly share code, notes, and snippets.

@hochan222
Created January 21, 2023 09:14
Show Gist options
  • Save hochan222/825bd401fd4a032be0ea704cc846424b to your computer and use it in GitHub Desktop.
Save hochan222/825bd401fd4a032be0ea704cc846424b to your computer and use it in GitHub Desktop.
replace macro to tag
// {{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