Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add more link types to enable branch-stable page and attachment links

  • Loading branch information...
commit 416407f5b130e28bd013beb6c02cb8b3bdba23ea 1 parent f18a3e5
Maik Schreiber authored
44 de.blizzy.documentr/src/main/java/de/blizzy/documentr/web/markdown/DocumentrLinkRenderer.java
@@ -24,10 +24,19 @@
24 24 import org.pegdown.ast.ExpLinkNode;
25 25 import org.pegdown.ast.Node;
26 26 import org.pegdown.ast.WikiLinkNode;
  27 +import org.springframework.util.Assert;
27 28
28 29 import de.blizzy.documentr.Util;
29 30
30 31 class DocumentrLinkRenderer extends LinkRenderer {
  32 + private HtmlSerializerContext context;
  33 +
  34 + DocumentrLinkRenderer(HtmlSerializerContext context) {
  35 + Assert.notNull(context);
  36 +
  37 + this.context = context;
  38 + }
  39 +
31 40 /*
32 41 * allows the following Wiki-style links:
33 42 *
@@ -35,6 +44,14 @@
35 44 * [[URI | nofollow]]
36 45 * [[URI link text]]
37 46 * [[URI link text | nofollow]]
  47 + * [[:page]]
  48 + * [[:page | nofollow]]
  49 + * [[:page link text]]
  50 + * [[:page link text | nofollow]]
  51 + * [[=attachment]]
  52 + * [[=attachment | nofollow]]
  53 + * [[=attachment link text]]
  54 + * [[=attachment link text | nofollow]]
38 55 * [[#Headline]]
39 56 */
40 57 @Override
@@ -51,11 +68,28 @@ public Rendering render(WikiLinkNode node) {
51 68 String params = StringUtils.substringAfter(text, "|").trim(); //$NON-NLS-1$
52 69 text = StringUtils.substringBefore(text, "|"); //$NON-NLS-1$
53 70
54   - if (StringUtils.isBlank(text)) {
55   - text = uri;
  71 + if (uri.startsWith(":") || uri.startsWith("=")) { //$NON-NLS-1$ //$NON-NLS-2$
  72 + if (StringUtils.isBlank(text)) {
  73 + text = uri.substring(1);
  74 + }
56 75 }
  76 +
  77 + if (uri.startsWith(":")) { //$NON-NLS-1$
  78 + uri = context.getPageURI(uri.substring(1));
  79 + } else if (uri.startsWith("=")) { //$NON-NLS-1$
  80 + uri = context.getAttachmentURI(uri.substring(1));
  81 + } else {
  82 + if (StringUtils.isBlank(text)) {
  83 + text = uri;
  84 + }
  85 + }
  86 +
57 87 text = text.trim();
58 88
  89 + if (uri.startsWith(":")) { //$NON-NLS-1$
  90 + uri = context.getPageURI(uri.substring(1));
  91 + }
  92 +
59 93 if (params.equalsIgnoreCase("nofollow")) { //$NON-NLS-1$
60 94 noFollow = true;
61 95 }
@@ -70,6 +104,7 @@ public Rendering render(WikiLinkNode node) {
70 104 /*
71 105 * allows the following link:
72 106 *
  107 + * [text](:page)
73 108 * [text](#Headline)
74 109 */
75 110 @Override
@@ -79,6 +114,11 @@ public Rendering render(ExpLinkNode node, String text) {
79 114 Node child = !children.isEmpty() ? children.get(0) : null;
80 115 String url = "#" + Util.simplifyForURL(node.url.substring(1)); //$NON-NLS-1$
81 116 node = new ExpLinkNode(node.title, url, child);
  117 + } else if (node.url.startsWith(":")) { //$NON-NLS-1$
  118 + List<Node> children = node.getChildren();
  119 + Node child = !children.isEmpty() ? children.get(0) : null;
  120 + String url = context.getPageURI(node.url.substring(1));
  121 + node = new ExpLinkNode(node.title, url, child);
82 122 }
83 123 return super.render(node, text);
84 124 }
2  de.blizzy.documentr/src/main/java/de/blizzy/documentr/web/markdown/HtmlSerializer.java
@@ -40,7 +40,7 @@
40 40 private HtmlSerializerContext context;
41 41
42 42 public HtmlSerializer(HtmlSerializerContext context) {
43   - super(new DocumentrLinkRenderer());
  43 + super(new DocumentrLinkRenderer(context));
44 44
45 45 this.context = context;
46 46 }
4 de.blizzy.documentr/src/main/resources/documentr_messages_de.properties
@@ -145,7 +145,9 @@ title.searchResults=Suchergebnisse
145 145 title.formattingHelp=Formatierungshilfe
146 146 title.actions=Aktionen
147 147 title.insertLink=Verkn�pfung einf�gen
148   -title.pageOrAttachment=Seite/Anhang
  148 +title.attachment=Anhang
  149 +title.page=Seite
  150 +title.pageStatic=Seite (statisch)
149 151 title.externalWebPage=Externe Webseite
150 152 title.insertImage=Bild einf�gen
151 153 title.importSampleContents=Beispielinhalte importieren
4 de.blizzy.documentr/src/main/resources/documentr_messages_en.properties
@@ -145,7 +145,9 @@ title.searchResults=Search Results
145 145 title.formattingHelp=Formatting Help
146 146 title.actions=Actions
147 147 title.insertLink=Insert Link
148   -title.pageOrAttachment=Page/Attachment
  148 +title.attachment=Attachment
  149 +title.page=Page
  150 +title.pageStatic=Page (static)
149 151 title.externalWebPage=External Web Page
150 152 title.insertImage=Insert Image
151 153 title.importSampleContents=Import Sample Contents
186 de.blizzy.documentr/src/main/webapp/WEB-INF/view/project/branch/page/edit.jsp
@@ -185,11 +185,18 @@ function showMarkdownHelp() {
185 185 }
186 186
187 187 function updateInsertLinkButton() {
  188 + var attachment = $('#insert-link-dialog .nav-tabs li:eq(0)').hasClass('active');
  189 + var page = $('#insert-link-dialog .nav-tabs li:eq(1)').hasClass('active');
  190 + var staticPage = $('#insert-link-dialog .nav-tabs li:eq(2)').hasClass('active');
  191 + var external = $('#insert-link-dialog .nav-tabs li:eq(3)').hasClass('active');
  192 + var linkedAttachment = $('#insert-link-dialog').data('linkedAttachment');
188 193 var linkedPage = $('#insert-link-dialog').data('linkedPage');
189   - var url = $('#insert-link-dialog input[name="url"]').val();
190   - var internal = $('#insert-link-dialog .nav-tabs li:eq(0)').hasClass('active');
191   - var valid = (internal && documentr.isSomething(linkedPage)) ||
192   - (!internal && (url.length > 0));
  194 + var linkedStaticPage = $('#insert-link-dialog').data('linkedStaticPage');
  195 + var url = $('#insert-link-dialog input[name="externalLinkUrl"]').val();
  196 + var valid = (attachment && documentr.isSomething(linkedAttachment)) ||
  197 + (page && documentr.isSomething(linkedPage)) ||
  198 + (staticPage && documentr.isSomething(linkedStaticPage)) ||
  199 + (external && (url.length > 0));
193 200 $('#insert-link-button').setButtonDisabled(!valid);
194 201 }
195 202
@@ -199,9 +206,9 @@ function openInsertLinkDialog() {
199 206 var end = textEl[0].selectionEnd;
200 207 var text = textEl.val();
201 208 var linkText = text.substring(start, end);
202   - $('#insert-link-linktext').val(linkText);
203   - $('#insert-link-dialog input[name="url"]').val('');
204   - $('#insert-link-dialog input[name="externalLinkText"]').val(linkText);
  209 + $('#insert-attachment-link-text, #insert-page-link-text, #insert-static-page-link-text, #insert-link-dialog input[name="externalLinkText"]')
  210 + .val(linkText);
  211 + $('#insert-link-dialog input[name="externalLinkUrl"]').val('');
205 212 $('#insert-link-dialog .nav-tabs a:first').tab('show');
206 213
207 214 function showDialog() {
@@ -209,9 +216,53 @@ function openInsertLinkDialog() {
209 216 $('#insert-link-dialog').showModal();
210 217 }
211 218
212   - var treeEl = $('#linked-page-tree');
213   - if (treeEl.children().length === 0) {
214   - documentr.createPageTree(treeEl, {
  219 + if ($('#linked-attachment-tree').children().length === 0) {
  220 + documentr.createPageTree($('#linked-attachment-tree'), {
  221 + start: {
  222 + type: 'page',
  223 + projectName: '<c:out value="${projectName}"/>',
  224 + branchName: '<c:out value="${branchName}"/>',
  225 + pagePath: '<c:out value="${path}"/>'
  226 + },
  227 + checkBranchPermissions: 'VIEW',
  228 + showPages: false,
  229 + showAttachments: true
  230 + })
  231 + .bind('select_node.jstree', function(event, data) {
  232 + var node = data.rslt.obj;
  233 + var linkedAttachment = {
  234 + path: node.data('name')
  235 + };
  236 + $('#insert-link-dialog').data('linkedAttachment', linkedAttachment);
  237 + updateInsertLinkButton();
  238 + })
  239 + .bind('deselect_node.jstree', function() {
  240 + $('#insert-link-dialog').data('linkedAttachment', null);
  241 + updateInsertLinkButton();
  242 + });
  243 +
  244 + documentr.createPageTree($('#linked-page-tree'), {
  245 + start: {
  246 + type: 'branch',
  247 + projectName: '<c:out value="${projectName}"/>',
  248 + branchName: '<c:out value="${branchName}"/>'
  249 + },
  250 + checkBranchPermissions: 'VIEW'
  251 + })
  252 + .bind('select_node.jstree', function(event, data) {
  253 + var node = data.rslt.obj;
  254 + var linkedPage = {
  255 + path: node.data('path').replace(/\//g, ',')
  256 + };
  257 + $('#insert-link-dialog').data('linkedPage', linkedPage);
  258 + updateInsertLinkButton();
  259 + })
  260 + .bind('deselect_node.jstree', function() {
  261 + $('#insert-link-dialog').data('linkedPage', null);
  262 + updateInsertLinkButton();
  263 + });
  264 +
  265 + documentr.createPageTree($('#linked-static-page-tree'), {
215 266 start: {
216 267 type: 'application'
217 268 },
@@ -219,32 +270,20 @@ function openInsertLinkDialog() {
219 270 projects: false,
220 271 branches: false
221 272 },
222   - checkBranchPermissions: 'VIEW',
223   - showAttachments: true
  273 + checkBranchPermissions: 'VIEW'
224 274 })
225 275 .bind('select_node.jstree', function(event, data) {
226 276 var node = data.rslt.obj;
227   - if (node.data('type') === 'page') {
228   - var linkedPage = {
229   - path: node.data('projectName') + '/' + node.data('branchName') + '/' +
230   - node.data('path').replace(/\//g, ','),
231   - pageType: 'page'
232   - };
233   - $('#insert-link-dialog').data('linkedPage', linkedPage);
234   - } else if (node.data('type') === 'attachment') {
235   - var linkedPage = {
236   - path: node.data('projectName') + '/' + node.data('branchName') + '/' +
237   - node.data('pagePath').replace(/\//g, ',') + '/' + node.data('name'),
238   - pageType: 'attachment'
239   - };
240   - $('#insert-link-dialog').data('linkedPage', linkedPage);
241   - } else {
242   - $('#insert-link-dialog').data('linkedPagePath', null);
243   - }
  277 + var linkedStaticPage = {
  278 + projectName: node.data('projectName'),
  279 + branchName: node.data('branchName'),
  280 + path: node.data('path')
  281 + };
  282 + $('#insert-link-dialog').data('linkedStaticPage', linkedStaticPage);
244 283 updateInsertLinkButton();
245 284 })
246 285 .bind('deselect_node.jstree', function() {
247   - $('#insert-link-dialog').data('linkedPagePath', null);
  286 + $('#insert-link-dialog').data('linkedStaticPage', null);
248 287 updateInsertLinkButton();
249 288 });
250 289
@@ -257,22 +296,40 @@ function openInsertLinkDialog() {
257 296 function insertLink() {
258 297 $('#insert-link-dialog').hideModal();
259 298
260   - var internal = $('#insert-link-dialog .nav-tabs li:eq(0)').hasClass('active');
  299 + var attachment = $('#insert-link-dialog .nav-tabs li:eq(0)').hasClass('active');
  300 + var page = $('#insert-link-dialog .nav-tabs li:eq(1)').hasClass('active');
  301 + var staticPage = $('#insert-link-dialog .nav-tabs li:eq(2)').hasClass('active');
  302 + var external = $('#insert-link-dialog .nav-tabs li:eq(3)').hasClass('active');
  303 + var linkedAttachment = $('#insert-link-dialog').data('linkedAttachment');
261 304 var linkedPage = $('#insert-link-dialog').data('linkedPage');
262   - var linkText = internal ? $('#insert-link-linktext').val() : $('#insert-link-dialog input[name="externalLinkText"]').val();
263   - var textEl = $('#text');
264   - var start = textEl[0].selectionStart;
265   - var end = textEl[0].selectionEnd;
  305 + var linkedStaticPage = $('#insert-link-dialog').data('linkedStaticPage');
  306 + var url = $('#insert-link-dialog input[name="externalLinkUrl"]').val();
  307 +
  308 + var linkText;
  309 + if (attachment) {
  310 + linkText = $('#insert-attachment-link-text').val();
  311 + } else if (page) {
  312 + linkText = $('#insert-page-link-text').val();
  313 + } else if (staticPage) {
  314 + linkText = $('#insert-static-page-link-text').val();
  315 + } else {
  316 + linkText = $('#insert-link-dialog input[name="externalLinkText"]').val();
  317 + }
266 318 var link;
267   - if (internal) {
268   - if (linkedPage.pageType === 'page') {
269   - link = '<c:url value="/page/"/>' + linkedPage.path;
270   - } else {
271   - link = '<c:url value="/attachment/"/>' + linkedPage.path;
272   - }
  319 + if (attachment) {
  320 + link = '=' + linkedAttachment.path;
  321 + } else if (page) {
  322 + link = ':' + linkedPage.path;
  323 + } else if (staticPage) {
  324 + link = '<c:url value="/page/"/>' + linkedStaticPage.projectName + '/' + linkedStaticPage.branchName + '/' +
  325 + linkedStaticPage.path.replace(/\//g, ',');
273 326 } else {
274   - link = $('#insert-link-dialog input[name="url"]').val();
  327 + link = url;
275 328 }
  329 +
  330 + var textEl = $('#text');
  331 + var start = textEl[0].selectionStart;
  332 + var end = textEl[0].selectionEnd;
276 333 var text = textEl.val();
277 334 text = text.substring(0, start) + '[[' + link + ' ' + linkText + ']]' + text.substring(end);
278 335 start = start + link.length + 3;
@@ -459,12 +516,29 @@ $(function() {
459 516 <div class="modal-body">
460 517 <form id="insertLinkForm" action="" method="POST" class="form-horizontal">
461 518 <ul class="nav nav-tabs">
462   - <li class="active"><a href="#insert-link-internal"><spring:message code="title.pageOrAttachment"/></a></li>
463   - <li><a href="#insert-link-external"><spring:message code="title.externalWebPage"/></a></li>
  519 + <li class="active"><a href="#insert-attachment-link"><spring:message code="title.attachment"/></a></li>
  520 + <li><a href="#insert-page-link"><spring:message code="title.page"/></a></li>
  521 + <li><a href="#insert-static-page-link"><spring:message code="title.pageStatic"/></a></li>
  522 + <li><a href="#insert-external-link"><spring:message code="title.externalWebPage"/></a></li>
464 523 </ul>
465 524
466 525 <div class="tab-content">
467   - <fieldset id="insert-link-internal" class="tab-pane active">
  526 + <fieldset id="insert-attachment-link" class="tab-pane active">
  527 + <div class="control-group">
  528 + <label class="control-label"><spring:message code="label.linkedPage"/>:</label>
  529 + <div class="controls">
  530 + <div id="linked-attachment-tree"></div>
  531 + </div>
  532 + </div>
  533 + <div class="control-group">
  534 + <label class="control-label"><spring:message code="label.linkText"/>:</label>
  535 + <div class="controls">
  536 + <input type="text" id="insert-attachment-link-text" class="input-xlarge"/>
  537 + </div>
  538 + </div>
  539 + </fieldset>
  540 +
  541 + <fieldset id="insert-page-link" class="tab-pane">
468 542 <div class="control-group">
469 543 <label class="control-label"><spring:message code="label.linkedPage"/>:</label>
470 544 <div class="controls">
@@ -474,15 +548,31 @@ $(function() {
474 548 <div class="control-group">
475 549 <label class="control-label"><spring:message code="label.linkText"/>:</label>
476 550 <div class="controls">
477   - <input type="text" id="insert-link-linktext" class="input-xlarge"/>
  551 + <input type="text" id="insert-page-link-text" class="input-xlarge"/>
478 552 </div>
479 553 </div>
480 554 </fieldset>
481   - <fieldset id="insert-link-external" class="tab-pane">
  555 +
  556 + <fieldset id="insert-static-page-link" class="tab-pane">
  557 + <div class="control-group">
  558 + <label class="control-label"><spring:message code="label.linkedPage"/>:</label>
  559 + <div class="controls">
  560 + <div id="linked-static-page-tree"></div>
  561 + </div>
  562 + </div>
  563 + <div class="control-group">
  564 + <label class="control-label"><spring:message code="label.linkText"/>:</label>
  565 + <div class="controls">
  566 + <input type="text" id="insert-static-page-link-text" class="input-xlarge"/>
  567 + </div>
  568 + </div>
  569 + </fieldset>
  570 +
  571 + <fieldset id="insert-external-link" class="tab-pane">
482 572 <div class="control-group">
483 573 <label class="control-label"><spring:message code="label.url"/>:</label>
484 574 <div class="controls">
485   - <input type="text" name="url" class="input-xlarge" onkeyup="updateInsertLinkButton()"/>
  575 + <input type="text" name="externalLinkUrl" class="input-xlarge" onkeyup="updateInsertLinkButton()"/>
486 576 </div>
487 577 </div>
488 578 <div class="control-group">
110 de.blizzy.documentr/src/test/java/de/blizzy/documentr/web/markdown/DocumentrLinkRendererTest.java
@@ -18,20 +18,29 @@
18 18 package de.blizzy.documentr.web.markdown;
19 19
20 20 import static org.junit.Assert.*;
  21 +import static org.mockito.Mockito.*;
21 22
22 23 import org.junit.Test;
  24 +import org.mockito.InjectMocks;
  25 +import org.mockito.Mock;
23 26 import org.pegdown.LinkRenderer.Attribute;
24 27 import org.pegdown.LinkRenderer.Rendering;
25 28 import org.pegdown.ast.ExpLinkNode;
26 29 import org.pegdown.ast.WikiLinkNode;
27 30
  31 +import de.blizzy.documentr.AbstractDocumentrTest;
28 32 import de.blizzy.documentr.Util;
29 33
30   -public class DocumentrLinkRendererTest {
  34 +public class DocumentrLinkRendererTest extends AbstractDocumentrTest {
  35 + @Mock
  36 + private HtmlSerializerContext context;
  37 + @InjectMocks
  38 + private DocumentrLinkRenderer renderer;
  39 +
31 40 @Test
32 41 public void renderWikiLink() {
33 42 WikiLinkNode node = new WikiLinkNode("foo"); //$NON-NLS-1$
34   - Rendering rendering = new DocumentrLinkRenderer().render(node);
  43 + Rendering rendering = renderer.render(node);
35 44 assertEquals("foo", rendering.href); //$NON-NLS-1$
36 45 assertEquals("foo", rendering.text); //$NON-NLS-1$
37 46 }
@@ -39,7 +48,7 @@ public void renderWikiLink() {
39 48 @Test
40 49 public void renderWikiLinkWithNoFollow() {
41 50 WikiLinkNode node = new WikiLinkNode("foo | nofollow"); //$NON-NLS-1$
42   - Rendering rendering = new DocumentrLinkRenderer().render(node);
  51 + Rendering rendering = renderer.render(node);
43 52 assertEquals("foo", rendering.href); //$NON-NLS-1$
44 53 assertEquals("foo", rendering.text); //$NON-NLS-1$
45 54 assertTrue(rendering.attributes.contains(Attribute.NO_FOLLOW));
@@ -48,7 +57,7 @@ public void renderWikiLinkWithNoFollow() {
48 57 @Test
49 58 public void renderWikiLinkWithText() {
50 59 WikiLinkNode node = new WikiLinkNode("foo link text"); //$NON-NLS-1$
51   - Rendering rendering = new DocumentrLinkRenderer().render(node);
  60 + Rendering rendering = renderer.render(node);
52 61 assertEquals("foo", rendering.href); //$NON-NLS-1$
53 62 assertEquals("link text", rendering.text); //$NON-NLS-1$
54 63 }
@@ -56,7 +65,7 @@ public void renderWikiLinkWithText() {
56 65 @Test
57 66 public void renderWikiLinkWithTextAndNoFollow() {
58 67 WikiLinkNode node = new WikiLinkNode("foo link text | nofollow"); //$NON-NLS-1$
59   - Rendering rendering = new DocumentrLinkRenderer().render(node);
  68 + Rendering rendering = renderer.render(node);
60 69 assertEquals("foo", rendering.href); //$NON-NLS-1$
61 70 assertEquals("link text", rendering.text); //$NON-NLS-1$
62 71 assertTrue(rendering.attributes.contains(Attribute.NO_FOLLOW));
@@ -66,17 +75,102 @@ public void renderWikiLinkWithTextAndNoFollow() {
66 75 public void renderWikiLinkWithAnchor() {
67 76 String headline = "A Headline"; //$NON-NLS-1$
68 77 WikiLinkNode node = new WikiLinkNode("#" + headline); //$NON-NLS-1$
69   - Rendering rendering = new DocumentrLinkRenderer().render(node);
  78 + Rendering rendering = renderer.render(node);
70 79 assertEquals("#" + Util.simplifyForURL(headline), rendering.href); //$NON-NLS-1$
71 80 assertEquals(headline, rendering.text);
72 81 }
73 82
74 83 @Test
75   - public void renderExpLinkNodeWithAnchor() {
  84 + public void renderWikiLinkToPage() {
  85 + when(context.getPageURI("foo")).thenReturn("fooPage"); //$NON-NLS-1$ //$NON-NLS-2$
  86 + WikiLinkNode node = new WikiLinkNode(":foo"); //$NON-NLS-1$
  87 + Rendering rendering = renderer.render(node);
  88 + assertEquals("fooPage", rendering.href); //$NON-NLS-1$
  89 + assertEquals("foo", rendering.text); //$NON-NLS-1$
  90 + }
  91 +
  92 + @Test
  93 + public void renderWikiLinkToPageWithNoFollow() {
  94 + when(context.getPageURI("foo")).thenReturn("fooPage"); //$NON-NLS-1$ //$NON-NLS-2$
  95 + WikiLinkNode node = new WikiLinkNode(":foo | nofollow"); //$NON-NLS-1$
  96 + Rendering rendering = renderer.render(node);
  97 + assertEquals("fooPage", rendering.href); //$NON-NLS-1$
  98 + assertEquals("foo", rendering.text); //$NON-NLS-1$
  99 + assertTrue(rendering.attributes.contains(Attribute.NO_FOLLOW));
  100 + }
  101 +
  102 + @Test
  103 + public void renderWikiLinkToPageWithText() {
  104 + when(context.getPageURI("foo")).thenReturn("fooPage"); //$NON-NLS-1$ //$NON-NLS-2$
  105 + WikiLinkNode node = new WikiLinkNode(":foo link text"); //$NON-NLS-1$
  106 + Rendering rendering = renderer.render(node);
  107 + assertEquals("fooPage", rendering.href); //$NON-NLS-1$
  108 + assertEquals("link text", rendering.text); //$NON-NLS-1$
  109 + }
  110 +
  111 + @Test
  112 + public void renderWikiLinkToPageWithTextAndNoFollow() {
  113 + when(context.getPageURI("foo")).thenReturn("fooPage"); //$NON-NLS-1$ //$NON-NLS-2$
  114 + WikiLinkNode node = new WikiLinkNode(":foo link text | nofollow"); //$NON-NLS-1$
  115 + Rendering rendering = renderer.render(node);
  116 + assertEquals("fooPage", rendering.href); //$NON-NLS-1$
  117 + assertEquals("link text", rendering.text); //$NON-NLS-1$
  118 + assertTrue(rendering.attributes.contains(Attribute.NO_FOLLOW));
  119 + }
  120 +
  121 + @Test
  122 + public void renderWikiLinkToAttachment() {
  123 + when(context.getAttachmentURI("foo")).thenReturn("fooAttachment"); //$NON-NLS-1$ //$NON-NLS-2$
  124 + WikiLinkNode node = new WikiLinkNode("=foo"); //$NON-NLS-1$
  125 + Rendering rendering = renderer.render(node);
  126 + assertEquals("fooAttachment", rendering.href); //$NON-NLS-1$
  127 + assertEquals("foo", rendering.text); //$NON-NLS-1$
  128 + }
  129 +
  130 + @Test
  131 + public void renderWikiLinkToAttachmentWithNoFollow() {
  132 + when(context.getAttachmentURI("foo")).thenReturn("fooAttachment"); //$NON-NLS-1$ //$NON-NLS-2$
  133 + WikiLinkNode node = new WikiLinkNode("=foo | nofollow"); //$NON-NLS-1$
  134 + Rendering rendering = renderer.render(node);
  135 + assertEquals("fooAttachment", rendering.href); //$NON-NLS-1$
  136 + assertEquals("foo", rendering.text); //$NON-NLS-1$
  137 + assertTrue(rendering.attributes.contains(Attribute.NO_FOLLOW));
  138 + }
  139 +
  140 + @Test
  141 + public void renderWikiLinkToAttachmentWithText() {
  142 + when(context.getAttachmentURI("foo")).thenReturn("fooAttachment"); //$NON-NLS-1$ //$NON-NLS-2$
  143 + WikiLinkNode node = new WikiLinkNode("=foo link text"); //$NON-NLS-1$
  144 + Rendering rendering = renderer.render(node);
  145 + assertEquals("fooAttachment", rendering.href); //$NON-NLS-1$
  146 + assertEquals("link text", rendering.text); //$NON-NLS-1$
  147 + }
  148 +
  149 + @Test
  150 + public void renderWikiLinkToAttachmentWithTextAndNoFollow() {
  151 + when(context.getAttachmentURI("foo")).thenReturn("fooAttachment"); //$NON-NLS-1$ //$NON-NLS-2$
  152 + WikiLinkNode node = new WikiLinkNode("=foo link text | nofollow"); //$NON-NLS-1$
  153 + Rendering rendering = renderer.render(node);
  154 + assertEquals("fooAttachment", rendering.href); //$NON-NLS-1$
  155 + assertEquals("link text", rendering.text); //$NON-NLS-1$
  156 + assertTrue(rendering.attributes.contains(Attribute.NO_FOLLOW));
  157 + }
  158 +
  159 + @Test
  160 + public void renderExpLinkWithAnchor() {
76 161 String headline = "A Headline"; //$NON-NLS-1$
77 162 ExpLinkNode node = new ExpLinkNode(null, "#" + headline, null); //$NON-NLS-1$
78   - Rendering rendering = new DocumentrLinkRenderer().render(node, headline);
  163 + Rendering rendering = renderer.render(node, headline);
79 164 assertEquals("#" + Util.simplifyForURL(headline), rendering.href); //$NON-NLS-1$
80 165 assertEquals(headline, rendering.text);
81 166 }
  167 +
  168 + @Test
  169 + public void renderExpLinkToPage() {
  170 + when(context.getPageURI("foo")).thenReturn("fooPage"); //$NON-NLS-1$ //$NON-NLS-2$
  171 + ExpLinkNode node = new ExpLinkNode(null, ":foo", null); //$NON-NLS-1$
  172 + Rendering rendering = renderer.render(node, "text"); //$NON-NLS-1$
  173 + assertEquals("fooPage", rendering.href); //$NON-NLS-1$
  174 + assertEquals("text", rendering.text); //$NON-NLS-1$
  175 + }
82 176 }

0 comments on commit 416407f

Please sign in to comment.
Something went wrong with that request. Please try again.