Skip to content

Commit

Permalink
Fixes data-fragment-index on code block
Browse files Browse the repository at this point in the history
  • Loading branch information
jtama committed May 2, 2024
1 parent 8484b01 commit f8ef253
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/asciidoctor-revealjs/highlightjs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,13 @@ 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 );
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;
Expand Down
6 changes: 5 additions & 1 deletion test/doctest/source-highlightjs-languages.html
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,13 @@ <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;
Expand Down

0 comments on commit f8ef253

Please sign in to comment.