Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the AsciidoctorJ Extension API #3

Open
ggrossetie opened this issue Jan 23, 2019 · 1 comment
Open

Implement the AsciidoctorJ Extension API #3

ggrossetie opened this issue Jan 23, 2019 · 1 comment

Comments

@ggrossetie
Copy link
Owner

Using Java extension is not an easy task because we need to register dynamically a Java function an call it from JavaScript with instance (instantiated in the JavaScript engine).

Let's take an example:

public class YellBlock extends BlockProcessor {

  public YellBlock(String name, Map<String, Object> config) {
    super(name, config);
  }

  @Override
  public Object process(StructuralNode parent, Reader reader, Map<String, Object> attributes) {
    List<String> lines = reader.readLines();
    String upperLines = lines.stream().map(String::toUpperCase).collect(Collectors.joining("\n"));
    return createBlock(parent, "paragraph", Arrays.asList(upperLines), attributes, new HashMap<>());
  }
}

In the example above, we need to call the process method from JavaScript with a StructuralNode instance, a Reader instance and a Map of attributes.
The JavaScript runtime has a parent and a reader object in memory but these objects are not available in Java.
The Java code is also calling the createBlock method with a StructuralNode (Java), so again we need to resolve this object in the JavaScript runtime.

Technically using a shared memory with "pointer" in the JavaScript runtime is working but I don't know if it's the best approach here.

@ggrossetie
Copy link
Owner Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant