Skip to content

Commit

Permalink
Merge pull request #46 from ep-skolberg/master
Browse files Browse the repository at this point in the history
Add license report type for confluence wiki markup
  • Loading branch information
eed3si9n authored Apr 17, 2023
2 parents e48b9ac + fef901b commit 1c369db
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/scala/sbtlicensereport/SbtLicenseReport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ object SbtLicenseReport extends AutoPlugin {
def Html = sbtlicensereport.license.Html
def MarkDown = sbtlicensereport.license.MarkDown
def Csv = sbtlicensereport.license.Csv
def ConfluenceWikiMarkup = sbtlicensereport.license.ConfluenceWikiMarkup

// Keys
val updateLicenses = taskKey[LicenseReport]("Construct a report of used licenses in a build.")
Expand Down
37 changes: 37 additions & 0 deletions src/main/scala/sbtlicensereport/license/TargetLanguage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,40 @@ case object Csv extends TargetLanguage {
def tableEnd: String = ""
def csvEncode(s: String): String = org.apache.commons.lang3.StringEscapeUtils.escapeCsv(s)
}

case object ConfluenceWikiMarkup extends TargetLanguage {
val ext = "confluence.mu"
def documentStart(title: String, reportStyleRules: Option[String]): String = ""
def documentEnd(): String = ""
def createHyperLink(link: String, content: String): String = s"[${trim(content)}|${trim(link)}]"
def blankLine(): String = "\n"
def header1(msg: String): String = s"h1.$msg\n"
def tableHeader(firstColumn: String, secondColumn: String, thirdColumn: String, fourthColumn: String): String = {
s"|| $firstColumn || $secondColumn || $thirdColumn || $fourthColumn ||\n"
}

def tableRow(
firstColumn: String,
secondColumn: String,
thirdColumn: String,
fourthColumn: String
): String = s"| $firstColumn | $secondColumn | $thirdColumn | $fourthColumn |\n"
def tableEnd: String = "\n"

def markdownEncode(s: String): String = s.flatMap {
case c if (List('*', '`', '[', ']', '#', '|').contains(c)) => "\\" + c
case x => x.toString
}

def escapeHtml(s: String): String = Html.htmlEncode(s).flatMap {
case '|' => "|" // it would destroy tables!
case c => c.toString
}

/** Null handling trim utility function. */
private[this] def trim(in: String): String = {
Option(in).fold("") { string =>
string.trim
}
}
}

0 comments on commit 1c369db

Please sign in to comment.