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

Load() and convert() has different behaviour as convert() #25

Open
gillesB opened this issue May 6, 2022 · 1 comment
Open

Load() and convert() has different behaviour as convert() #25

gillesB opened this issue May 6, 2022 · 1 comment

Comments

@gillesB
Copy link

gillesB commented May 6, 2022

Hello,

I am not sure if the following is a bug or a feature and if this is the right project to post this issue.

Anyhow I created a simple .adoc with a PlantUml diagram and I want to convert it to HTML.

# Foo

:imagesdir: images

.Title (optional)
[plantuml]
--
abstract class AbstractList
abstract AbstractCollection
interface List
interface Collection

List <|-- AbstractList
Collection <|-- AbstractCollection

Collection <|- List
AbstractCollection <|- AbstractList
AbstractList <|-- ArrayList

class ArrayList {
  Object[] elementData
  size()
}

enum TimeUnit {
  DAYS
  HOURS
  MINUTES
}

annotation SuppressWarnings
--

When converting the .adoc I expect that a .png will be created in the images-folder.
This folder should be a sibling of the actual document.

The following code does this as expected but only if doctor.convert(text, options); is called.
If I call Document doc = doctor.load(text, options); String converted = doc.convert(); the .png is created but in the wrong images-folder.
This images-folder is a child of my current working folder.

public class Test {

	public static void main(String[] args) throws IOException {
		String absPath = "C:/Users/gilles.baatz/git/gilles/PlantumlTest/src/main/resources/foobar/test.adoc";
		Path absPathAdoc = Paths.get(absPath);
		String text = Files.readString(absPathAdoc);

		Path parent = absPathAdoc.getParent();
		Path images = parent.resolve("images");
		Files.createDirectories(images);
		Files.walk(images)
		     .sorted(Comparator.reverseOrder())
		     .map(Path::toFile)
		     .forEach(File::delete);
		Files.createDirectories(images);

		Asciidoctor doctor = Asciidoctor.Factory.create();
		doctor.requireLibrary("asciidoctor-diagram");
		System.out.println("HTML creation");

		Options options = Options.builder()
		                         .backend("html5")
		                         .baseDir(parent.toFile())
		                         .safe(SafeMode.UNSAFE)
		                         .sourcemap(true)
		                         .headerFooter(false)
		                         .build();

                // Does not work as expected: images will be created at "C:/Users/gilles.baatz/git/gilles/PlantumlTest/images"
		System.out.println("load then convert");
		Document doc = doctor.load(text, options);
		String converted = doc.convert();
		Files.list(images).forEach(p -> System.out.println(p));
                // no files printed

		System.out.println("only convert");
		doctor.convert(text, options);

		Files.list(images).forEach(p -> System.out.println(p));
                // one file printed
	}
}
@robertpanzer
Copy link
Member

You might want to open this ticket against asciidoctor/asciidoctor-diagram. This repository is just a repackaging of that gem.

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

2 participants