|
|
|
@ -7,6 +7,7 @@
@@ -7,6 +7,7 @@
|
|
|
|
|
#include <unordered_map> |
|
|
|
|
#include <optional> |
|
|
|
|
|
|
|
|
|
#include <syntect-c.h> |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* |
|
|
|
@ -18,181 +19,181 @@
@@ -18,181 +19,181 @@
|
|
|
|
|
class gnu_highlighter { |
|
|
|
|
|
|
|
|
|
const std::unordered_map<std::string, std::string> supported_languages { |
|
|
|
|
{"cpp", "cpp.lang"}, |
|
|
|
|
{"C", "cpp.lang"}, |
|
|
|
|
{"c", "cpp.lang"}, |
|
|
|
|
{"F77", "fortran.lang"}, |
|
|
|
|
{"f77", "fortran.lang"}, |
|
|
|
|
{"F90", "fortran.lang"}, |
|
|
|
|
{"f90", "fortran.lang"}, |
|
|
|
|
{"H", "cpp.lang"}, |
|
|
|
|
{"h", "cpp.lang"}, |
|
|
|
|
{"ac", "m4.lang"}, |
|
|
|
|
{"ada", "ada.lang"}, |
|
|
|
|
{"adb", "ada.lang"}, |
|
|
|
|
{"am", "makefile.lang"}, |
|
|
|
|
{"applescript", "applescript.lang"}, |
|
|
|
|
{"asm", "asm.lang"}, |
|
|
|
|
{"autoconf", "m4.lang"}, |
|
|
|
|
{"awk", "awk.lang"}, |
|
|
|
|
{"bash", "sh.lang"}, |
|
|
|
|
{"bat", "bat.lang"}, |
|
|
|
|
{"batch", "bat.lang"}, |
|
|
|
|
{"bib", "bib.lang"}, |
|
|
|
|
{"bison", "bison.lang"}, |
|
|
|
|
{"c", "c.lang"}, |
|
|
|
|
{"caml", "caml.lang"}, |
|
|
|
|
{"cbl", "cobol.lang"}, |
|
|
|
|
{"cc", "cpp.lang"}, |
|
|
|
|
{"changelog", "changelog.lang"}, |
|
|
|
|
{"clipper", "clipper.lang"}, |
|
|
|
|
{"cls", "latex.lang"}, |
|
|
|
|
{"cobol", "cobol.lang"}, |
|
|
|
|
{"coffee", "coffeescript.lang"}, |
|
|
|
|
{"coffeescript", "coffeescript.lang"}, |
|
|
|
|
{"conf", "conf.lang"}, |
|
|
|
|
{"cpp", "cpp.lang"}, |
|
|
|
|
{"cs", "csharp.lang"}, |
|
|
|
|
{"csh", "sh.lang"}, |
|
|
|
|
{"csharp", "csharp.lang"}, |
|
|
|
|
{"css", "css.lang"}, |
|
|
|
|
{"ctp", "php.lang"}, |
|
|
|
|
{"cxx", "cpp.lang"}, |
|
|
|
|
{"d", "d.lang"}, |
|
|
|
|
{"desktop", "desktop.lang"}, |
|
|
|
|
{"diff", "diff.lang"}, |
|
|
|
|
{"dmd", "d.lang"}, |
|
|
|
|
{"docbook", "xml.lang"}, |
|
|
|
|
{"dtx", "latex.lang"}, |
|
|
|
|
{"el", "lisp.lang"}, |
|
|
|
|
{"eps", "postscript.lang"}, |
|
|
|
|
{"erl", "erlang.lang"}, |
|
|
|
|
{"erlang", "erlang.lang"}, |
|
|
|
|
{"errors", "errors.lang"}, |
|
|
|
|
{"f", "fortran.lang"}, |
|
|
|
|
{"f77", "fortran.lang"}, |
|
|
|
|
{"f90", "fortran.lang"}, |
|
|
|
|
{"feature", "feature.lang"}, |
|
|
|
|
{"fixed-fortran", "fixed-fortran.lang"}, |
|
|
|
|
{"flex", "flex.lang"}, |
|
|
|
|
{"fortran", "fortran.lang"}, |
|
|
|
|
{"free-fortran", "fortran.lang"}, |
|
|
|
|
{"glsl", "glsl.lang"}, |
|
|
|
|
{"go", "go.lang"}, |
|
|
|
|
{"groovy", "groovy.lang"}, |
|
|
|
|
{"h", "cpp.lang"}, |
|
|
|
|
{"haskell", "haskell.lang"}, |
|
|
|
|
{"haxe", "haxe.lang"}, |
|
|
|
|
{"hh", "cpp.lang"}, |
|
|
|
|
{"hpp", "cpp.lang"}, |
|
|
|
|
{"hs", "haskell.lang"}, |
|
|
|
|
{"htm", "html.lang"}, |
|
|
|
|
{"html", "html.lang"}, |
|
|
|
|
{"hx", "haxe.lang"}, |
|
|
|
|
{"hxx", "cpp.lang"}, |
|
|
|
|
{"in", "makefile.lang"}, |
|
|
|
|
{"ini", "desktop.lang"}, |
|
|
|
|
{"islisp", "islisp.lang"}, |
|
|
|
|
{"java", "java.lang"}, |
|
|
|
|
{"javalog", "javalog.lang"}, |
|
|
|
|
{"javascript", "javascript.lang"}, |
|
|
|
|
{"js", "javascript.lang"}, |
|
|
|
|
{"json", "json.lang"}, |
|
|
|
|
{"kcfg", "xml.lang"}, |
|
|
|
|
{"kdevelop", "xml.lang"}, |
|
|
|
|
{"kidl", "xml.lang"}, |
|
|
|
|
{"ksh", "sh.lang"}, |
|
|
|
|
{"l", "flex.lang"}, |
|
|
|
|
{"lang", "langdef.lang"}, |
|
|
|
|
{"langdef", "langdef.lang"}, |
|
|
|
|
{"latex", "latex.lang"}, |
|
|
|
|
{"ldap", "ldap.lang"}, |
|
|
|
|
{"ldif", "ldap.lang"}, |
|
|
|
|
{"lex", "flex.lang"}, |
|
|
|
|
{"lgt", "logtalk.lang"}, |
|
|
|
|
{"lhs", "haskell_literate.lang"}, |
|
|
|
|
{"lilypond", "lilypond.lang"}, |
|
|
|
|
{"lisp", "lisp.lang"}, |
|
|
|
|
{"ll", "flex.lang"}, |
|
|
|
|
{"log", "log.lang"}, |
|
|
|
|
{"logtalk", "logtalk.lang"}, |
|
|
|
|
{"lsm", "lsm.lang"}, |
|
|
|
|
{"lua", "lua.lang"}, |
|
|
|
|
{"ly", "lilypond.lang"}, |
|
|
|
|
{"m4", "m4.lang"}, |
|
|
|
|
{"makefile", "makefile.lang"}, |
|
|
|
|
{"manifest", "manifest.lang"}, |
|
|
|
|
{"mf", "manifest.lang"}, |
|
|
|
|
{"ml", "caml.lang"}, |
|
|
|
|
{"mli", "caml.lang"}, |
|
|
|
|
{"moc", "cpp.lang"}, |
|
|
|
|
{"opa", "opa.lang"}, |
|
|
|
|
{"outlang", "outlang.lang"}, |
|
|
|
|
{"oz", "oz.lang"}, |
|
|
|
|
{"pas", "pascal.lang"}, |
|
|
|
|
{"pascal", "pascal.lang"}, |
|
|
|
|
{"patch", "diff.lang"}, |
|
|
|
|
{"pc", "pc.lang"}, |
|
|
|
|
{"perl", "perl.lang"}, |
|
|
|
|
{"php", "php.lang"}, |
|
|
|
|
{"php3", "php.lang"}, |
|
|
|
|
{"php4", "php.lang"}, |
|
|
|
|
{"php5", "php.lang"}, |
|
|
|
|
{"pkgconfig", "pc.lang"}, |
|
|
|
|
{"pl", "prolog.lang"}, |
|
|
|
|
{"pm", "perl.lang"}, |
|
|
|
|
{"po", "po.lang"}, |
|
|
|
|
{"postscript", "postscript.lang"}, |
|
|
|
|
{"pot", "po.lang"}, |
|
|
|
|
{"prg", "clipper.lang"}, |
|
|
|
|
{"prolog", "prolog.lang"}, |
|
|
|
|
{"properties", "properties.lang"}, |
|
|
|
|
{"proto", "proto.lang"}, |
|
|
|
|
{"protobuf", "proto.lang"}, |
|
|
|
|
{"ps", "postscript.lang"}, |
|
|
|
|
{"py", "python.lang"}, |
|
|
|
|
{"python", "python.lang"}, |
|
|
|
|
{"r", "r.lang"}, |
|
|
|
|
{"rb", "ruby.lang"}, |
|
|
|
|
{"rc", "xml.lang"}, |
|
|
|
|
{"ruby", "ruby.lang"}, |
|
|
|
|
{"s", "s.lang"}, |
|
|
|
|
{"scala", "scala.lang"}, |
|
|
|
|
{"scheme", "scheme.lang"}, |
|
|
|
|
{"scm", "scheme.lang"}, |
|
|
|
|
{"scpt", "applescript.lang"}, |
|
|
|
|
{"sh", "sh.lang"}, |
|
|
|
|
{"shell", "sh.lang"}, |
|
|
|
|
{"sig", "sml.lang"}, |
|
|
|
|
{"sl", "slang.lang"}, |
|
|
|
|
{"slang", "slang.lang"}, |
|
|
|
|
{"slsh", "slang.lang"}, |
|
|
|
|
{"sml", "sml.lang"}, |
|
|
|
|
{"spec", "spec.lang"}, |
|
|
|
|
{"sql", "sql.lang"}, |
|
|
|
|
{"sty", "latex.lang"}, |
|
|
|
|
{"style", "style.lang"}, |
|
|
|
|
{"syslog", "log.lang"}, |
|
|
|
|
{"tcl", "tcl.lang"}, |
|
|
|
|
{"tcsh", "sh.lang"}, |
|
|
|
|
{"tex", "latex.lang"}, |
|
|
|
|
{"texi", "texinfo.lang"}, |
|
|
|
|
{"texinfo", "texinfo.lang"}, |
|
|
|
|
{"tk", "tcl.lang"}, |
|
|
|
|
{"tml", "tml.lang"}, |
|
|
|
|
{"txt", "nohilite.lang"}, |
|
|
|
|
{"ui", "xml.lang"}, |
|
|
|
|
{"upc", "upc.lang"}, |
|
|
|
|
{"vala", "vala.lang"}, |
|
|
|
|
{"vbs", "vbscript.lang"}, |
|
|
|
|
{"vbscript", "vbscript.lang"}, |
|
|
|
|
{"xhtml", "xml.lang"}, |
|
|
|
|
{"xml", "xml.lang"}, |
|
|
|
|
{"xorg", "xorg.lang"}, |
|
|
|
|
{"y", "bison.lang"}, |
|
|
|
|
{"yacc", "bison.lang"}, |
|
|
|
|
{"yy", "bison.lang"}, |
|
|
|
|
{"zsh", "zsh.lang"}, |
|
|
|
|
{"cpp", "cpp"}, |
|
|
|
|
{"C", "cpp"}, |
|
|
|
|
{"c", "cpp"}, |
|
|
|
|
{"F77", "fortran"}, |
|
|
|
|
{"f77", "fortran"}, |
|
|
|
|
{"F90", "fortran"}, |
|
|
|
|
{"f90", "fortran"}, |
|
|
|
|
{"H", "cpp"}, |
|
|
|
|
{"h", "cpp"}, |
|
|
|
|
{"ac", "m4"}, |
|
|
|
|
{"ada", "ada"}, |
|
|
|
|
{"adb", "ada"}, |
|
|
|
|
{"am", "makefile"}, |
|
|
|
|
{"applescript", "applescript"}, |
|
|
|
|
{"asm", "asm"}, |
|
|
|
|
{"autoconf", "m4"}, |
|
|
|
|
{"awk", "awk"}, |
|
|
|
|
{"bash", "sh"}, |
|
|
|
|
{"bat", "bat"}, |
|
|
|
|
{"batch", "bat"}, |
|
|
|
|
{"bib", "bib"}, |
|
|
|
|
{"bison", "bison"}, |
|
|
|
|
{"c", "c"}, |
|
|
|
|
{"caml", "caml"}, |
|
|
|
|
{"cbl", "cobol"}, |
|
|
|
|
{"cc", "cpp"}, |
|
|
|
|
{"changelog", "changelog"}, |
|
|
|
|
{"clipper", "clipper"}, |
|
|
|
|
{"cls", "latex"}, |
|
|
|
|
{"cobol", "cobol"}, |
|
|
|
|
{"coffee", "coffeescript"}, |
|
|
|
|
{"coffeescript", "coffeescript"}, |
|
|
|
|
{"conf", "conf"}, |
|
|
|
|
{"cpp", "cpp"}, |
|
|
|
|
{"cs", "csharp"}, |
|
|
|
|
{"csh", "sh"}, |
|
|
|
|
{"csharp", "csharp"}, |
|
|
|
|
{"css", "css"}, |
|
|
|
|
{"ctp", "php"}, |
|
|
|
|
{"cxx", "cpp"}, |
|
|
|
|
{"d", "d"}, |
|
|
|
|
{"desktop", "desktop"}, |
|
|
|
|
{"diff", "diff"}, |
|
|
|
|
{"dmd", "d"}, |
|
|
|
|
{"docbook", "xml"}, |
|
|
|
|
{"dtx", "latex"}, |
|
|
|
|
{"el", "lisp"}, |
|
|
|
|
{"eps", "postscript"}, |
|
|
|
|
{"erl", "erlang"}, |
|
|
|
|
{"erlang", "erlang"}, |
|
|
|
|
{"errors", "errors"}, |
|
|
|
|
{"f", "fortran"}, |
|
|
|
|
{"f77", "fortran"}, |
|
|
|
|
{"f90", "fortran"}, |
|
|
|
|
{"feature", "feature"}, |
|
|
|
|
{"fixed-fortran", "fixed-fortran"}, |
|
|
|
|
{"flex", "flex"}, |
|
|
|
|
{"fortran", "fortran"}, |
|
|
|
|
{"free-fortran", "fortran"}, |
|
|
|
|
{"glsl", "glsl"}, |
|
|
|
|
{"go", "go"}, |
|
|
|
|
{"groovy", "groovy"}, |
|
|
|
|
{"h", "cpp"}, |
|
|
|
|
{"haskell", "haskell"}, |
|
|
|
|
{"haxe", "haxe"}, |
|
|
|
|
{"hh", "cpp"}, |
|
|
|
|
{"hpp", "cpp"}, |
|
|
|
|
{"hs", "haskell"}, |
|
|
|
|
{"htm", "html"}, |
|
|
|
|
{"html", "html"}, |
|
|
|
|
{"hx", "haxe"}, |
|
|
|
|
{"hxx", "cpp"}, |
|
|
|
|
{"in", "makefile"}, |
|
|
|
|
{"ini", "desktop"}, |
|
|
|
|
{"islisp", "islisp"}, |
|
|
|
|
{"java", "java"}, |
|
|
|
|
{"javalog", "javalog"}, |
|
|
|
|
{"javascript", "javascript"}, |
|
|
|
|
{"js", "javascript"}, |
|
|
|
|
{"json", "json"}, |
|
|
|
|
{"kcfg", "xml"}, |
|
|
|
|
{"kdevelop", "xml"}, |
|
|
|
|
{"kidl", "xml"}, |
|
|
|
|
{"ksh", "sh"}, |
|
|
|
|
{"l", "flex"}, |
|
|
|
|
{"lang", "langdef"}, |
|
|
|
|
{"langdef", "langdef"}, |
|
|
|
|
{"latex", "latex"}, |
|
|
|
|
{"ldap", "ldap"}, |
|
|
|
|
{"ldif", "ldap"}, |
|
|
|
|
{"lex", "flex"}, |
|
|
|
|
{"lgt", "logtalk"}, |
|
|
|
|
{"lhs", "haskell_literate"}, |
|
|
|
|
{"lilypond", "lilypond"}, |
|
|
|
|
{"lisp", "lisp"}, |
|
|
|
|
{"ll", "flex"}, |
|
|
|
|
{"log", "log"}, |
|
|
|
|
{"logtalk", "logtalk"}, |
|
|
|
|
{"lsm", "lsm"}, |
|
|
|
|
{"lua", "lua"}, |
|
|
|
|
{"ly", "lilypond"}, |
|
|
|
|
{"m4", "m4"}, |
|
|
|
|
{"makefile", "makefile"}, |
|
|
|
|
{"manifest", "manifest"}, |
|
|
|
|
{"mf", "manifest"}, |
|
|
|
|
{"ml", "caml"}, |
|
|
|
|
{"mli", "caml"}, |
|
|
|
|
{"moc", "cpp"}, |
|
|
|
|
{"opa", "opa"}, |
|
|
|
|
{"outlang", "outlang"}, |
|
|
|
|
{"oz", "oz"}, |
|
|
|
|
{"pas", "pascal"}, |
|
|
|
|
{"pascal", "pascal"}, |
|
|
|
|
{"patch", "diff"}, |
|
|
|
|
{"pc", "pc"}, |
|
|
|
|
{"perl", "perl"}, |
|
|
|
|
{"php", "php"}, |
|
|
|
|
{"php3", "php"}, |
|
|
|
|
{"php4", "php"}, |
|
|
|
|
{"php5", "php"}, |
|
|
|
|
{"pkgconfig", "pc"}, |
|
|
|
|
{"pl", "prolog"}, |
|
|
|
|
{"pm", "perl"}, |
|
|
|
|
{"po", "po"}, |
|
|
|
|
{"postscript", "postscript"}, |
|
|
|
|
{"pot", "po"}, |
|
|
|
|
{"prg", "clipper"}, |
|
|
|
|
{"prolog", "prolog"}, |
|
|
|
|
{"properties", "properties"}, |
|
|
|
|
{"proto", "proto"}, |
|
|
|
|
{"protobuf", "proto"}, |
|
|
|
|
{"ps", "postscript"}, |
|
|
|
|
{"py", "python"}, |
|
|
|
|
{"python", "python"}, |
|
|
|
|
{"r", "r"}, |
|
|
|
|
{"rb", "ruby"}, |
|
|
|
|
{"rc", "xml"}, |
|
|
|
|
{"ruby", "ruby"}, |
|
|
|
|
{"s", "s"}, |
|
|
|
|
{"scala", "scala"}, |
|
|
|
|
{"scheme", "scheme"}, |
|
|
|
|
{"scm", "scheme"}, |
|
|
|
|
{"scpt", "applescript"}, |
|
|
|
|
{"sh", "sh"}, |
|
|
|
|
{"shell", "sh"}, |
|
|
|
|
{"sig", "sml"}, |
|
|
|
|
{"sl", "slang"}, |
|
|
|
|
{"slang", "slang"}, |
|
|
|
|
{"slsh", "slang"}, |
|
|
|
|
{"sml", "sml"}, |
|
|
|
|
{"spec", "spec"}, |
|
|
|
|
{"sql", "sql"}, |
|
|
|
|
{"sty", "latex"}, |
|
|
|
|
{"style", "style"}, |
|
|
|
|
{"syslog", "log"}, |
|
|
|
|
{"tcl", "tcl"}, |
|
|
|
|
{"tcsh", "sh"}, |
|
|
|
|
{"tex", "latex"}, |
|
|
|
|
{"texi", "texinfo"}, |
|
|
|
|
{"texinfo", "texinfo"}, |
|
|
|
|
{"tk", "tcl"}, |
|
|
|
|
{"tml", "tml"}, |
|
|
|
|
{"txt", "nohilite"}, |
|
|
|
|
{"ui", "xml"}, |
|
|
|
|
{"upc", "upc"}, |
|
|
|
|
{"vala", "vala"}, |
|
|
|
|
{"vbs", "vbscript"}, |
|
|
|
|
{"vbscript", "vbscript"}, |
|
|
|
|
{"xhtml", "xml"}, |
|
|
|
|
{"xml", "xml"}, |
|
|
|
|
{"xorg", "xorg"}, |
|
|
|
|
{"y", "bison"}, |
|
|
|
|
{"yacc", "bison"}, |
|
|
|
|
{"yy", "bison"}, |
|
|
|
|
{"zsh", "zsh"}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
srchilite::SourceHighlight shl {"htmlcss.outlang"}; |
|
|
|
@ -211,13 +212,14 @@ class gnu_highlighter {
@@ -211,13 +212,14 @@ class gnu_highlighter {
|
|
|
|
|
std::string highlight(const std::string &program,
|
|
|
|
|
const std::string &lang) { |
|
|
|
|
|
|
|
|
|
std::stringstream pr {program}; |
|
|
|
|
char *highlighted = syntect_to_html(lang.c_str(), "base16-ocean.light", program.c_str()); |
|
|
|
|
return std::string(highlighted, highlighted + strlen(highlighted)); |
|
|
|
|
|
|
|
|
|
std::ostringstream oout {}; |
|
|
|
|
|
|
|
|
|
shl.highlight(pr, oout, lang); |
|
|
|
|
//return oout.str();
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return oout.str(); |
|
|
|
|
gnu_highlighter() { |
|
|
|
|
syntect_init(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|