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

Categories

0 votes
111 views
in Technique[技术] by (71.8m points)

javascript - jQuery Add Gist Embed from original Gist Link

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

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

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...