Skip to content

Instantly share code, notes, and snippets.

@tindzk
Created July 7, 2018 11:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tindzk/bfdb967b9ffcf8bc8ae2ba3abdbf0875 to your computer and use it in GitHub Desktop.
Save tindzk/bfdb967b9ffcf8bc8ae2ba3abdbf0875 to your computer and use it in GitHub Desktop.
Prefix all referenced CSS tags in HTML files
[project]
scalaVersion = "2.12.4-bin-typelevel-4"
scalaOptions = ["-Yliteral-types"]
scalaOrganisation = "org.typelevel"
[module.app.jvm]
root = "."
sources = ["src"]
scalaDeps = [
["tech.sparse", "pine", "0.1.3"],
["com.github.pathikrit", "better-files", "3.5.0"]
]
import pine._
import better.files._
// Place file in src/
object PrefixClasses extends App {
File.currentWorkingDirectory.glob("*.html").foreach { file =>
val newContent = HtmlParser.fromString(file.contentAsString).map {
case t: Tag[_] => t.`class`.update(_.map(cls =>
if (cls.startsWith("sk-")) cls else "sk-" + cls))
case n => n
}
file.write(newContent.toHtml)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment