Open jberger opened 3 years ago
Without changing the selectors, LE could support <pre><code>
by changing
to
$self->{paste} = $tmp->all_text;
or by adding something like
if (my $code = $tmp->at('code')) { $tmp = $code }
above it. I'd be happy to put together a PR for either solution if you'd accept them @jhthorsen . Just let me know.
(adding a selector for body pre > code
would be fine by me too remember).
I've been giving this some more thought, and I think we should "break" LinkEmbedder by adding the fix you suggest. By "breaking" I mean that it will probably find some non-pastebin sites and render them as a pastebin. I'm thinking about blogs with code examples and such. I do think breaking it, and then later on adding better tests would be better than holding this change back.
Feel free to open a PR under these conditions (if possible)
About the "document in the code" point: I should've done that myself, but I haven't so now we're in this situation 😞
Seems like all_text has already been implemented, so I'm going to close this issue.
Let me know if I forgot something @jberger.
...or just open a PR with a sloppy "pre" lookup, and I'll merge it.
I'm reopening this, since https://svelte.dev/docs is a case where it gets expanded to a \
tag when it shouldn't imo. Might also discuss if https://svelte.dev/docs#4_Prefix_stores_with_$_to_access_their_values should get rendered as a code example.Could this be fixed simply by checking if there's a "bunch" of \
tags? Where bunch is more than 1 or 2..?And even this issue: Looks like LinkEmbedder finds the code link in https://github.com/convos-chat/linkembedder/issues/24#issuecomment-812595658 - Thought that's probably Github.pm specific.
A user told me that they have a home-rolled pastebin that they use that doesn't get embedded. While we can't expect to support every little bin, I think the situation as it exists could be somewhat improved.
The fallback in basic for generic pastetbins uses oddly-specific selectors, which I'm assuming conform to some specific paste sites. Notably the fact that it uses direct descendent selectors
body > pre
andbody > div > pre
is somewhat limiting. However in the specific case I'm looking at it wouldn't be insurmountable.The site would work with a selector
body > div > pre > code
. That selector is again rather specific, it would be odd to require a div tag like that, it could bebody pre > code
to be a bit more accepting, though it would have to be attempted beforebody > div > pre
or it would never get there. Alternatively it could optionally look for acode
tag inside the resulting selector and walk into it if present. Or it could useall_text
rather thantext
to get the tag contents. Are any of these suggestions acceptable?