กรณีที่ตัวแปลภาษา markdown ของคุณไม่รองรับคำสั่งพิเศษในการเปิดลิงก์ใน tab ใหม่ มีวิธีแก้ไข ดังนี้
อาศัยความสามารถของ markdown ที่สามารถแทรกคำสั่งที่อยู่ในไฟล์ html เข้าไปได้ เราก็สามารถแทรกคำสั่งด้านล่างนี้เข้าไปในเอกสาร markdown ก็จะทำให้ลิงก์ภายนอก ที่ขึ้นด้นด้วย http หรือ https เปิดลิงก์ใน tab ใหม่ได้
<script>
document.addEventListener('DOMContentLoaded', function() {
// Auto-add target="_blank" to all external links
var links = document.querySelectorAll('a');
var currentDomain = window.location.hostname;
links.forEach(function(link) {
var href = link.getAttribute('href');
if (href && (href.startsWith('http://') || href.startsWith('https://'))) {
var linkDomain = href.split('/')[2];
if (linkDomain !== currentDomain && !linkDomain.endsWith('.' + currentDomain)) {
link.setAttribute('target', '_blank');
link.setAttribute('rel', 'noopener noreferrer');
}
}
});
});
</script>