Add demo for displaying query result kwics

Change-Id: Ifc802b5b9a94ad52aeeab58eeda080b2f41ed18d
diff --git a/demo/00Index b/demo/00Index
index 4a9a3c8..7ff8cf1 100644
--- a/demo/00Index
+++ b/demo/00Index
@@ -7,3 +7,5 @@
 highcharter-example       Visualize frqequencies of optionally alternative terms over time with interactive HTML and JavaScript elements using the package highcharter as wrapper for Highcharts
 shiny-frequency-curves    Web application that plots frequency curves with highcharts and shiny
 writtenVsSpoken           Compare frequencies in written vs. spoken corpora
+displayKwics              Display query results as KWICs via html
+
diff --git a/demo/displayKwics.R b/demo/displayKwics.R
new file mode 100644
index 0000000..b57aae7
--- /dev/null
+++ b/demo/displayKwics.R
@@ -0,0 +1,79 @@
+library(RKorAPClient)
+
+displayKwics <- function(q, htmlFile = file.path(tempfile(fileext = ".html"))) {
+  cat(
+    '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+    <!DOCTYPE html>
+    <html>
+     <header>
+      <style>
+            body {
+              font-family: "Lato", sans-serif;
+              font-size: 10pt;
+            }
+            div.kwic {
+                display: table-row;
+                line-height: 180%;
+            }
+            div.kwic:nth-child(even) {background: #EEE}
+            div.kwic:nth-child(odd) {background: #FFF}
+            .sigle {
+                font-size: 90%;
+                font-family: "Courier New", monospace;
+                display: table-cell;
+                text-align: right;
+                padding-right: 1ex;
+            }
+            .context-left {
+                display: table-cell;
+                text-align: right;
+                overflow: hidden;
+                white-space: nowrap;
+            }
+            .context-right {
+                display: table-cell;
+                text-align: left;
+                white-space: nowrap;
+                overflow: hidden;
+            }
+            .match {
+                display: table-cell;
+                padding-left: 1ex;
+                padding-right: 1ex;
+                text-align: center;
+            }
+      </style>
+    </header>
+    <body>
+      <table>',
+    paste0(
+      "<div class='kwic'><span class='sigle'>",
+      q@collectedMatches$textSigle,
+      "</span> ",
+      as.character(q@collectedMatches$snippet),
+      "</div>"
+    ),
+    '      </table>
+    </body>
+</html>',
+    file = htmlFile,
+    sep = "\n"
+  )
+  viewer <- getOption("viewer")
+  viewer(htmlFile)
+}
+
+kco <- new("KorAPConnection", verbose = TRUE)
+if (is.null(kco@accessToken)) {
+  message(
+    paste0(
+      "In order to receive KWICSs also from corpora with restricted licenses, you need an access token.\n",
+      "To generate an access token, login to KorAP and navigite to KorAP's OAuth settings <",
+      kco@KorAPUrl,
+      "settings/oauth#page-top>"
+    )
+  )
+}
+q <- corpusQuery(kco, "Ameisenplage", metadataOnly = F) %>%
+  fetchAll() %>%
+  displayKwics()