diff --git a/core/src/main/scala/com/lightbend/paradox/markdown/StyledVerbatim.scala b/core/src/main/scala/com/lightbend/paradox/markdown/StyledVerbatim.scala index 26ad3e52..30e24b78 100644 --- a/core/src/main/scala/com/lightbend/paradox/markdown/StyledVerbatim.scala +++ b/core/src/main/scala/com/lightbend/paradox/markdown/StyledVerbatim.scala @@ -47,9 +47,11 @@ abstract class StyledVerbatimSerializer extends VerbatimSerializer { node match { case vgn: VerbatimGroupNode => + printer.print("""""") vgn.getSourceUrl.ifPresent(new Consumer[String] { - override def accept(sourceUrl: String): Unit = - printer.print(s"""""") + override def accept(sourceUrl: String): Unit = { + printer.print(s"""source""") + } }) case _ => } diff --git a/plugin/src/sbt-test/paradox/default-theme/expected/index.html b/plugin/src/sbt-test/paradox/default-theme/expected/index.html index ae9e0685..882fa4b0 100644 --- a/plugin/src/sbt-test/paradox/default-theme/expected/index.html +++ b/plugin/src/sbt-test/paradox/default-theme/expected/index.html @@ -12,6 +12,7 @@ + diff --git a/plugin/src/sbt-test/paradox/default-theme/expected/sub/indexed.html b/plugin/src/sbt-test/paradox/default-theme/expected/sub/indexed.html index efca0ac2..3b8d5893 100644 --- a/plugin/src/sbt-test/paradox/default-theme/expected/sub/indexed.html +++ b/plugin/src/sbt-test/paradox/default-theme/expected/sub/indexed.html @@ -12,6 +12,7 @@ + diff --git a/plugin/src/sbt-test/paradox/default-theme/expected/sub/unindexed.html b/plugin/src/sbt-test/paradox/default-theme/expected/sub/unindexed.html index 65d9e700..365b7f37 100644 --- a/plugin/src/sbt-test/paradox/default-theme/expected/sub/unindexed.html +++ b/plugin/src/sbt-test/paradox/default-theme/expected/sub/unindexed.html @@ -12,6 +12,7 @@ + diff --git a/plugin/src/sbt-test/paradox/snippet-absolute/docs/expected/absolute.html b/plugin/src/sbt-test/paradox/snippet-absolute/docs/expected/absolute.html index f5e769b3..f5af37e7 100644 --- a/plugin/src/sbt-test/paradox/snippet-absolute/docs/expected/absolute.html +++ b/plugin/src/sbt-test/paradox/snippet-absolute/docs/expected/absolute.html @@ -1 +1 @@ -
val snippet = 0
\ No newline at end of file
+val snippet = 0
\ No newline at end of file
diff --git a/plugin/src/sbt-test/paradox/snippet-noindent-writer/expected/index.html b/plugin/src/sbt-test/paradox/snippet-noindent-writer/expected/index.html
index 4c15062a..571cd8ad 100644
--- a/plugin/src/sbt-test/paradox/snippet-noindent-writer/expected/index.html
+++ b/plugin/src/sbt-test/paradox/snippet-noindent-writer/expected/index.html
@@ -1,6 +1,6 @@
object Hello extends App {
+object Hello extends App {
def say(str: String): Unit = {
println(str)
}
@@ -10,7 +10,7 @@
object Hello extends App {
+object Hello extends App {
def say(str: String): Unit = {
println(str)
}
diff --git a/plugin/src/sbt-test/paradox/snippets/expected/configured-bases.html b/plugin/src/sbt-test/paradox/snippets/expected/configured-bases.html
index 8ad3a6b3..1254ab45 100644
--- a/plugin/src/sbt-test/paradox/snippets/expected/configured-bases.html
+++ b/plugin/src/sbt-test/paradox/snippets/expected/configured-bases.html
@@ -1,4 +1,4 @@
-val foo = 42
-val foo = 42
-val foo = 42
-val foo = 42
\ No newline at end of file
+val foo = 42
+val foo = 42
+val foo = 42
+val foo = 42
\ No newline at end of file
diff --git a/plugin/src/sbt-test/paradox/snippets/expected/group.html b/plugin/src/sbt-test/paradox/snippets/expected/group.html
index c7113739..48a0f3b9 100644
--- a/plugin/src/sbt-test/paradox/snippets/expected/group.html
+++ b/plugin/src/sbt-test/paradox/snippets/expected/group.html
@@ -1,2 +1,2 @@
-private class SomethingElse
-import scala.util.Try
\ No newline at end of file
+private class SomethingElse
+import scala.util.Try
\ No newline at end of file
diff --git a/plugin/src/sbt-test/paradox/snippets/expected/multiple.html b/plugin/src/sbt-test/paradox/snippets/expected/multiple.html
index 717998d5..98a9b794 100644
--- a/plugin/src/sbt-test/paradox/snippets/expected/multiple.html
+++ b/plugin/src/sbt-test/paradox/snippets/expected/multiple.html
@@ -1,10 +1,10 @@
-import scala.concurrent.duration._
+import scala.concurrent.duration._
case class Measurement(method: Method, duration: Duration)
-import scala.util.Try
+import scala.util.Try
def parseInt(s: String): Option[Int] = Try(s.toInt).toOption
-# HTTP Configuration
+# HTTP Configuration
http {
port=80
host=0.0.0.0
diff --git a/plugin/src/sbt-test/paradox/snippets/expected/nocode.html b/plugin/src/sbt-test/paradox/snippets/expected/nocode.html
index 6b838a24..e822affe 100644
--- a/plugin/src/sbt-test/paradox/snippets/expected/nocode.html
+++ b/plugin/src/sbt-test/paradox/snippets/expected/nocode.html
@@ -1,4 +1,4 @@
-certpath: -Using checker7 ... [sun.security.provider.certpath.RevocationChecker]
+certpath: -Using checker7 ... [sun.security.provider.certpath.RevocationChecker]
certpath: connecting to OCSP service at: http://gtssl2-ocsp.geotrust.com
certpath: OCSP response status: SUCCESSFUL
certpath: OCSP response type: basic
diff --git a/plugin/src/sbt-test/paradox/snippets/expected/reference.html b/plugin/src/sbt-test/paradox/snippets/expected/reference.html
index b1c7fa11..171a2aec 100644
--- a/plugin/src/sbt-test/paradox/snippets/expected/reference.html
+++ b/plugin/src/sbt-test/paradox/snippets/expected/reference.html
@@ -1,4 +1,4 @@
-# This should be included
+# This should be included
#and this as well
snippets {
@@ -6,5 +6,5 @@
snip = "snap"
}
-# this snip is a snap
+# this snip is a snap
snip = "snap"
diff --git a/plugin/src/sbt-test/paradox/snippets/expected/snippets.html b/plugin/src/sbt-test/paradox/snippets/expected/snippets.html
index bc16abac..854e0f7a 100644
--- a/plugin/src/sbt-test/paradox/snippets/expected/snippets.html
+++ b/plugin/src/sbt-test/paradox/snippets/expected/snippets.html
@@ -1,8 +1,8 @@
-def indented = {
+def indented = {
1 + 2
}
-snippets {
+snippets {
test = 1
}
-val symbols = Seq('symbols, Symbol("@"), 'EOL)
-val spacy = "Please do not remove ending spaces after these markers"
+val symbols = Seq('symbols, Symbol("@"), 'EOL)
+val spacy = "Please do not remove ending spaces after these markers"
diff --git a/plugin/src/sbt-test/paradox/snippets/expected/some-xml.html b/plugin/src/sbt-test/paradox/snippets/expected/some-xml.html
index aa75dc31..d3ea360f 100644
--- a/plugin/src/sbt-test/paradox/snippets/expected/some-xml.html
+++ b/plugin/src/sbt-test/paradox/snippets/expected/some-xml.html
@@ -1,3 +1,3 @@
-<bar>
+<bar>
XML FTW
</bar>
diff --git a/tests/src/test/scala/com/lightbend/paradox/markdown/IncludeDirectiveSpec.scala b/tests/src/test/scala/com/lightbend/paradox/markdown/IncludeDirectiveSpec.scala
index b981dc90..b68b5b96 100644
--- a/tests/src/test/scala/com/lightbend/paradox/markdown/IncludeDirectiveSpec.scala
+++ b/tests/src/test/scala/com/lightbend/paradox/markdown/IncludeDirectiveSpec.scala
@@ -53,7 +53,7 @@ class IncludeDirectiveSpec extends MarkdownBaseSpec {
it should "include nested code snippets" in {
markdown("""@@include(tests/src/test/resources/include-code-snip.md)""") shouldEqual html("""
|
- |
+ |
|a = b
|
""")
}
diff --git a/tests/src/test/scala/com/lightbend/paradox/markdown/SnipDirectiveSpec.scala b/tests/src/test/scala/com/lightbend/paradox/markdown/SnipDirectiveSpec.scala
index 8d90c6ab..e178a0a8 100644
--- a/tests/src/test/scala/com/lightbend/paradox/markdown/SnipDirectiveSpec.scala
+++ b/tests/src/test/scala/com/lightbend/paradox/markdown/SnipDirectiveSpec.scala
@@ -31,7 +31,7 @@ class SnipDirectiveSpec extends MarkdownBaseSpec {
"The `snip` directive" should "render code snippets" in {
markdown("""@@snip[example.scala](tests/src/test/scala/com/lightbend/paradox/markdown/example.scala) { #example }""") shouldEqual html("""
|
- |
+ |
|object example extends App {
| println("Hello, World!")
|}
@@ -50,7 +50,7 @@ class SnipDirectiveSpec extends MarkdownBaseSpec {
|Scala
|
|
- |
+ |
|object example extends App {
| println("Hello, World!")
|}
@@ -59,7 +59,7 @@ class SnipDirectiveSpec extends MarkdownBaseSpec {
|Java
|
|
- |
+ |
|public class example2 {
| public static void main(String[] args) {
| System.out.println("Hello, World");
@@ -75,7 +75,7 @@ class SnipDirectiveSpec extends MarkdownBaseSpec {
|@@snip[example2.java](tests/src/test/scala/com/lightbend/paradox/markdown/example2.java){ #example2 .red .blue }
|""") shouldEqual html("""
|
- |
+ |
|public class example2 {
| public static void main(String[] args) {
| System.out.println("Hello, World");
@@ -87,7 +87,7 @@ class SnipDirectiveSpec extends MarkdownBaseSpec {
it should "trim indentation from snippets" in {
markdown("""@@snip[example.scala](tests/src/test/scala/com/lightbend/paradox/markdown/example.scala) { #indented-example }""") shouldEqual html("""
|
- |
+ |
|case object Dent
| case object DoubleDent
|
""")
@@ -96,7 +96,7 @@ class SnipDirectiveSpec extends MarkdownBaseSpec {
it should "not truncate snippets" in {
markdown("""@@snip[example.scala](tests/src/test/scala/com/lightbend/paradox/markdown/example.scala) { #multi-indented-example }""") shouldEqual html("""
|
- |
+ |
|object AnotherIndentedExample {
| def rendered(): Unit = {
| }
@@ -106,7 +106,7 @@ class SnipDirectiveSpec extends MarkdownBaseSpec {
|
""")
}
- it should "add link to source" in {
+ it should "add link to source and copy button" in {
implicit val context = writerContextWithProperties(
"github.base_url" -> "https://github.com/lightbend/paradox/tree/v0.2.1",
"github.root.base_dir" -> new File(".").getAbsoluteFile.getParent,
@@ -114,7 +114,7 @@ class SnipDirectiveSpec extends MarkdownBaseSpec {
markdown("""@@snip[example.scala](tests/src/test/scala/com/lightbend/paradox/markdown/example.scala) { #example }""") shouldEqual html(
"""
- |
+ |source
|object example extends App {
| println("Hello, World!")
|}
@@ -131,7 +131,7 @@ class SnipDirectiveSpec extends MarkdownBaseSpec {
markdown("""@@snip[example.scala]($test$/example.scala) { #example }""") shouldEqual html(
"""
- |
+ |source
|object example extends App {
| println("Hello, World!")
|}
@@ -147,7 +147,7 @@ class SnipDirectiveSpec extends MarkdownBaseSpec {
markdown("""@@snip[example.scala](tests/src/test/scala/com/lightbend/paradox/markdown/example.scala) { #example }""") shouldEqual html(
"""
- |
+ |
|object example extends App {
| println("Hello, World!")
|}
@@ -157,7 +157,7 @@ class SnipDirectiveSpec extends MarkdownBaseSpec {
it should "include labels when including the whole file" in {
markdown("""@@snip[example.scala](tests/src/test/scala/com/lightbend/paradox/markdown/example.scala)""") shouldEqual html(
"""
- |
+ |
|/*
| * Copyright © 2015 - 2019 Lightbend, Inc. <http://www.lightbend.com>
| *
@@ -247,7 +247,7 @@ class SnipDirectiveSpec extends MarkdownBaseSpec {
it should "filter labels by default" in {
markdown("""@@snip[example.scala](tests/src/test/scala/com/lightbend/paradox/markdown/example.scala) { #example-with-label }""") shouldEqual html(
"""
- |
+ |
|object Constants {
|}
|
"""
@@ -257,7 +257,7 @@ class SnipDirectiveSpec extends MarkdownBaseSpec {
it should "allow including labels if specified" in {
markdown("""@@snip[example.scala](tests/src/test/scala/com/lightbend/paradox/markdown/example.scala) { #example-with-label filterLabels=false }""") shouldEqual html(
"""
- |
+ |
|object Constants {
| val someString = " #foo "
|}
diff --git a/themes/generic/src/main/assets/css/page.css b/themes/generic/src/main/assets/css/page.css
index f4a36e62..7be66ced 100644
--- a/themes/generic/src/main/assets/css/page.css
+++ b/themes/generic/src/main/assets/css/page.css
@@ -149,15 +149,29 @@ a.anchor .anchor-link:before {
content: "ยง";
}
-a.go-to-source::before {
- content: "๐";
+.site-content .page-content .prettyprint .snippet-button {
+ float: right;
+ text-decoration: none;
+ font-size: 0.75rem;
+ font-weight: bold;
+ font-family: "Roboto", "Helvetica Neue", "Helvetica", Arial, sans-serif;
+ speak: none;
+ color: #4078c0;
+ border: 2px solid #e5e6e4;
+ padding: 4px 4px;
+ margin-left: 8px;
+ line-height: 1.2;
+ vertical-align: middle;
+ -webkit-font-smoothing: antialiased;
+ -moz-osx-font-smoothing: grayscale;
}
-.prettyprint .icon {
- float: right;
+.site-content .page-content .prettyprint .snippet-button:hover {
+ background-color: #e5e6e4;
+ border: 2px solid #4078c0;
}
-a.anchor .anchor-link, .icon {
+a.anchor .anchor-link {
font-size: 18px;
font-family: "icons" !important;
font-style: normal !important;
diff --git a/themes/generic/src/main/assets/js/snippets.js b/themes/generic/src/main/assets/js/snippets.js
new file mode 100644
index 00000000..a0d6c869
--- /dev/null
+++ b/themes/generic/src/main/assets/js/snippets.js
@@ -0,0 +1,6 @@
+$(function() {
+ $(".snippet-button.copy-snippet").click(function() {
+ var code = $(this).parent().find("code").text()
+ navigator.clipboard.writeText(code)
+ })
+})
\ No newline at end of file
diff --git a/themes/generic/src/main/assets/page.st b/themes/generic/src/main/assets/page.st
index 50d752ff..f61430b3 100644
--- a/themes/generic/src/main/assets/page.st
+++ b/themes/generic/src/main/assets/page.st
@@ -14,6 +14,7 @@ $endif$
+