Remove attrs object from format
This commit is contained in:
parent
7881420cbd
commit
97c994d866
@ -18,16 +18,38 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import ix.Ix;
|
import ix.Ix;
|
||||||
import ix.IxFunction;
|
import ix.IxFunction;
|
||||||
import ix.IxPredicate;
|
import ix.IxPredicate;
|
||||||
|
|
||||||
|
import static ru.noties.markwon.renderer.visitor.TestSpan.BLOCK_QUOTE;
|
||||||
|
import static ru.noties.markwon.renderer.visitor.TestSpan.BULLET_LIST;
|
||||||
|
import static ru.noties.markwon.renderer.visitor.TestSpan.CODE;
|
||||||
|
import static ru.noties.markwon.renderer.visitor.TestSpan.CODE_BLOCK;
|
||||||
|
import static ru.noties.markwon.renderer.visitor.TestSpan.EMPHASIS;
|
||||||
|
import static ru.noties.markwon.renderer.visitor.TestSpan.HEADING;
|
||||||
|
import static ru.noties.markwon.renderer.visitor.TestSpan.IMAGE;
|
||||||
|
import static ru.noties.markwon.renderer.visitor.TestSpan.LINK;
|
||||||
|
import static ru.noties.markwon.renderer.visitor.TestSpan.ORDERED_LIST;
|
||||||
|
import static ru.noties.markwon.renderer.visitor.TestSpan.PARAGRAPH;
|
||||||
|
import static ru.noties.markwon.renderer.visitor.TestSpan.STRIKE_THROUGH;
|
||||||
|
import static ru.noties.markwon.renderer.visitor.TestSpan.STRONG_EMPHASIS;
|
||||||
|
import static ru.noties.markwon.renderer.visitor.TestSpan.SUB_SCRIPT;
|
||||||
|
import static ru.noties.markwon.renderer.visitor.TestSpan.SUPER_SCRIPT;
|
||||||
|
import static ru.noties.markwon.renderer.visitor.TestSpan.TABLE_ROW;
|
||||||
|
import static ru.noties.markwon.renderer.visitor.TestSpan.TASK_LIST;
|
||||||
|
import static ru.noties.markwon.renderer.visitor.TestSpan.THEMATIC_BREAK;
|
||||||
|
import static ru.noties.markwon.renderer.visitor.TestSpan.UNDERLINE;
|
||||||
|
|
||||||
abstract class TestDataReader {
|
abstract class TestDataReader {
|
||||||
|
|
||||||
private static final String FOLDER = "tests/";
|
private static final String FOLDER = "tests/";
|
||||||
@ -79,9 +101,40 @@ abstract class TestDataReader {
|
|||||||
|
|
||||||
static class Reader {
|
static class Reader {
|
||||||
|
|
||||||
private static final String ATTRS = "attrs";
|
|
||||||
private static final String TEXT = "text";
|
private static final String TEXT = "text";
|
||||||
|
|
||||||
|
private static final Set<String> TAGS;
|
||||||
|
|
||||||
|
static {
|
||||||
|
TAGS = new HashSet<>(Arrays.asList(
|
||||||
|
STRONG_EMPHASIS,
|
||||||
|
EMPHASIS,
|
||||||
|
BLOCK_QUOTE,
|
||||||
|
CODE,
|
||||||
|
CODE_BLOCK,
|
||||||
|
ORDERED_LIST,
|
||||||
|
BULLET_LIST,
|
||||||
|
THEMATIC_BREAK,
|
||||||
|
HEADING,
|
||||||
|
STRIKE_THROUGH,
|
||||||
|
TASK_LIST,
|
||||||
|
TABLE_ROW,
|
||||||
|
PARAGRAPH,
|
||||||
|
IMAGE,
|
||||||
|
LINK,
|
||||||
|
SUPER_SCRIPT,
|
||||||
|
SUB_SCRIPT,
|
||||||
|
UNDERLINE,
|
||||||
|
HEADING + "1",
|
||||||
|
HEADING + "2",
|
||||||
|
HEADING + "3",
|
||||||
|
HEADING + "4",
|
||||||
|
HEADING + "5",
|
||||||
|
HEADING + "6",
|
||||||
|
TEXT
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
private final String file;
|
private final String file;
|
||||||
|
|
||||||
Reader(@NonNull String file) {
|
Reader(@NonNull String file) {
|
||||||
@ -160,8 +213,7 @@ abstract class TestDataReader {
|
|||||||
// it can additionally contain "attrs" key which is the attributes
|
// it can additionally contain "attrs" key which is the attributes
|
||||||
// b:
|
// b:
|
||||||
// - text: "bold"
|
// - text: "bold"
|
||||||
// attrs:
|
// href: "my-href"
|
||||||
// href: "my-href"
|
|
||||||
|
|
||||||
final int size = array.size();
|
final int size = array.size();
|
||||||
|
|
||||||
@ -172,16 +224,25 @@ abstract class TestDataReader {
|
|||||||
final JsonObject object = array.get(i).getAsJsonObject();
|
final JsonObject object = array.get(i).getAsJsonObject();
|
||||||
|
|
||||||
String name = null;
|
String name = null;
|
||||||
Map<String, String> attributes = null;
|
Map<String, String> attributes = new HashMap<>(0);
|
||||||
|
|
||||||
for (String key : object.keySet()) {
|
for (String key : object.keySet()) {
|
||||||
if (ATTRS.equals(key)) {
|
if (TAGS.contains(key)) {
|
||||||
attributes = attributes(object.get(key));
|
if (name == null) {
|
||||||
} else if (name == null) {
|
name = key;
|
||||||
name = key;
|
} else {
|
||||||
|
throw new RuntimeException("Unexpected key in object: " + object);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// we allow only 2 keys: span and/or attributes and no more
|
// fill attribute map with it
|
||||||
throw new RuntimeException("Unexpected key in object: " + object);
|
final String value;
|
||||||
|
final JsonElement valueElement = object.get(key);
|
||||||
|
if (valueElement.isJsonNull()) {
|
||||||
|
value = null;
|
||||||
|
} else {
|
||||||
|
value = valueElement.getAsString();
|
||||||
|
}
|
||||||
|
attributes.put(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -189,10 +250,6 @@ abstract class TestDataReader {
|
|||||||
throw new RuntimeException("Object is missing tag name: " + object);
|
throw new RuntimeException("Object is missing tag name: " + object);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attributes == null) {
|
|
||||||
attributes = Collections.emptyMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
final JsonElement element = object.get(name);
|
final JsonElement element = object.get(name);
|
||||||
|
|
||||||
if (TEXT.equals(name)) {
|
if (TEXT.equals(name)) {
|
||||||
@ -263,33 +320,5 @@ abstract class TestDataReader {
|
|||||||
|
|
||||||
return new TestConfig(map);
|
return new TestConfig(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private static Map<String, String> attributes(@NonNull JsonElement element) {
|
|
||||||
|
|
||||||
final JsonObject object = element.isJsonObject()
|
|
||||||
? element.getAsJsonObject()
|
|
||||||
: null;
|
|
||||||
|
|
||||||
final Map<String, String> attributes;
|
|
||||||
|
|
||||||
if (object != null) {
|
|
||||||
attributes = new HashMap<>(object.size());
|
|
||||||
for (String key : object.keySet()) {
|
|
||||||
final String value;
|
|
||||||
final JsonElement valueElement = object.get(key);
|
|
||||||
if (valueElement.isJsonNull()) {
|
|
||||||
value = null;
|
|
||||||
} else {
|
|
||||||
value = valueElement.getAsString();
|
|
||||||
}
|
|
||||||
attributes.put(key, value);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
attributes = Collections.emptyMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
return attributes;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,7 @@ config:
|
|||||||
output:
|
output:
|
||||||
- text: "Here is some "
|
- text: "Here is some "
|
||||||
- a: "link"
|
- a: "link"
|
||||||
attrs:
|
href: "https://my.href"
|
||||||
href: "https://my.href"
|
|
||||||
- text: " "
|
- text: " "
|
||||||
- b:
|
- b:
|
||||||
- text: "bold "
|
- text: "bold "
|
||||||
|
@ -66,8 +66,7 @@ output:
|
|||||||
- h2: "link"
|
- h2: "link"
|
||||||
- text: "\n"
|
- text: "\n"
|
||||||
- a: "a"
|
- a: "a"
|
||||||
attrs:
|
href: "a://href"
|
||||||
href: "a://href"
|
|
||||||
- text: "\n"
|
- text: "\n"
|
||||||
- h2: "unordered-list"
|
- h2: "unordered-list"
|
||||||
- text: "\n"
|
- text: "\n"
|
||||||
@ -78,18 +77,15 @@ output:
|
|||||||
- h2: "ordered-list"
|
- h2: "ordered-list"
|
||||||
- text: "\n"
|
- text: "\n"
|
||||||
- ol: "ol1"
|
- ol: "ol1"
|
||||||
attrs:
|
start: 1
|
||||||
start: 1
|
|
||||||
- text: "\n"
|
- text: "\n"
|
||||||
- ol: "ol2"
|
- ol: "ol2"
|
||||||
attrs:
|
start: 2
|
||||||
start: 2
|
|
||||||
- text: "\n"
|
- text: "\n"
|
||||||
- h2: "image"
|
- h2: "image"
|
||||||
- text: "\n"
|
- text: "\n"
|
||||||
- img: "img"
|
- img: "img"
|
||||||
attrs:
|
src: "img://src"
|
||||||
src: "img://src"
|
|
||||||
- text: "\n"
|
- text: "\n"
|
||||||
- h2: "blockquote"
|
- h2: "blockquote"
|
||||||
- text: "\n"
|
- text: "\n"
|
||||||
|
@ -2,5 +2,4 @@ input: "[link](#href)"
|
|||||||
|
|
||||||
output:
|
output:
|
||||||
- a: "link"
|
- a: "link"
|
||||||
attrs:
|
href: "#href"
|
||||||
href: "#href"
|
|
@ -2,7 +2,6 @@ input: ""
|
|||||||
|
|
||||||
output:
|
output:
|
||||||
- img: "image"
|
- img: "image"
|
||||||
attrs:
|
src: "#href"
|
||||||
src: "#href"
|
imageSize: null
|
||||||
imageSize: null
|
replacementTextIsLink: false
|
||||||
replacementTextIsLink: false
|
|
@ -2,5 +2,4 @@ input: "1. ol"
|
|||||||
|
|
||||||
output:
|
output:
|
||||||
- ol: "ol"
|
- ol: "ol"
|
||||||
attrs:
|
start: 1
|
||||||
start: 1
|
|
@ -2,6 +2,5 @@ input: "- [ ] task-list"
|
|||||||
|
|
||||||
output:
|
output:
|
||||||
- task-list: "task-list"
|
- task-list: "task-list"
|
||||||
attrs:
|
blockIdent: 1
|
||||||
blockIdent: 1
|
done: false
|
||||||
done: false
|
|
@ -2,5 +2,4 @@ input: "* ul"
|
|||||||
|
|
||||||
output:
|
output:
|
||||||
- ul: "ul"
|
- ul: "ul"
|
||||||
attrs:
|
level: 0
|
||||||
level: 0
|
|
Loading…
x
Reference in New Issue
Block a user