Skip to content

Commit

Permalink
[asciidoctor-java] basic html implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
rmannibucau committed Dec 10, 2023
1 parent 9e3f18a commit b71fde8
Show file tree
Hide file tree
Showing 12 changed files with 731 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public boolean test(final Context context) {
}
}

public record Ifeval(String todo) implements Predicate<Context> {
public record Ifeval(Predicate<Context> evaluator) implements Predicate<Context> {
@Override
public boolean test(final Context context) {
return context.attribute(todo) == null;
return evaluator.test(context);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public sealed interface Element permits
Code, DescriptionList, LineBreak, Link, Macro, OrderedList,
Paragraph, Section, Text, UnOrderedList, Admonition, Anchor,
Table, Quote, OpenBlock, PassthroughBlock, ConditionalBlock,
Attribute {
Attribute, PageBreak {
ElementType type();

/**
Expand All @@ -34,6 +34,7 @@ enum ElementType {
PARAGRAPH,
SECTION,
LINE_BREAK,
PAGE_BREAK,
CODE, // including source blocks
UNORDERED_LIST,
ORDERED_LIST,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.yupiik.asciidoc.model;

import java.util.Map;

import static io.yupiik.asciidoc.model.Element.ElementType.PAGE_BREAK;

public record PageBreak(Map<String, String> options) implements Element {
@Override
public ElementType type() {
return PAGE_BREAK;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import static io.yupiik.asciidoc.model.Element.ElementType.PASS_BLOCK;

public record PassthroughBlock(String text, Map<String, String> options) implements Element {
public record PassthroughBlock(String value, Map<String, String> options) implements Element {
@Override
public ElementType type() {
return PASS_BLOCK;
Expand Down
305 changes: 209 additions & 96 deletions asciidoc-java/src/main/java/io/yupiik/asciidoc/parser/Parser.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.yupiik.asciidoc.parser.internal;

import java.util.ArrayList;
import java.util.List;

/**
Expand All @@ -25,7 +26,7 @@ public class Reader {
private int lineOffset = 0;

public Reader(final List<String> lines) {
this.lines = lines;
this.lines = new ArrayList<>(lines);
}

// human indexed
Expand Down Expand Up @@ -81,6 +82,10 @@ public String skipCommentsAndEmptyLines() {
return null;
}

public void setPreviousValue(final String newValue) {
lines.set(lineOffset - 1, newValue);
}

@Override
public String toString() {
return "Reader[current=" + (lineOffset >= lines.size() ? "<none>" : lines.get(lineOffset)) + ", total=" + lines.size() + ", offset=" + lineOffset + "]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

/**
* Simple base class to delegate the visit of a document to a visitor.
* Enables to override only what you need (ex: text handling).
* Enables to override only what you need (ex: value handling).
*
* @param <T> the type of result the delegate visitor computes.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import io.yupiik.asciidoc.model.Macro;
import io.yupiik.asciidoc.model.OpenBlock;
import io.yupiik.asciidoc.model.OrderedList;
import io.yupiik.asciidoc.model.PageBreak;
import io.yupiik.asciidoc.model.Paragraph;
import io.yupiik.asciidoc.model.PassthroughBlock;
import io.yupiik.asciidoc.model.Quote;
Expand Down Expand Up @@ -84,13 +85,18 @@ default void visitElement(final Element element) {
case CODE -> visitCode((Code) element);
case TEXT -> visitText((Text) element);
case LINE_BREAK -> visitLineBreak((LineBreak) element);
case PAGE_BREAK -> visitPageBreak((PageBreak) element);
case PARAGRAPH -> visitParagraph((Paragraph) element);
case SECTION -> visitSection((Section) element);
case CONDITIONAL_BLOCK -> visitConditionalBlock((ConditionalBlock) element);
case ATTRIBUTE -> visitAttribute((Attribute) element);
}
}

default void visitPageBreak(final PageBreak element) {
// no-op
}

default void visitAttribute(final Attribute element) {
final var attribute = context().attribute(element.attribute());
if (attribute != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public class HtmlEscaping implements Function<String, String> {
public static final HtmlEscaping INSTANCE = new HtmlEscaping();

// taken from commons-text
// taken from commons-value
private final Map<Character, String> escaped = Map.ofEntries(
entry('"', "&quot;"),
entry('&', "&amp;"),
Expand Down
Loading

0 comments on commit b71fde8

Please sign in to comment.