-
-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there any way to get outerHTML of the node? #10
Comments
That's doable, although I'm not sure why you'd use a |
Try this: const page = `<figure>
<img src="/media-narrow.png" width="800" height="400" alt="A stacked component, image on the top, text below" />
<figcaption>The component as a single column</figcaption>
</figure>`;
const breakdance = new Breakdance();
breakdance.set('figure', function(node) {
const context = {};
const stack = [];
visit(node, child => {
switch (child.type) {
case 'figcaption.open':
stack.push(child);
break;
case 'figcaption.close':
stack.pop();
break;
case 'img':
context.img = child;
break;
case 'text':
if (stack.length) {
context.figcaption = child;
// console.log('inside <figcaption>', [child.val]);
} else {
// console.log('outside <figcaption>', [child.val]);
}
break;
default: {
// console.log('OTHER:', child.type)
break;
}
}
});
const img = context.img.attribs;
const value = `![${img.alt}][${context.figcaption.val}]\n[${context.figcaption.val}]: ${img.src} "${img.alt}"`;
this.emit(value, node);
});
const md = breakdance.render(page);
console.log(md);
function visit(node, fn) {
fn(node);
return node.nodes ? mapVisit(node, fn) : node;
}
function mapVisit(node, fn) {
for (const child of node.nodes) visit(child, fn);
return node;
} Basically, since the |
Hi,
I want render some nodes as html … well leaving them as is. Is it possible?
Also I think that would be nice transform this to:
But not sure how to solve this
The text was updated successfully, but these errors were encountered: