Browse Source

switch to syntect

master
alistair 3 years ago
parent
commit
95c0deebe4
  1. 4
      main.cpp
  2. 362
      srchighlight.hpp

4
main.cpp

@ -445,8 +445,10 @@ class builder {
const std::string dec_lang {clname, clname + len}; const std::string dec_lang {clname, clname + len};
auto language = shl.get_lang(dec_lang); auto language = shl.get_lang(dec_lang);
if (!language) if (!language) {
spdlog::warn("Unknown language: {}", dec_lang);
continue; // skip tags with unsupported language continue; // skip tags with unsupported language
}
std::string highlighted = shl.highlight(tt, *language); std::string highlighted = shl.highlight(tt, *language);

362
srchighlight.hpp

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

Loading…
Cancel
Save