Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to use jQuery or JavaScript to automatically add a Gist Embed from a link for the original Gist. For example:-

Original Link Example Format

https://gist.github.com/user/a3efe9bb4706aea8b6e63bcbe7eebaab

Format for Gist Embed as shown on Github would be of the format:-

<script src="https://gist.github.com/user/a3efe9bb4706aea8b6e63bcbe7eebaab.js"></script>

What I want the code to do is search through a container div '.post-content' for all links that include the persistent URL value i.e. 'https://gist.github.com/user/' and then wrap the full URL as text in the script tags to finalise the embed format.

So far I have managed to find and check for matching URL (gistLink variable), but I'm not sure if it would iterate through each and every Github link and I haven't finalised it to add in the script tags either:-

<script>
jQuery(document).ready(function($) {
$('.post-content').each(function() {
var gistLink = $('a[href*="https://gist.github.com/user/"]').attr('href');
console.log(gistLink);
});
});
</script>

Your input is appreciated.

Thanks

question from:https://stackoverflow.com/questions/65945423/jquery-add-gist-embed-from-original-gist-link

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
119 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...