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

Fixes data-fragment-index on code block #533

Merged
merged 1 commit into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions examples/release-5.2.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ console.log(a+b); <3>
<2> using the `%step` attribute...
<3> to explain code more easily !

== Synchronising step-by-step syntax highlighting
[.fragment, java, highlight="1|2|3", step=0]
----
Optional<String> foo();
Optional<String> bar();
Optional<String> foobar();
----
[.fragment, data-fragment-index=0]
step-by-step syntax highlighting
[.fragment, data-fragment-index=1]
In combination with data-fragment-index
[.fragment, data-fragment-index=2]
Allow synchronized fragment display

[transition=fade,transition-speed=slow]
== Learn More!

Expand Down
8 changes: 7 additions & 1 deletion lib/asciidoctor-revealjs/highlightjs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,18 @@ def docinfo location, doc, opts
var highlightSteps = RevealHighlight.deserializeHighlightSteps( block.getAttribute( 'data-line-numbers' ) );
if( highlightSteps.length > 1 ) {

// When rendered with asciidoc, data-fragment index if it exists lies on the listing block element, so we have to lookup
// If the original code block has a fragment-index,
// each clone should follow in an incremental sequence
var fragmentIndex = parseInt( block.getAttribute( 'data-fragment-index' ), 10 );
jtama marked this conversation as resolved.
Show resolved Hide resolved
var preCodeWrapper = block.parentElement;
var divContent = preCodeWrapper.parentElement;
var listingBlock = divContent.parentElement;
var fragmentIndex = parseInt( listingBlock.getAttribute( 'data-fragment-index' ), 10 );

if( typeof fragmentIndex !== 'number' || isNaN( fragmentIndex ) ) {
fragmentIndex = null;
} else {
fragmentIndex += 1;
}

// Generate fragments for all steps except the original block
Expand Down
8 changes: 7 additions & 1 deletion test/doctest/source-highlightjs-languages.html
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,18 @@ <h2>Use the Source</h2>
var highlightSteps = RevealHighlight.deserializeHighlightSteps( block.getAttribute( 'data-line-numbers' ) );
if( highlightSteps.length > 1 ) {

// When rendered with asciidoc, data-fragment index if it exists lies on the listing block element, so we have to lookup
// If the original code block has a fragment-index,
// each clone should follow in an incremental sequence
var fragmentIndex = parseInt( block.getAttribute( 'data-fragment-index' ), 10 );
var preCodeWrapper = block.parentElement;
var divContent = preCodeWrapper.parentElement;
var listingBlock = divContent.parentElement;
var fragmentIndex = parseInt( listingBlock.getAttribute( 'data-fragment-index' ), 10 );

if( typeof fragmentIndex !== 'number' || isNaN( fragmentIndex ) ) {
fragmentIndex = null;
} else {
fragmentIndex += 1;
}

// Generate fragments for all steps except the original block
Expand Down
Loading