spring-io / asciidoctor-extensions

Asciidoctor extensions (currently Asciidoctor.js only) developed for the Spring docs.
Apache License 2.0
2 stars 5 forks source link

Code folding extension doesnt work in antora? #23

Open BaksaZoo opened 1 day ago

BaksaZoo commented 1 day ago

I tried to configure my antora playbook with code-folding-extension but it does not seem to work.

# antora-playbook.yml
asciidoc:
  sourcemap: true
  extensions:
    - '@springio/asciidoctor-extensions/code-folding-extension'

I included this code in one of my pages

[,java]
----
public class Main {

  // @fold:on
  public enum MyEnum {
    MYCONSTANT1,
    MYCONSTANT2,
    MYCONSTANT3
  }
  // @fold:off

  public static void main(String[] args) {
    System.out.println("Hello World");
  }
}
----

Im using the default ui, and installed @springio/asciidoctor-extensions package but no code-folding happens. The build process doesnt report any errors with --stacktrace enabled.

I tried looking for usages in spring project documentations but did not find any. Is there a problem when using this extension with antora or am i just misconfiguring something?

philwebb commented 1 day ago

Here's one usage example:

https://github.com/spring-projects/spring-boot/blob/91778e9f96fa0ab561b43705c67a7236c4cbafe9/spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/features/externalconfig/typesafeconfigurationproperties/javabeanbinding/MyProperties.java#L35

The results are at https://docs.spring.io/spring-boot/reference/features/external-config.html#features.external-config.typesafe-configuration-properties.java-bean-binding

Do you see cold folding on that page? Perhaps you can provide a small sample project that replicates the problem.

BaksaZoo commented 1 day ago

Thank you for providing the usage i can see that code folding should work properly.

I created a simple project to demonstrate the problem and attached it as a zip file. Could you please tell me where did i go wrong?

Edit: Sorry, i made a typo in the readme, fixed it. antora-issue.zip

philwebb commented 1 day ago

It looks like the extension is running as expected, however, the required javascipt isn't being included. If you open build/site/demo-docs/2.0.0/example.html and inspect the HTML you should see the expected fold-block <span> elements.

I'm not an expert on the UI side of things, but I think you'll need to fork https://gitlab.com/antora/antora-ui-default and replace src/js/06-copy-to-clipboard.js with https://github.com/spring-io/antora-ui-spring/blob/24b0ea9bb868390e1ef3290e476fd66788c083d5/src/js/06-source-toolbox.bundle.js.

Alternatively, if you don't mind some Spring styling you can update your playbook.yml:

ui:
  bundle:
    url: "https://github.com/spring-io/antora-ui-spring/releases/download/v0.4.18/ui-bundle.zip"
    snapshot: false

I tried that and it created a working example plage.