diff --git a/BUILD.bazel b/BUILD.bazel index 3daed91..ee56454 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -2,6 +2,7 @@ load(":toolchain.bzl", "pandoc_toolchain") load(":pandoc.bzl", "PANDOC_EXTENSIONS", "pandoc") exports_files(["README.md"]) +exports_files(["stylesheet.css"]) # Precompiled Pandoc binaries provided by upstream. diff --git a/pandoc.bzl b/pandoc.bzl index d36a2a1..f76bac7 100644 --- a/pandoc.bzl +++ b/pandoc.bzl @@ -57,6 +57,8 @@ def _pandoc_impl(ctx): cli_args.extend(["--from", ctx.attr.from_format]) if ctx.attr.to_format: cli_args.extend(["--to", ctx.attr.to_format]) + if ctx.attr.css and PANDOC_EXTENSIONS[ctx.attr.to_format] == "html": + cli_args.extend(["-css", ctx.file.css.path]) cli_args.extend(["-o", ctx.outputs.output.path]) cli_args.extend([ctx.file.src.path]) ctx.actions.run( @@ -64,7 +66,7 @@ def _pandoc_impl(ctx): executable = toolchain.pandoc.files.to_list()[0].path, arguments = cli_args, inputs = depset( - direct = ctx.files.src, + direct = ctx.files.src + ctx.files.css, transitive = [toolchain.pandoc.files], ), outputs = [ctx.outputs.output], @@ -75,6 +77,7 @@ _pandoc = rule( "from_format": attr.string(), "options": attr.string_list(), "src": attr.label(allow_single_file = True, mandatory = True), + "css": attr.label(allow_single_file = True, mandatory = False), "to_format": attr.string(), "output": attr.output(mandatory = True), }, diff --git a/sample/BUILD.bazel b/sample/BUILD.bazel index 14af1a8..ff289e6 100644 --- a/sample/BUILD.bazel +++ b/sample/BUILD.bazel @@ -4,6 +4,7 @@ load("//:pandoc.bzl", "PANDOC_EXTENSIONS", "pandoc") [pandoc( name = "readme_" + fmt, src = "//:README.md", + css = "//:stylesheet.css", from_format = "markdown", to_format = fmt, ) for fmt in PANDOC_EXTENSIONS.keys()] diff --git a/stylesheet.css b/stylesheet.css new file mode 100644 index 0000000..13fa8b0 --- /dev/null +++ b/stylesheet.css @@ -0,0 +1,9 @@ +