1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-03-19 21:10:15 +02:00

Correct HTML output + add R/S.

Fixes #1, #2, #3.
This commit is contained in:
Alec Thomas 2017-09-19 10:29:24 +10:00
parent d4a6811691
commit fbc889aad6
4 changed files with 116 additions and 59 deletions

View File

@ -27,22 +27,7 @@ translaters for Pygments lexers and styles.
## Supported languages
ABNF, ActionScript, ActionScript 3, Ada, Angular2, ANTLR, ApacheConf, APL,
AppleScript, Awk, Bash, Batchfile, BlitzBasic, BNF, Brainfuck, C, Cap'n
Proto, Ceylon, CFEngine3, ChaiScript, Python, Cheetah, Common Lisp, Clojure,
COBOL, CoffeeScript, cfstatement, Coq, C++, Crystal, CSS, Cython, Dart, Diff,
Django/Jinja, Docker, DTD, EBNF, Elixir, Elm, EmacsLisp, Erlang, Factor, Fish,
Forth, Fortran, FSharp, GAS, Genshi Text, GLSL, Gnuplot, Go, Groovy,
Handlebars, Haskell, Haxe, JavaScript, HTML, Hy, Idris, INI, Io, Java, JSON,
Julia, Kotlin, Lighttpd configuration file, LLVM, Lua, Base Makefile, Mako,
markdown, Perl, Mason, Mathematica, Modula-2, Myghty, MySQL, NASM, Newspeak,
Nginx configuration file, Nimrod, OCaml, Octave, PacmanConf, PHP, Pig,
PkgConfig, PL/pgSQL, PostgreSQL SQL dialect, PostScript, POVRay, PowerShell,
Prolog, Protocol Buffer, Puppet, Python 3, QBasic, Racket, Ragel, reg, Rexx,
Ruby, Rust, Sass, Scala, Scheme, Scilab, Smalltalk, Smarty, Snobol, SPARQL,
SQL, SquidConf, Swift, TASM, Tcl, Tcsh, Termcap, Terminfo, Terraform, Thrift,
Transact-SQL, Turtle, Twig, TypeScript, TypoScript, verilog, vhdl, VimL, XML,
Xorg
ABNF, ActionScript, ActionScript, Ada, Angular2, ANTLR, ApacheConf, APL, AppleScript, Awk, Bash, Batchfile, BlitzBasic, BNF, Brainfuck, C, Cap'n, Ceylon, CFEngine3, ChaiScript, Python, Cheetah, Common, Clojure, CMake, COBOL, CoffeeScript, cfstatement, Coq, C++, Crystal, CSS, Cython, Dart, Diff, Django/Jinja, Docker, DTD, EBNF, Elixir, Elm, EmacsLisp, Erlang, Factor, Fish, Forth, Fortran, FSharp, GAS, Genshi, GLSL, Gnuplot, Go, Groovy, Handlebars, Haskell, Haxe, JavaScript, HTML, Hy, Idris, INI, Io, Java, JSON, Julia, Kotlin, Lighttpd, LLVM, Lua, Base, Mako, markdown, Perl, Mason, Mathematica, Modula-2, Myghty, MySQL, NASM, Newspeak, Nginx, Nimrod, OCaml, Octave, PacmanConf, PHP, Pig, PkgConfig, PL/pgSQL, PostgreSQL, PostScript, POVRay, PowerShell, Prolog, Protocol, Puppet, Python, QBasic, S, Racket, Ragel, reg, Rexx, Ruby, Rust, Sass, Scala, Scheme, Scilab, Smalltalk, Smarty, Snobol, SPARQL, SQL, SquidConf, Swift, TASM, Tcl, Tcsh, Termcap, Terminfo, Terraform, Thrift, Transact-SQL, Turtle, Twig, TypeScript, TypoScriptHtmlData, TypoScriptCssData, TypoScript, verilog, vhdl, VimL, XML, Xorg
_I will attempt to keep this section up to date, but an authoritative list can be
displayed with `chroma --list`._

View File

@ -76,17 +76,19 @@ command, for Go.
if *htmlPrefixFlag != "" {
options = append(options, html.ClassPrefix(*htmlPrefixFlag))
}
if !*htmlOnlyFlag {
options = append(options, html.Standalone())
}
if !*htmlInlineStyleFlag {
options = append(options, html.WithClasses())
}
// Dump styles.
if *htmlStylesFlag {
formatter := html.New(html.WithClasses())
formatter.WriteCSS(w, styles.Get(*styleFlag))
return
}
if !*htmlInlineStyleFlag {
options = append(options, html.WithClasses())
}
if !*htmlOnlyFlag {
options = append(options, html.Standalone())
}
formatters.Register("html", html.New(options...))
}
writer := getWriter(w)

View File

@ -62,20 +62,21 @@ func (h *HTMLFormatter) formatWithoutClasses(w io.Writer, style *chroma.Style) (
fmt.Fprint(w, "</body>\n")
fmt.Fprint(w, "</html>\n")
}
return
}
html := html.EscapeString(token.String())
style := classes[token.Type]
if style == "" {
style = classes[token.Type.SubCategory()]
if style == "" {
style = classes[token.Type.Category()]
}
}
if style == "" {
fmt.Fprint(w, html)
} else {
html := html.EscapeString(token.String())
style := classes[token.Type]
if style == "" {
style = classes[token.Type.SubCategory()]
if style == "" {
style = classes[token.Type.Category()]
}
}
if style == "" {
fmt.Fprint(w, html)
} else {
fmt.Fprintf(w, "<span style=\"%s\">%s</span>", style, html)
}
fmt.Fprintf(w, "<span style=\"%s\">%s</span>", style, html)
}
}, nil
}
@ -100,39 +101,39 @@ func (h *HTMLFormatter) formatWithClasses(w io.Writer, style *chroma.Style) (fun
classes := h.typeStyles(style)
if h.standalone {
fmt.Fprint(w, "<html>\n")
}
fmt.Fprint(w, "<style type=\"text/css\">\n")
h.WriteCSS(w, style)
if h.standalone {
fmt.Fprint(w, "<style type=\"text/css\">\n")
h.WriteCSS(w, style)
fmt.Fprintf(w, "body { %s; }\n", classes[chroma.Background])
}
fmt.Fprint(w, "</style>\n")
if h.standalone {
fmt.Fprint(w, "</style>\n")
fmt.Fprint(w, "<body>\n")
}
fmt.Fprint(w, "<pre class=\"chroma\">\n")
return func(token *chroma.Token) {
if h.standalone && token.Type == chroma.EOF {
fmt.Fprint(w, "</body>\n")
fmt.Fprint(w, "</html>\n")
} else {
tt := token.Type
class := classes[tt]
if token.Type == chroma.EOF {
fmt.Fprint(w, "</pre>\n")
if h.standalone {
fmt.Fprint(w, "</body>\n")
fmt.Fprint(w, "</html>\n")
}
return
}
tt := token.Type
class := classes[tt]
if class == "" {
tt = tt.SubCategory()
class = classes[tt]
if class == "" {
tt = tt.SubCategory()
tt = tt.Category()
class = classes[tt]
if class == "" {
tt = tt.Category()
class = classes[tt]
}
}
if class == "" {
fmt.Fprint(w, token)
} else {
html := html.EscapeString(token.String())
fmt.Fprintf(w, "<span class=\"%ss%x\">%s</span>", h.prefix, int(tt), html)
}
}
if class == "" {
fmt.Fprint(w, token)
} else {
html := html.EscapeString(token.String())
fmt.Fprintf(w, "<span class=\"%ss%x\">%s</span>", h.prefix, int(tt), html)
}
}, nil
}

69
lexers/r.go Normal file

File diff suppressed because one or more lines are too long