Skip to content

Commit

Permalink
Escape parenthesis for links in Markdown format
Browse files Browse the repository at this point in the history
  • Loading branch information
BoykoAlex committed Nov 25, 2024
1 parent 0f854a9 commit 54beb6a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ public void renderAsMarkdown(StringBuilder buffer) {
buffer.append(']');
if (url != null) {
buffer.append('(');
buffer.append(url);
// Escape parenthesis for the MD format
buffer.append(url.replace("(", "%28").replace(")", "%29"));
buffer.append(')');
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2024 Broadcom, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Broadcom, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.commons.util;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;

public class RenderablesTest {

@Test
void escapeParenthesisForMardownLink() {
Renderable r = Renderables.link("my-link-with-parenthesis", "https://foo.com/index(1).html");
StringBuilder sb = new StringBuilder();
r.renderAsMarkdown(sb);
assertThat(sb.toString()).isEqualTo("[my-link-with-parenthesis](https://foo.com/index%281%29.html)");
}

}

0 comments on commit 54beb6a

Please sign in to comment.