Support tag generation from markdown.
This commit is contained in:
parent
9f9f2857fd
commit
3bd23f8d58
|
@ -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}>`;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue