Skip to content

Commit 1c369db

Browse files
authored
Merge pull request #46 from ep-skolberg/master
Add license report type for confluence wiki markup
2 parents e48b9ac + fef901b commit 1c369db

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/main/scala/sbtlicensereport/SbtLicenseReport.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ object SbtLicenseReport extends AutoPlugin {
1919
def Html = sbtlicensereport.license.Html
2020
def MarkDown = sbtlicensereport.license.MarkDown
2121
def Csv = sbtlicensereport.license.Csv
22+
def ConfluenceWikiMarkup = sbtlicensereport.license.ConfluenceWikiMarkup
2223

2324
// Keys
2425
val updateLicenses = taskKey[LicenseReport]("Construct a report of used licenses in a build.")

src/main/scala/sbtlicensereport/license/TargetLanguage.scala

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,40 @@ case object Csv extends TargetLanguage {
100100
def tableEnd: String = ""
101101
def csvEncode(s: String): String = org.apache.commons.lang3.StringEscapeUtils.escapeCsv(s)
102102
}
103+
104+
case object ConfluenceWikiMarkup extends TargetLanguage {
105+
val ext = "confluence.mu"
106+
def documentStart(title: String, reportStyleRules: Option[String]): String = ""
107+
def documentEnd(): String = ""
108+
def createHyperLink(link: String, content: String): String = s"[${trim(content)}|${trim(link)}]"
109+
def blankLine(): String = "\n"
110+
def header1(msg: String): String = s"h1.$msg\n"
111+
def tableHeader(firstColumn: String, secondColumn: String, thirdColumn: String, fourthColumn: String): String = {
112+
s"|| $firstColumn || $secondColumn || $thirdColumn || $fourthColumn ||\n"
113+
}
114+
115+
def tableRow(
116+
firstColumn: String,
117+
secondColumn: String,
118+
thirdColumn: String,
119+
fourthColumn: String
120+
): String = s"| $firstColumn | $secondColumn | $thirdColumn | $fourthColumn |\n"
121+
def tableEnd: String = "\n"
122+
123+
def markdownEncode(s: String): String = s.flatMap {
124+
case c if (List('*', '`', '[', ']', '#', '|').contains(c)) => "\\" + c
125+
case x => x.toString
126+
}
127+
128+
def escapeHtml(s: String): String = Html.htmlEncode(s).flatMap {
129+
case '|' => "|" // it would destroy tables!
130+
case c => c.toString
131+
}
132+
133+
/** Null handling trim utility function. */
134+
private[this] def trim(in: String): String = {
135+
Option(in).fold("") { string =>
136+
string.trim
137+
}
138+
}
139+
}

0 commit comments

Comments
 (0)