123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899(*********************************************************************************)(* Stog *)(* *)(* Copyright (C) 2012-2015 INRIA All rights reserved. *)(* Author: Maxence Guesdon, INRIA Saclay *)(* *)(* This program is free software; you can redistribute it and/or modify *)(* it under the terms of the GNU General Public License as *)(* published by the Free Software Foundation, version 3 of the License. *)(* *)(* This program is distributed in the hope that it will be useful, *)(* but WITHOUT ANY WARRANTY; without even the implied warranty of *)(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *)(* GNU General Public License for more details. *)(* *)(* You should have received a copy of the GNU General Public *)(* License along with this program; if not, write to the Free Software *)(* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA *)(* 02111-1307 USA *)(* *)(* As a special exception, you have permission to link this program *)(* with the OCaml compiler and distribute executables, as long as you *)(* follow the requirements of the GNU GPL in regard to all of the *)(* software in the executable aside from the OCaml compiler. *)(* *)(* Contact: Maxence.Guesdon@inria.fr *)(* *)(*********************************************************************************)(** *)moduleXR=Xtmpl.Rewriteletexternal_highlight~optscode=letcode_file=Filename.temp_file"stog""code"inStog_base.Misc.file_of_string~file:code_filecode;lettemp_file=Filename.temp_file"stog""highlight"inletcom=Printf.sprintf"highlight -O xhtml %s -f %s > %s"opts(Filename.quotecode_file)(Filename.quotetemp_file)inmatchSys.commandcomwith0->letcode=Stog_base.Misc.string_of_filetemp_fileinSys.removecode_file;Sys.removetemp_file;letcode=Stog_base.Misc.strip_stringcodeinXR.from_stringcode|_->failwith(Printf.sprintf"command failed: %s"com);;lethiglo_classes=letkeyword=function0->"hl kwa"|1->"hl kwb"|2->"hl kwc"|3->"hl kwd"|n->"hl kw"^(string_of_intn)inletsymbol_="sym"in{Higlo.Printers.id="";keyword;lcomment="hl slc";bcomment="hl com";string="hl str";text="hl std";numeric="hl num";directive="hl dir";escape="hl esc";symbol;constant="hl num";};;lethighlight?lang?optscode=matchlang,optswithNone,Someopts|Some"",Someopts->external_highlight~optscode|None,None|Some"",None->[XR.cdatacode]|Somelang,Someopts->letopts=opts^" --syntax="^langinexternal_highlight~optscode|Some"txt",None->[Higlo.Printers.token_to_xml_rewrite~classes:higlo_classes(Higlo.Lang.Textcode)]|Somelang,None->trylet_lexer=Higlo.Lang.get_lexerlanginHiglo.Printers.to_xml_rewrite~classes:higlo_classes~langcodewithHiglo.Lang.(Error(Unknown_langs))->Log.warn(funm->m"Higlo: unknown language %s. Falling back to external highlight"lang);letopts=" --syntax="^langinexternal_highlight~optscode;;