Escape parenthesis for links in Markdown format

This commit is contained in:
aboyko
2024-11-25 14:06:23 -05:00
parent 0f854a97ee
commit 54beb6afc4
2 changed files with 29 additions and 1 deletions

View File

@@ -210,7 +210,8 @@ public class Renderables {
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(')');
}
}

View File

@@ -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)");
}
}