Skip to content

Commit 76472ed

Browse files
committed
Prevent callouts from being pull up to earlier blocks
Closes gh-68
1 parent 8e80121 commit 76472ed

File tree

3 files changed

+55
-4
lines changed

3 files changed

+55
-4
lines changed

src/main/js/site/tabs.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 the original author or authors.
2+
* Copyright 2021-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the 'License');
55
* you may not use this file except in compliance with the License.
@@ -59,7 +59,7 @@
5959
function createTab(blockElement, tabsElement) {
6060
const title = blockElement.querySelector(".title").textContent;
6161
const content = blockElement.querySelectorAll(".content").item(0);
62-
const colist = nextSibling(blockElement, ".colist");
62+
const colist = nextSibling(blockElement, ".colist", ".listingblock");
6363
if (colist) {
6464
content.append(colist);
6565
}
@@ -72,12 +72,15 @@
7272
return { tabElement: tabElement, content: content };
7373
}
7474

75-
function nextSibling(element, selector) {
75+
function nextSibling(element, selector, stopSelector) {
7676
let sibling = element.nextElementSibling;
7777
while (sibling) {
7878
if (sibling.matches(selector)) {
7979
return sibling;
8080
}
81+
if (sibling.matches(stopSelector)) {
82+
return;
83+
}
8184
sibling = sibling.nextElementSibling;
8285
}
8386
}

src/test/java/io/spring/asciidoctor/backend/integrationtest/TabIntegrationTests.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 the original author or authors.
2+
* Copyright 2021-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -148,6 +148,15 @@ void secondaryBlockWithNoPrimary(@Source("secondaryBlockWithNoPrimary.adoc") Con
148148
assertThat(secondaries).hasSize(1);
149149
}
150150

151+
@Test
152+
void tabsWithAndWithoutCallouts(@Source("tabsWithAndWithoutCallouts.adoc") ConvertedHtml html) throws IOException {
153+
RemoteWebDriver driver = html.inWebBrowser(this.chrome);
154+
List<WebElement> listings = driver.findElementsByCssSelector(".listingblock");
155+
assertThat(listings).hasSize(3);
156+
assertThatTabs(listings.get(0)).hasNoCalloutList();
157+
assertThatTabs(listings.get(2)).hasDisplayedCalloutListContaining("Callout for tab one");
158+
}
159+
151160
private static TabsAssert assertThatTabs(WebElement actual) {
152161
return assertThat(new TabsAssert(actual));
153162
}
@@ -186,6 +195,11 @@ TabsAssert hasDisplayedCalloutListContaining(String contained) {
186195

187196
}
188197

198+
TabsAssert hasNoCalloutList() {
199+
assertThat(this.actual.findElements(By.cssSelector(".colist"))).isEmpty();
200+
return this;
201+
}
202+
189203
TabsAssert uponClicking(String item) {
190204
List<WebElement> unselected = this.actual.findElements(By.cssSelector(".tab:not(.selected)"));
191205
Optional<WebElement> match = unselected.stream().filter((element) -> element.getText().equals(item))
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[source,indent=0,subs="verbatim,quotes",role="primary"]
2+
.One
3+
----
4+
One without callout.
5+
----
6+
7+
[source,indent=0,subs="verbatim,quotes",role="secondary"]
8+
.Two
9+
----
10+
Two without callout.
11+
----
12+
13+
14+
[source,indent=0,subs="verbatim,quotes"]
15+
.No Tabs
16+
----
17+
No tabs with callout <1>
18+
----
19+
<1> Callout without tab
20+
21+
22+
[source,indent=0,subs="verbatim,quotes",role="primary"]
23+
.One
24+
----
25+
One with callout <1>
26+
----
27+
<1> Callout for tab one
28+
29+
[source,indent=0,subs="verbatim,quotes",role="secondary"]
30+
.Two
31+
----
32+
Two with callout <1>
33+
----
34+
<1> Callout for tab two

0 commit comments

Comments
 (0)