Search in sources :

Example 1 with Attribute

use of com.vladsch.flexmark.util.html.Attribute in project flexmark-java by vsch.

the class AttributeTest method testBasic.

@Test
public void testBasic() throws Exception {
    Attribute attribute = AttributeImpl.of("name", "value1", ' ');
    assertEquals("no name change", "name", attribute.getName().toString());
    assertEquals("contains a simple value", true, attribute.containsValue("value1"));
    Attribute attribute1 = attribute.setValue("value2");
    assertEquals("add a new value", "value1 value2", attribute1.getValue().toString());
    assertEquals("non-equality", false, attribute1.equals(attribute));
    assertEquals("no name change", "name", attribute1.getName().toString());
    Attribute attribute2 = attribute.removeValue("value2");
    assertEquals("remove non-existent value", "value1", attribute.getValue().toString());
    assertEquals("remove non-existent value, no new attribute", attribute2, attribute);
    assertEquals("equality", true, attribute2.equals(attribute));
    assertEquals("no name change", "name", attribute2.getName().toString());
    Attribute attribute3 = attribute.replaceValue("value2");
    assertEquals("replace value", "value2", attribute3.getValue().toString());
    assertEquals("no name change", "name", attribute3.getName().toString());
    Attribute attribute4 = attribute1.setValue("value1");
    assertEquals("add existing value", "value1 value2", attribute4.getValue().toString());
    assertEquals("add existing value, no new attribute", attribute4, attribute1);
    assertEquals("no name change", "name", attribute4.getName().toString());
    Attribute attribute5 = attribute1.setValue("value1");
    assertEquals("add existing value", "value1 value2", attribute5.getValue().toString());
    assertEquals("add existing value, no new attribute", attribute5, attribute1);
    assertEquals("no name change", "name", attribute5.getName().toString());
    Attribute attribute6 = attribute1.setValue("value2");
    assertEquals("add existing value", "value1 value2", attribute6.getValue().toString());
    assertEquals("add existing value, no new attribute", attribute6, attribute1);
    assertEquals("no name change", "name", attribute6.getName().toString());
    Attribute attribute7 = attribute1.setValue("value3");
    assertEquals("add existing value", "value1 value2 value3", attribute7.getValue().toString());
    assertEquals("no name change", "name", attribute7.getName().toString());
    Attribute attribute8 = attribute7.removeValue("value2");
    assertEquals("remove middle value", "value1 value3", attribute8.getValue().toString());
    assertEquals("non-equality", false, attribute8.equals(attribute7));
    assertEquals("no name change", "name", attribute8.getName().toString());
    Attribute attribute9 = attribute3.replaceValue("value2");
    assertEquals("replace value", "value2", attribute9.getValue().toString());
    assertEquals("replace same value, no new attribute", attribute9, attribute3);
    assertEquals("no name change", "name", attribute9.getName().toString());
}
Also used : Attribute(com.vladsch.flexmark.util.html.Attribute) Test(org.junit.Test)

Example 2 with Attribute

use of com.vladsch.flexmark.util.html.Attribute in project flexmark-java by vsch.

the class FlexmarkHtmlParser method transferToParentOnly.

private void transferToParentOnly(String... includes) {
    if (myStateStack.isEmpty())
        throw new IllegalStateException("transferIdToParent with an empty stack");
    final Attributes attributes = new Attributes();
    for (String include : includes) {
        Attribute attribute = myState.myAttributes.get(include);
        if (attribute != null) {
            myState.myAttributes.remove(include);
            attributes.addValue(attribute);
        }
    }
    if (!attributes.isEmpty()) {
        final State parentState = myStateStack.peek();
        for (String attrName : attributes.keySet()) {
            parentState.myAttributes.addValue(attributes.get(attrName));
        }
    }
}
Also used : Attribute(com.vladsch.flexmark.util.html.Attribute) Attributes(com.vladsch.flexmark.util.html.Attributes)

Example 3 with Attribute

use of com.vladsch.flexmark.util.html.Attribute in project flexmark-java by vsch.

the class FlexmarkHtmlParser method transferIdToParent.

void transferIdToParent() {
    if (myStateStack.isEmpty())
        throw new IllegalStateException("transferIdToParent with an empty stack");
    final Attribute attribute = myState.myAttributes.get("id");
    myState.myAttributes.remove("id");
    if (attribute != null && !attribute.getValue().isEmpty()) {
        myStateStack.peek().myAttributes.addValue("id", attribute.getValue());
    }
}
Also used : Attribute(com.vladsch.flexmark.util.html.Attribute)

Aggregations

Attribute (com.vladsch.flexmark.util.html.Attribute)3 Attributes (com.vladsch.flexmark.util.html.Attributes)1 Test (org.junit.Test)1