Skip to content

Adding a div compiler#2

Closed
datapimp wants to merge 2 commits intoremarkjs:masterfrom
datapimp:master
Closed

Adding a div compiler#2
datapimp wants to merge 2 commits intoremarkjs:masterfrom
datapimp:master

Conversation

@datapimp
Copy link
Contributor

@datapimp datapimp commented Sep 9, 2015

When developing plugins which modify the ast, I wanted the ability to create simple wrapper divs.

I just noticed the new functionality where you can specify a custom element name and I think this is a good improvement overall. What wasn't clear to me was which element I should use as the base, if what I wanted was just a simple div which wrapped whatever children the node has.

Would be happy to clean up and simplify the implementation or hear about better approaches to solving this.

@wooorm
Copy link
Member

wooorm commented Sep 9, 2015

Nice approach.
However, instead of making 'div' nodes standard and becoming some sort of HTML syntax tree,
I recommend the following: inside 'visit', there's a test if 'type' exists on 'visitors'. If not, an error is thrown. instead of throwing, maybe test if 'node.data.htmlName' exists, if it does pass it to a function similar to the 'div' one you just created, but maybe call it 'unknown' or something.

In that case, there won't be any issues popping up here for section nodes, main nodes, article nodes...

P.S. Line 632/633 in your pr are superfluous

@datapimp
Copy link
Contributor Author

datapimp commented Sep 9, 2015

What about something like this? In a plugin we have:

exports = function (mdast, options){
  var compiler = mdast.Compiler

  compiler.renderer('section', function(node){

  })

return function(ast){

  }
}

basically some way of accessing the compiler and registering a new renderer function.

@wooorm
Copy link
Member

wooorm commented Sep 9, 2015

That's in fact possible :) in an 'attacher' there's access to mdast, which has access to the compiler

@wooorm wooorm closed this in f3b35fe Sep 9, 2015
@wooorm
Copy link
Member

wooorm commented Sep 9, 2015

I just woke up when I wrote the previous reply. Hope the code in f3b35fe better shows what I meant ;)

@datapimp
Copy link
Contributor Author

datapimp commented Sep 9, 2015

this is great -- thank you

@wooorm wooorm added the 🙋 no/question This does not need any changes label Aug 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🙋 no/question This does not need any changes

Development

Successfully merging this pull request may close these issues.

2 participants