diff options
author | Loïc Hoguin <[email protected]> | 2018-06-11 22:21:36 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2018-06-11 22:21:36 +0200 |
commit | dbb935a5972350f734d4abcf31c03f9e54bbd1d4 (patch) | |
tree | bbd4f56f9a5647c807187eb55f033255a29488df /src/asciideck_source_highlight.erl | |
parent | 976dfc5d92e3e23f356cb19f17ff51b22c75e634 (diff) | |
download | asciideck-dbb935a5972350f734d4abcf31c03f9e54bbd1d4.tar.gz asciideck-dbb935a5972350f734d4abcf31c03f9e54bbd1d4.tar.bz2 asciideck-dbb935a5972350f734d4abcf31c03f9e54bbd1d4.zip |
Add source-highlight support to HTML output
Diffstat (limited to 'src/asciideck_source_highlight.erl')
-rw-r--r-- | src/asciideck_source_highlight.erl | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/asciideck_source_highlight.erl b/src/asciideck_source_highlight.erl new file mode 100644 index 0000000..24c3054 --- /dev/null +++ b/src/asciideck_source_highlight.erl @@ -0,0 +1,27 @@ +%% Copyright (c) 2018, Loïc Hoguin <[email protected]> +%% +%% Permission to use, copy, modify, and/or distribute this software for any +%% purpose with or without fee is hereby granted, provided that the above +%% copyright notice and this permission notice appear in all copies. +%% +%% THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +%% WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +%% MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +%% ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +%% WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +%% ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +%% OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +%% https://www.gnu.org/software/src-highlite/source-highlight.html +-module(asciideck_source_highlight). + +-export([filter/2]). + +filter(Input, #{2 := Lang}) -> + TmpFile = "/tmp/asciideck-" ++ integer_to_list(erlang:phash2(make_ref())), + ok = file:write_file(TmpFile, Input), + Output = os:cmd(io_lib:format( + "source-highlight -i ~s -s ~s", + [TmpFile, Lang])), + file:delete(TmpFile), + unicode:characters_to_binary(Output). |