Skip to content

Commit

Permalink
Added close html filter implementation with Jsoup
Browse files Browse the repository at this point in the history
  • Loading branch information
asegal-hs committed Nov 15, 2023
1 parent 16fb43f commit daf2c84
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.hubspot.jinjava.doc.annotations.JinjavaParam;
import com.hubspot.jinjava.doc.annotations.JinjavaSnippet;
import com.hubspot.jinjava.interpret.JinjavaInterpreter;
import java.util.Objects;
import org.jsoup.Jsoup;

@JinjavaDoc(
value = "Closes open HTML tags in a string",
Expand All @@ -19,10 +21,6 @@ public String getName() {

@Override
public Object filter(Object var, JinjavaInterpreter interpreter, String... args) {
/*
Closes open HTML tags.
*/

return null;
return Jsoup.parse(Objects.toString(var)).toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.hubspot.jinjava.lib.filter;

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

import com.google.common.collect.ImmutableMap;
import com.hubspot.jinjava.BaseInterpretingTest;
import com.hubspot.jinjava.BaseJinjavaTest;
import org.junit.Before;
import org.junit.Test;

public class CloseHtmlFilterTest extends BaseInterpretingTest {
CloseHtmlFilter f;

@Before
public void setup() {
f = new CloseHtmlFilter();
}

@Test
public void itClosesTags() {
String openTags = "<p>Hello, world!";
assertThat(f.filter(openTags, interpreter)).isEqualTo("<p>Hello, world!</p>");
}
}

0 comments on commit daf2c84

Please sign in to comment.