Skip to content

Commit ab3f0f4

Browse files
author
Torsten Krause
committed
Split node type filters into block type and content type filters
1 parent 8c311c1 commit ab3f0f4

14 files changed

+182
-128
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.markdom.handler.filter.blocktype;
2+
3+
import java.util.EnumSet;
4+
import java.util.Set;
5+
6+
import io.markdom.common.MarkdomBlockType;
7+
import io.markdom.util.ObjectHelper;
8+
9+
public final class BlacklistBlockTypeMarkdomFilterHandler implements BlockTypeMarkdomFilterHandler {
10+
11+
private final Set<MarkdomBlockType> blockTypes;
12+
13+
public BlacklistBlockTypeMarkdomFilterHandler(Set<MarkdomBlockType> blockTypes) {
14+
this.blockTypes = EnumSet.copyOf(ObjectHelper.notNull("set of block types", blockTypes));
15+
}
16+
17+
@Override
18+
public boolean testBlockType(MarkdomBlockType type) {
19+
return blockTypes.contains(type);
20+
}
21+
22+
}
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
package io.markdom.handler.filter.nodetype;
1+
package io.markdom.handler.filter.blocktype;
22

33
import java.util.Optional;
44

55
import io.markdom.common.MarkdomBlockType;
6-
import io.markdom.common.MarkdomContentType;
7-
import io.markdom.common.MarkdomEmphasisLevel;
86
import io.markdom.common.MarkdomHeadingLevel;
97
import io.markdom.handler.AbstractMarkdomFilter;
108
import io.markdom.util.ObjectHelper;
119

12-
public final class NodeTypeMarkdomFilter extends AbstractMarkdomFilter {
10+
public final class BlockTypeMarkdomFilter extends AbstractMarkdomFilter {
1311

14-
private final NodeTypeMarkdomFilterHandler handler;
12+
private final BlockTypeMarkdomFilterHandler handler;
1513

16-
public NodeTypeMarkdomFilter(NodeTypeMarkdomFilterHandler handler) {
14+
public BlockTypeMarkdomFilter(BlockTypeMarkdomFilterHandler handler) {
1715
this.handler = ObjectHelper.notNull("handler", handler);
1816
}
1917

@@ -57,34 +55,4 @@ public boolean testUnorderedListBlock() {
5755
return handler.testBlockType(MarkdomBlockType.UNORDERED_LIST);
5856
}
5957

60-
@Override
61-
public boolean testCodeContent(String code) {
62-
return handler.testContentType(MarkdomContentType.CODE);
63-
}
64-
65-
@Override
66-
public boolean testEmphasisContent(MarkdomEmphasisLevel level) {
67-
return handler.testContentType(MarkdomContentType.EMPHASIS);
68-
}
69-
70-
@Override
71-
public boolean testImageContent(String uri, Optional<String> title, Optional<String> alternative) {
72-
return handler.testContentType(MarkdomContentType.IMAGE);
73-
}
74-
75-
@Override
76-
public boolean testLineBreakContent(Boolean hard) {
77-
return handler.testContentType(MarkdomContentType.LINE_BREAK);
78-
}
79-
80-
@Override
81-
public boolean testLinkContent(String uri, Optional<String> title) {
82-
return handler.testContentType(MarkdomContentType.LINK);
83-
}
84-
85-
@Override
86-
public boolean testTextContent(String text) {
87-
return handler.testContentType(MarkdomContentType.TEXT);
88-
}
89-
9058
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.markdom.handler.filter.blocktype;
2+
3+
import io.markdom.common.MarkdomBlockType;
4+
5+
public interface BlockTypeMarkdomFilterHandler {
6+
7+
public boolean testBlockType(MarkdomBlockType type);
8+
9+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.markdom.handler.filter.blocktype;
2+
3+
import io.markdom.common.MarkdomBlockType;
4+
5+
public final class IdleBlockTypeMarkdomFilterHandler implements BlockTypeMarkdomFilterHandler {
6+
7+
@Override
8+
public boolean testBlockType(MarkdomBlockType type) {
9+
return false;
10+
}
11+
12+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.markdom.handler.filter.blocktype;
2+
3+
import java.util.EnumSet;
4+
import java.util.Set;
5+
6+
import io.markdom.common.MarkdomBlockType;
7+
import io.markdom.util.ObjectHelper;
8+
9+
public final class WhitelistBlockTypeMarkdomFilterHandler implements BlockTypeMarkdomFilterHandler {
10+
11+
private final Set<MarkdomBlockType> blockTypes;
12+
13+
public WhitelistBlockTypeMarkdomFilterHandler(Set<MarkdomBlockType> blockTypes) {
14+
this.blockTypes = EnumSet.copyOf(ObjectHelper.notNull("set of block types", blockTypes));
15+
}
16+
17+
@Override
18+
public boolean testBlockType(MarkdomBlockType type) {
19+
return !blockTypes.contains(type);
20+
}
21+
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.markdom.handler.filter.contenttype;
2+
3+
import java.util.EnumSet;
4+
import java.util.Set;
5+
6+
import io.markdom.common.MarkdomContentType;
7+
import io.markdom.util.ObjectHelper;
8+
9+
public final class BlacklistContentTypeMarkdomFilterHandler implements ContentTypeMarkdomFilterHandler {
10+
11+
private final Set<MarkdomContentType> contentTypes;
12+
13+
public BlacklistContentTypeMarkdomFilterHandler(Set<MarkdomContentType> contentTypes) {
14+
this.contentTypes = EnumSet.copyOf(ObjectHelper.notNull("set of content types", contentTypes));
15+
}
16+
17+
@Override
18+
public boolean testContentType(MarkdomContentType type) {
19+
return contentTypes.contains(type);
20+
}
21+
22+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package io.markdom.handler.filter.contenttype;
2+
3+
import java.util.Optional;
4+
5+
import io.markdom.common.MarkdomContentType;
6+
import io.markdom.common.MarkdomEmphasisLevel;
7+
import io.markdom.handler.AbstractMarkdomFilter;
8+
import io.markdom.util.ObjectHelper;
9+
10+
public final class ContentTypeMarkdomFilter extends AbstractMarkdomFilter {
11+
12+
private final ContentTypeMarkdomFilterHandler handler;
13+
14+
public ContentTypeMarkdomFilter(ContentTypeMarkdomFilterHandler handler) {
15+
this.handler = ObjectHelper.notNull("handler", handler);
16+
}
17+
18+
@Override
19+
public boolean testCodeContent(String code) {
20+
return handler.testContentType(MarkdomContentType.CODE);
21+
}
22+
23+
@Override
24+
public boolean testEmphasisContent(MarkdomEmphasisLevel level) {
25+
return handler.testContentType(MarkdomContentType.EMPHASIS);
26+
}
27+
28+
@Override
29+
public boolean testImageContent(String uri, Optional<String> title, Optional<String> alternative) {
30+
return handler.testContentType(MarkdomContentType.IMAGE);
31+
}
32+
33+
@Override
34+
public boolean testLineBreakContent(Boolean hard) {
35+
return handler.testContentType(MarkdomContentType.LINE_BREAK);
36+
}
37+
38+
@Override
39+
public boolean testLinkContent(String uri, Optional<String> title) {
40+
return handler.testContentType(MarkdomContentType.LINK);
41+
}
42+
43+
@Override
44+
public boolean testTextContent(String text) {
45+
return handler.testContentType(MarkdomContentType.TEXT);
46+
}
47+
48+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package io.markdom.handler.filter.contenttype;
2+
3+
import io.markdom.common.MarkdomContentType;
4+
5+
public interface ContentTypeMarkdomFilterHandler {
6+
7+
public boolean testContentType(MarkdomContentType type);
8+
9+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.markdom.handler.filter.contenttype;
2+
3+
import io.markdom.common.MarkdomContentType;
4+
5+
public final class IdleContentTypeMarkdomFilterHandler implements ContentTypeMarkdomFilterHandler {
6+
7+
@Override
8+
public boolean testContentType(MarkdomContentType type) {
9+
return false;
10+
}
11+
12+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.markdom.handler.filter.contenttype;
2+
3+
import java.util.EnumSet;
4+
import java.util.Set;
5+
6+
import io.markdom.common.MarkdomContentType;
7+
import io.markdom.util.ObjectHelper;
8+
9+
public final class WhitelistContentTypeMarkdomFilterHandler implements ContentTypeMarkdomFilterHandler {
10+
11+
private final Set<MarkdomContentType> contentTypes;
12+
13+
public WhitelistContentTypeMarkdomFilterHandler(Set<MarkdomContentType> contentTypes) {
14+
this.contentTypes = EnumSet.copyOf(ObjectHelper.notNull("set of content types", contentTypes));
15+
}
16+
17+
@Override
18+
public boolean testContentType(MarkdomContentType type) {
19+
return !contentTypes.contains(type);
20+
}
21+
22+
}

0 commit comments

Comments
 (0)