Refined-github: Embedded Gists destroy content

Created on 16 Apr 2018  路  3Comments  路  Source: sindresorhus/refined-github

It seems that the Gist embedding functionality only looks for lines where a Gist was linked... without checking if there is _other_ content on the line.

For the following content:

...in lacinia dolor vitae purus euismod euismod. Pellentesque ac turpis nulla. Morbi elementum eros in rutrum dignissim.

Lorem ipsum dolor sit amet, [consectetur adipiscing elit](https://gist.github.com/user/hash). Ut id ipsum euismod, maximus leo a, facilisis tortor. Phasellus et nulla egestas, ornare ipsum nec, congue mi. Suspendisse dolor arcu, lobortis ut dui ut, ultrices accumsan nisl.

Nam sodales ut ante et rutrum. Donec sit amet tortor...

The entire middle paragraph gets replaced with the embedded Gist, hiding the content for anyone that has this plugin installed.

bug good first issue help wanted

Most helpful comment

It's expected that only links on their own line are selected:

https://github.com/sindresorhus/refined-github/blob/1e2428126e1e4eabe4e822eac6f2efd9263f02cc/source/features/embed-gist-inline.js#L42

But the :only-child selector does not work when the sibling is just text (because it's not really a sibling) so there just needs to be a better way to determine if the link is on its own line. I'll take a look at it.

All 3 comments

You're right, it's caused by parentNode here:

https://github.com/sindresorhus/refined-github/blob/1e2428126e1e4eabe4e822eac6f2efd9263f02cc/source/features/embed-gist-inline.js#L26

The reason was that the embed would be created in a p instead of inside an a element, but probably that's not necessary.

PR welcome!

It's expected that only links on their own line are selected:

https://github.com/sindresorhus/refined-github/blob/1e2428126e1e4eabe4e822eac6f2efd9263f02cc/source/features/embed-gist-inline.js#L42

But the :only-child selector does not work when the sibling is just text (because it's not really a sibling) so there just needs to be a better way to determine if the link is on its own line. I'll take a look at it.

Test comment

...in lacinia dolor vitae purus euismod euismod. Pellentesque ac turpis nulla. Morbi elementum eros in rutrum dignissim.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut id ipsum euismod, maximus leo a, facilisis tortor. Phasellus et nulla egestas, ornare ipsum nec, congue mi. Suspendisse dolor arcu, lobortis ut dui ut, ultrices accumsan nisl.

Nam sodales ut ante et rutrum. Donec sit amet tortor...

This should still embed:

https://gist.github.com/rotemtam/b4474f732674a9fd5884719d8c5bdf3e

Was this page helpful?
0 / 5 - 0 ratings

Related issues

juliocanares picture juliocanares  路  3Comments

olso picture olso  路  3Comments

hkdobrev picture hkdobrev  路  3Comments

sindresorhus picture sindresorhus  路  3Comments

hkdobrev picture hkdobrev  路  3Comments