Skip to content

Commit

Permalink
feat(mustache): Add a trim function. Resolves #894
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Aug 14, 2022
1 parent a3eda47 commit 9a68dba
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public static void applyFunctions(Map<String, Object> props) {
}
props.put("f_now", new TimeFormatFunction(now));

props.put("f_trim", new TrimFunction());
props.put("f_underscore", new UnderscoreFunction());
props.put("f_dash", new DashFunction());
props.put("f_slash", new SlashFunction());
Expand Down Expand Up @@ -179,6 +180,13 @@ public String apply(String input) {
}
}

public static class TrimFunction implements Function<String, String> {
@Override
public String apply(String input) {
return input.trim();
}
}

public static class UnderscoreFunction implements Function<String, String> {
@Override
public String apply(String input) {
Expand Down Expand Up @@ -240,7 +248,7 @@ public String apply(String input) {
Parser parser = Parser.builder().build();
Node document = parser.parse(input);
HtmlRenderer renderer = HtmlRenderer.builder().build();
return renderer.render(document);
return renderer.render(document).trim();
}
}

Expand Down

0 comments on commit 9a68dba

Please sign in to comment.