mirror of
https://github.com/len0rd/personal-website.git
synced 2025-04-19 21:11:58 -04:00
trying to add class to tag while keeping id. having difficulty with async filter function returning value before I'm done doing stuff
This commit is contained in:
parent
392156bf6c
commit
8bbd4dbcf7
|
@ -15,3 +15,19 @@ iframe {
|
||||||
margin-top: 2vh;
|
margin-top: 2vh;
|
||||||
margin-bottom: 2vh;
|
margin-bottom: 2vh;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
padding-left: 5%;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul {
|
||||||
|
margin-left: 5%;
|
||||||
|
}
|
||||||
|
|
||||||
|
ol {
|
||||||
|
margin-left: 5%;
|
||||||
|
}
|
||||||
|
|
||||||
|
li p {
|
||||||
|
padding-left: 0;
|
||||||
|
}
|
45
prestart.js
45
prestart.js
|
@ -5,12 +5,51 @@
|
||||||
// md changes), it is more efficient in
|
// md changes), it is more efficient in
|
||||||
// that we aren't converting MD -> ejs
|
// that we aren't converting MD -> ejs
|
||||||
// on EVERY request
|
// on EVERY request
|
||||||
var showdown = require('showdown'),
|
const showdown = require('showdown'),
|
||||||
converter = new showdown.Converter(),
|
|
||||||
fs = require('fs'),
|
fs = require('fs'),
|
||||||
mkdirp = require('mkdirp'),
|
mkdirp = require('mkdirp'),
|
||||||
inputDir = './project_writeups/',
|
inputDir = './project_writeups/',
|
||||||
outputDir = './views/partials/md/';
|
outputDir = './views/partials/md/',
|
||||||
|
classMap = {
|
||||||
|
h1: 'display-1'
|
||||||
|
};
|
||||||
|
|
||||||
|
//handles adding classes to specific
|
||||||
|
//tag types automatically
|
||||||
|
const bindings = Object.keys(classMap)
|
||||||
|
.map(key => ({
|
||||||
|
|
||||||
|
|
||||||
|
type: 'output',
|
||||||
|
regex: new RegExp(`<${key}(.*?)>`, 'g'),
|
||||||
|
replace: `<${key} class="${classMap[key]}">`
|
||||||
|
}));
|
||||||
|
|
||||||
|
const addClass = {
|
||||||
|
type: 'output',
|
||||||
|
filter: text => {
|
||||||
|
var modifiedText = text;
|
||||||
|
Object.keys(classMap).forEach(function(key) {
|
||||||
|
var regex = new RegExp(`<${key}(.*?)>`, 'g');
|
||||||
|
matcher = regex.exec(modifiedText);
|
||||||
|
|
||||||
|
while (matcher != null && !matcher[0].includes(classMap[key])) {
|
||||||
|
console.log(matcher[0]);
|
||||||
|
|
||||||
|
var restOfTag = matcher[1];
|
||||||
|
modifiedText.replace(matcher[0], `<${key} class="${classMap[key]}" ${restOfTag}>`);
|
||||||
|
|
||||||
|
matcher = regex.exec(modifiedText);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return modifiedText;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const converter = new showdown.Converter({
|
||||||
|
extensions: [addClass]//bindings]//,
|
||||||
|
// noHeaderId: false // important to add this, else regex match doesn't work
|
||||||
|
});
|
||||||
|
|
||||||
mkdirp(outputDir, (err) => {
|
mkdirp(outputDir, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
Loading…
Reference in a new issue