Support tag generation from markdown.

This commit is contained in:
Dorian 2019-05-06 09:01:07 -04:00
parent 9f9f2857fd
commit 3bd23f8d58
1 changed files with 22 additions and 7 deletions

View File

@ -10,18 +10,33 @@ Greeting.propTypes = {
name: PropTypes.string,
};
export const tagName = 'rookeries-hello';
export const tagName = 'hello-world';
export const markdownPattern = new RegExp(':: hello (.*)::');
export const replacement = (match, p1) => {
console.log(`Got ${p1.trim()}.`);
// const tags = p1.split(' ');
// for (let tag in tags) {
// if (!tag.contains('=')) {
// console.log(`Skipping "${tag}" as not an attribute`);
// }
// }
const tags = p1.trim().split(' ');
let validTags = [];
for (let tag of tags) {
if (!tag.includes('=')) {
console.log(`Skipping "${tag}" as not an attribute`);
continue;
}
let [head, value, ..._ ] = tag.split('=');
value = value.trim();
if (value !== '' && (head === 'name' || head === 'id')) {
validTags.push(`${head}="${value}"`);
} else {
console.log(`Unsupported attribute ${head}="${value}"`);
}
}
if (validTags.length > 0) {
return `<${tagName} ${validTags.join(' ')}></${tagName}>`;
}
return `<${tagName}></${tagName}>`;
};