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

StructuralNode#setLevel is missing #931

Closed
ggrossetie opened this issue Jun 18, 2020 · 3 comments · Fixed by #934
Closed

StructuralNode#setLevel is missing #931

ggrossetie opened this issue Jun 18, 2020 · 3 comments · Fixed by #934

Comments

@ggrossetie
Copy link
Member

Unless I'm missing something, I think that setLevel is missing from StructuralNode right?

level is defined as an attribute accessor so it should be possible to set the value:
https://github.com/asciidoctor/asciidoctor/blob/cb7c20593344bda9bc968a619b02065d3401ad29/lib/asciidoctor/abstract_block.rb#L18-L19

In Ruby, I can do:

section.level = 1

If the method is indeed missing, is there a workaround? (i.e. casting the objet to access low-level methods?)

@robertpanzer
Copy link
Member

Honestly I never considered this property to be set by anybody else but the parser (or to be it simply computed from the level in the AST).
It looks like I was wrong and I'll add a setter soon.

Until then you can set the level like this:

        RubyObjectWrapper rubyBlock = (RubyObjectWrapper) block;
        Ruby ruby = rubyBlock.getRubyObject().getRuntime();
        rubyBlock.setRubyProperty("@level", ruby.newFixnum(42));

@ggrossetie
Copy link
Member Author

For reference, I'm using this method to "flatten" a document in order to have only first level sections (i.e. not nested sections).
Basically, the following:

= Document

== Section 1

=== Section 1.1

== Section 2

gets transformed into:

= Document

== Section 1

== Section 1.1

== Section 2

(can be useful when you convert an AsciiDoc document into slides)

@robertpanzer
Copy link
Member

I see, @level is set when a block is created.

robertpanzer added a commit to robertpanzer/asciidoctorj that referenced this issue Jun 28, 2020
robertpanzer added a commit that referenced this issue Jul 3, 2020
Fixes #931. Add method StructuralNode.setLevel()
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

Successfully merging a pull request may close this issue.

2 participants