Skip to content
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

Additional options to allow more sophisticated examples #19

Closed
wants to merge 4 commits into from

Conversation

codepunkt
Copy link

@codepunkt codepunkt commented Aug 30, 2020

I'd like to style the existing children of the link. The goal is to start with a link like this:

[a link](http://example.com/some/path)

And be able to generate something like that:

<a href="http://example.com/some/path" rel="noopener noreferrer">
  <span class="link-content">a link</span>
  &#65279;
  <span class="link-hint">
    <img src="http://favicon-api.example.com/?domain=example.com">
  </span>
</a>

What's not possible today is:

  • Wrapping the "original content" into a specified wrapper (.link-content span from the example above)
  • Changing the content depending on original link href
  • Adding something in between the wrapped "original content" and the additional content that's wrapped into the .link-hint span

To reach the desired result, I'm using this with:

{
  rel: 'noopener noreferrer',
  content: linkUrl => [
    {
      type: 'element',
      tagName: 'img',
      properties: {
        src: `http://favicon-api.example.com/?domain=${new URL(linkUrl).hostname}`
      },
    },
  ],
  contentProperties: {
    class: 'link-hint',
  },
  beforeContent: {
    type: 'text',
    value: '',
  },
  transformChildren: (children) => {
    return [
      {
        type: 'fragment',
        children: [],
        data: {
          hName: 'span',
          hChildren: children,
          hProperties: {
            class: 'link-content',
          },
        },
      },
    ]
  },
}

I know it's a lot, but the result is really nice and it's not something i could do with the existing library.

Can you think of better/easier APIs to reach the results i want? Would love to discuss!

@codepunkt codepunkt changed the title transformChildren option Additional options to allow more sophisticated examples Sep 9, 2020
@codepunkt
Copy link
Author

Build fails because test coverage threshold is a miss.

@wooorm I can implement tests for everything when we have agreed on a good API.

@wooorm
Copy link
Member

wooorm commented Oct 3, 2020

Sorry, I was busy making micromark.

I see that your use case makes sense; but I’m unsure whether it makes sense in this project? This what, triples the API surface? That could be buggy, such as that content passed to transformChildren is mdast, as in that it includes emphasis nodes, but your injecting it into hChildren, which will make divs for unknown nodes.

Might it make sense to solve your problems in the hast/rehype space instead, with your own plugin, or with rehype-urls perhaps?

@wooorm
Copy link
Member

wooorm commented Nov 11, 2020

@codepunkt Ping! 😊

@codepunkt
Copy link
Author

codepunkt commented Dec 23, 2020

It might make sense to solve this elsewhere - i'm not deep enough into this space to comment on that. Also not sure how that would work - and as I'm using my fork on codepunkt.de, I'm kinda happy with it.

It's up to you if you think this sounds worthwhile or not 😀

@wooorm
Copy link
Member

wooorm commented Dec 28, 2020

It’s becoming a bit complex I think, so I’ll pass on it. Still, I’m not saying it’s in any way bad. Just: it could live somewhere else quite nicely!

Thanks for the work though, Christoph, and happy holidays!

@wooorm wooorm closed this Dec 28, 2020
@wooorm wooorm added the 👀 no/external This makes more sense somewhere else label Dec 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👀 no/external This makes more sense somewhere else
Development

Successfully merging this pull request may close these issues.

None yet

2 participants