Skip to content

Commit

Permalink
Process HTML files like markdown files, fixes #199. (#200)
Browse files Browse the repository at this point in the history
Process HTML files like markdown files, fixes #199.
  • Loading branch information
olafurpg authored Oct 31, 2019
2 parents 8ce1073 + c273908 commit d3d4c8e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
8 changes: 5 additions & 3 deletions mdoc/src/main/scala/mdoc/internal/cli/MainOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ final class MainOps(
try {
if (!settings.isIncluded(file.relpath)) Exit.success
else {
PathIO.extension(file.in.toNIO) match {
case "md" => handleMarkdown(file)
case _ => handleRegularFile(file)
val extension = PathIO.extension(file.in.toNIO)
if (settings.isMarkdownFileExtension(extension)) {
handleMarkdown(file)
} else {
handleRegularFile(file)
}
}
} catch {
Expand Down
4 changes: 4 additions & 0 deletions mdoc/src/main/scala/mdoc/internal/cli/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ case class Settings(
usage: Boolean = false,
@Description("Print out the version number and exit")
version: Boolean = false,
@Description("Set of file extensions to treat as markdown files.")
markdownExtensions: List[String] = List("md", "html"),
@Description(
"Glob to filter which files to process. Defaults to all files. " +
"Example: --include **/example.md will process only files with the name example.md."
Expand Down Expand Up @@ -135,6 +137,8 @@ case class Settings(
variablePrinter: Variable => String = ReplVariablePrinter
) {

val isMarkdownFileExtension = markdownExtensions.toSet

def withProperties(props: MdocProperties): Settings =
copy(
scalacOptions = props.scalacOptions,
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/src/test/scala/tests/cli/CliSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,27 @@ class CliSuite extends BaseCliSuite {
}
)

checkCli(
"html",
"""
|/index.html
|<h1>My Fantastic Talk!</h1>
|<p>
|```scala mdoc
|println(42)
|```
|</p>
|""".stripMargin,
"""
|/index.html
|<h1>My Fantastic Talk!</h1>
|<p>
|```scala
|println(42)
|// 42
|```
|</p>
|""".stripMargin
)

}

0 comments on commit d3d4c8e

Please sign in to comment.