@@ -420,15 +420,14 @@ public String genericCodeBlock(String text) {
420
420
}
421
421
422
422
private TextEditor doTableBlocks (TextEditor markup ) {
423
- doAnchors (markup );
424
423
Pattern p = Pattern .compile (
425
424
"(\\ |(?:[^\\ n]*\\ |)+\\ n" +
426
425
"\\ |(?:[ ]*-+[ ]*\\ |)+\\ n" +
427
426
"(?:\\ |(?:[^\\ n]*\\ |)+[^\n ]*\\ n)+)" , Pattern .DOTALL );
428
427
return markup .replaceAll (p , new Replacement () {
429
428
@ Override
430
429
public String replacement (Matcher m ) {
431
- String tableMd = m .group (1 );
430
+ String tableMd = getAnchorsString ( m .group (1 ) );
432
431
String [] lines = tableMd .split ("\\ n" );
433
432
StringBuilder sb = new StringBuilder ();
434
433
sb .append ("<table class=\" table\" " );
@@ -787,6 +786,47 @@ private void doLocalImage(TextEditor text) {
787
786
text .update (sb .toString ());
788
787
}
789
788
789
+ private String getAnchorsString (String s ) {
790
+ Pattern internalLink = Pattern .compile ("(" +
791
+ "\\ [(.*?)\\ ]" + // Link text = $2
792
+ "[ ]?(?:\\ n[ ]*)?" +
793
+ "\\ [(.*?)\\ ]" + // ID = $3
794
+ ")" );
795
+
796
+ return replaceAll (s , internalLink , new Replacement () {
797
+ @ Override
798
+ public String replacement (Matcher m ) {
799
+ String replacementText ;
800
+ String wholeMatch = m .group (1 );
801
+ String linkText = m .group (2 );
802
+ String id = m .group (3 ).toLowerCase ();
803
+ if ("" .equals (id )) { // for shortcut links like [this][]
804
+ id = linkText .toLowerCase ();
805
+ }
806
+
807
+ LinkDefinition defn = linkDefinitions .get (id );
808
+ if (defn != null ) {
809
+ String url = defn .getUrl ();
810
+ // protect emphasis (* and _) within urls
811
+ url = url .replaceAll ("\\ *" , CHAR_PROTECTOR .encode ("*" ));
812
+ url = url .replaceAll ("_" , CHAR_PROTECTOR .encode ("_" ));
813
+ String title = defn .getTitle ();
814
+ String titleTag = "" ;
815
+ if (title != null && !title .equals ("" )) {
816
+ // protect emphasis (* and _) within urls
817
+ title = title .replaceAll ("\\ *" , CHAR_PROTECTOR .encode ("*" ));
818
+ title = title .replaceAll ("_" , CHAR_PROTECTOR .encode ("_" ));
819
+ titleTag = " title=\" " + title + "\" " ;
820
+ }
821
+ replacementText = "<a href=\" " + url + "\" " + titleTag + ">" + linkText + "</a>" ;
822
+ } else {
823
+ replacementText = wholeMatch ;
824
+ }
825
+ return replacementText ;
826
+ }
827
+ });
828
+ }
829
+
790
830
private TextEditor doAnchors (TextEditor markup ) {
791
831
// Internal references: [link text] [id]
792
832
Pattern internalLink = Pattern .compile ("(" +
0 commit comments