-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactoring markdown escapes * Escape node name and labels * Escape descriptor * Refactoring markdown none handling
- Loading branch information
Showing
3 changed files
with
92 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/com/cloudbees/jenkins/support/util/Markdown.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.cloudbees.jenkins.support.util; | ||
|
||
import hudson.model.Describable; | ||
|
||
public final class Markdown { | ||
public static final String NONE_STRING = "(none)"; | ||
|
||
/** Not instantiable. */ | ||
private Markdown() { | ||
throw new AssertionError("Not instantiable"); | ||
} | ||
|
||
public static String escapeUnderscore(String raw) { | ||
return raw.replaceAll("_", "_"); | ||
} | ||
public static String escapeBacktick(String raw) { | ||
return raw.replaceAll("`", "`"); | ||
} | ||
|
||
public static String prettyNone(String raw) { return raw != null && !raw.isEmpty() ? raw : NONE_STRING; } | ||
} |
27 changes: 27 additions & 0 deletions
27
src/test/java/com/cloudbees/jenkins/support/util/MarkdownTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.cloudbees.jenkins.support.util; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class MarkdownTest { | ||
|
||
@Test | ||
public void escapeUnderscore() { | ||
assertEquals("a_b", Markdown.escapeUnderscore("a_b")); | ||
assertEquals("a`b", Markdown.escapeUnderscore("a`b")); | ||
} | ||
|
||
@Test | ||
public void escapeBacktick() { | ||
assertEquals("a`b", Markdown.escapeBacktick("a`b")); | ||
assertEquals("a_b", Markdown.escapeBacktick("a_b")); | ||
} | ||
|
||
@Test | ||
public void prettyNone() { | ||
assertEquals(Markdown.NONE_STRING, Markdown.prettyNone(null)); | ||
assertEquals(Markdown.NONE_STRING, Markdown.prettyNone("")); | ||
assertEquals("a", Markdown.prettyNone("a")); | ||
} | ||
} |