-
Notifications
You must be signed in to change notification settings - Fork 76
Tab-group switching for snippets #95
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright © 2015 - 2016 Lightbend, Inc. <http://www.lightbend.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.pegdown.ast; | ||
|
||
public class VerbatimGroupNode extends VerbatimNode { | ||
private final String group; | ||
|
||
public VerbatimGroupNode(String text) { | ||
this(text, "", ""); | ||
} | ||
|
||
public VerbatimGroupNode(String text, String type) { | ||
this(text, type, ""); | ||
} | ||
|
||
public VerbatimGroupNode(String text, String type, String group) { | ||
super(text, type); | ||
this.group = group; | ||
} | ||
|
||
@Override | ||
public void accept(Visitor visitor) { | ||
visitor.visit(this); | ||
} | ||
|
||
public String getGroup() { | ||
return group; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,45 @@ should not be highlighted set `type=text` in the directive's attribute section: | |
@@snip [example.log](example.log) { #example-log type=text } | ||
``` | ||
|
||
#### tab switching | ||
|
||
It is possible to associate multiple snippets under the same "tag". If some tab of a snippet is switched by the user, all tabs associated with the selected one will be switched as well. To associate snippet tabs under some tag, set the `group` field of the snippet: | ||
|
||
@@@vars | ||
```markdown | ||
First-java | ||
: @@snip [example-first.java](../../resources/tab-switching/examples.java) { #java_first group=java } | ||
$empty$ | ||
First-scala | ||
: @@snip [example-first.scala](../../resources/tab-switching/examples.scala) { #scala_first group=scala } | ||
$empty$ | ||
Some separator. | ||
$empty$ | ||
Second-java | ||
: @@snip [example-second.java](../../resources/tab-switching/examples.java) { #java_second group=java } | ||
$empty$ | ||
Second-scala | ||
: @@snip [example-second.scala](../../resources/tab-switching/examples.scala) { #scala_second group=scala } | ||
``` | ||
@@@ | ||
|
||
The result will be rendered like this (try to switch tabs): | ||
|
||
First-java | ||
: @@snip [example-first.java](../../resources/tab-switching/examples.java) { #java_first group=java } | ||
|
||
First-scala | ||
: @@snip [example-first.scala](../../resources/tab-switching/examples.scala) { #scala_first group=scala } | ||
|
||
Some separator. | ||
|
||
Second-java | ||
: @@snip [example-second.java](../../resources/tab-switching/examples.java) { #java_second group=java } | ||
|
||
Second-scala | ||
: @@snip [example-second.scala](../../resources/tab-switching/examples.scala) { #scala_second group=scala } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAIC there is not way to provide grouping for tabs which contain inline text (not a snippet). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, would be good to have an approach that supports anything in the tab, rather than relying on the group attribute in snippets. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the current tab grouping allow different types of groups? For example, Java/Scala and sbt/Maven/Gradle on the same page. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed tabs with inline text are still not supported, but switching arbitrary text is now available in #107. Different types of groups on the same page should be no problem. |
||
|
||
|
||
### snip.*.base_dir | ||
|
||
In order to specify your snippet source paths off certain base directories you can define placeholders | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// #java_first | ||
class JavaFirst { | ||
public static void main(String[] args) { | ||
System.out.println("Hello java!"); | ||
} | ||
} | ||
// #java_first | ||
|
||
// #java_second | ||
class JavaSecond { | ||
public static void main(String[] args) { | ||
System.out.println("Hello java!"); | ||
} | ||
} | ||
// #java_second |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// #scala_first | ||
object ScalaFirst extends App { | ||
println("Hello scala!") | ||
} | ||
// #scala_first | ||
|
||
// #scala_second | ||
object ScalaSecond extends App { | ||
println("Hello scala!") | ||
} | ||
// #scala_second |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<pre class="prettyprint tab-group-a"><code class="language-scala">private class SomethingElse</code></pre> | ||
<pre class="prettyprint tab-group-b"><code class="language-scala">import scala.util.Try</code></pre> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@@ snip [Group A](../../test/scala/Multiple.scala) { #multiple-something-else group=a } | ||
|
||
@@ snip [Group B](../../test/scala/Multiple.scala) { #parseint-imports group=b } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This tests if the generated HTML is correct, but will the group=b snippet be hidden by default? I have tried it on a project and it looks like that both snippets are always visible. Also if there are no tabbed snippets in the page, then a user will have no way of switching between the two. I think we should add a hover box or other interactive control that would allow switching between the alternatives. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a selectbox for switching in #107 Actually selecting tabs/alternatives is done in javascript, so isn't easy to incorporate in a test... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we should use the tab name for a group if the group is not explicitly defined. This would allow easier feature use for the documentation writers making docs less verbose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tab name doesn't seem too easy to reach at this point, but defaulting to the
lang
seems reasonable, too - applied to #107