Browse Source

fix(openLinksInNewWindow): hash links are not affected by the option

Closes #457
Estevao Soares dos Santos 7 years ago
parent
commit
11936ecb77

+ 3 - 1
dist/showdown.js

@@ -2598,7 +2598,9 @@ showdown.subParser('anchors', function (text, options, globals) {
       result += ' title="' + title + '"';
     }
 
-    if (options.openLinksInNewWindow) {
+    // optionLinksInNewWindow only applies
+    // to external links. Hash links (#) open in same page
+    if (options.openLinksInNewWindow && !/^#/.test(url)) {
       // escaped _
       result += ' target="¨E95Eblank"';
     }

File diff suppressed because it is too large
+ 0 - 0
dist/showdown.js.map


File diff suppressed because it is too large
+ 0 - 0
dist/showdown.min.js


File diff suppressed because it is too large
+ 0 - 0
dist/showdown.min.js.map


+ 3 - 1
src/subParsers/anchors.js

@@ -44,7 +44,9 @@ showdown.subParser('anchors', function (text, options, globals) {
       result += ' title="' + title + '"';
     }
 
-    if (options.openLinksInNewWindow) {
+    // optionLinksInNewWindow only applies
+    // to external links. Hash links (#) open in same page
+    if (options.openLinksInNewWindow && !/^#/.test(url)) {
       // escaped _
       result += ' target="¨E95Eblank"';
     }

+ 1 - 0
test/features/openLinksInNewWindow/hash-links-open-in-same-page.html

@@ -0,0 +1 @@
+<p>this link is in the <a href="#same-page">same page</a></p>

+ 1 - 0
test/features/openLinksInNewWindow/hash-links-open-in-same-page.md

@@ -0,0 +1 @@
+this link is in the [same page](#same-page)

Some files were not shown because too many files changed in this diff