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

81 Commits

Author SHA1 Message Date
Alvaro Aleman
ab61726cdb Make linkeable lines a link to themselves
Currently its already possible to make line lumbers linkeable. Getting
such a link however requires the end user to look at the pages source
and then to manually edit the URL, which is not a great UX.

This PR changes that to make the line numbers a link to themselves, so
clicking on them gives a link to that line that can then be passed
around, similiar to e.G. GitHub.
2020-11-03 21:31:04 +11:00
Cameron Little
809ff9ba45 Don't emit styles that are missing a class 2020-05-09 22:56:49 +10:00
Cameron Little
cc5e532d14 Add failing test for invalid css with allClasses
This was reported at https://github.com/gohugoio/hugo/issues/7207
2020-05-09 22:56:49 +10:00
Alec Thomas
cc53faa932 Add option to preserve all HTML classes.
Fixes .
2020-04-13 07:36:37 +10:00
Pablo Santiago Blum de Aguiar
9e22bd6e2f Consider baseLineNumber when calculating the column width 2020-01-10 08:23:54 +11:00
Alexandru Băluț
19d5ee688c Highlight the line number targeted by the URL anchor
This currently works only when `html.WithClasses(true)` is used.
The same colors as for the pre-highlighted lines are used.
Only the line number is highlighted, so difficult to notice, but
better than nothing.
2019-12-31 11:10:38 +11:00
Alexandru Băluț
a41c89767d Add the option of making the line numbers linkable 2019-12-12 17:31:43 -08:00
Bjørn Erik Pedersen
5921c52787 Add bool argument to WithClasses, WithLineNumbers etc.
This allows the boolean options to be reconfigured, e.g:

```go
options := getOptions()
options = append(options, html.WithLineNumbers(true))
```

Fixes 
2019-11-22 10:13:00 +11:00
Bjørn Erik Pedersen
d3926cc0e1 Add WithPreWrapper option 2019-11-20 20:09:17 +11:00
Alec Thomas
bbc59ac372 Emit error tokens when there's a group mismatch.
Also don't panic/recover, as we no longer use panic to report "real"
errors.

Fixes .
2019-10-24 17:03:35 +11:00
rsteube
aaa94ce97c svg: fixed text background rectangles
- location and size looks fine now even when scaled and with larger files (used `em` for line height and `ch` for
width)
- svg width/height looks ok now, width has some problems on scaling (seems this needs to be a unit like `px` and cannot be `ch` so it's a rough estimate)
- updated liberation mono font to 2.00.5 since the current one had wrong width for the full block character (https://github.com/liberationfonts/liberation-fonts)
2019-10-16 21:09:59 +11:00
rsteube
611a24ccdd embedded font in svg () 2019-10-15 23:38:42 +11:00
Alec Thomas
73d11b3c45 Clear background colour for TTY formatters. 2019-10-15 21:08:17 +11:00
Alec Thomas
b44683eae8 Fix linter. 2019-10-06 20:14:05 +11:00
rsteube
22511fb8e4 added svg formatter
basic version without any options. colors and font-styles seem to be ok.
rough support for text background in styles like `murphy` using predrawn
rectangles (svg has no text background attribute).

things to improve:
- svg width attribute (`<svg width=""`)
- linenumbers
- highlighting
- embedded font
- tabwidth option
- margins?
- better position/width calculation (rectangles not correctly drawn on
resize)
2019-09-30 09:43:27 +10:00
Ray Lee
2f5349aa18 Add italics support for indexed colour terminals 2019-09-02 08:12:43 +10:00
Ray Lee
f2e05136f7 Add italics support for truecolour terminals 2019-09-02 08:12:43 +10:00
Alec Thomas
e6a56651ad Add width:100% to content <td> when inlining styles.
Fixes .
2019-07-20 23:19:20 +10:00
Alec Thomas
da5ac60d8c Add golangci-lint and fix all lint issues. 2018-12-31 22:46:59 +11:00
Alec Thomas
2a59c2c77e Synthesise meta style-entries on demand.
This includes line highlighting, numbers, etc.

Fixes .
2018-12-31 11:33:36 +11:00
Alec Thomas
69c9a262c3 Expose Colour.BrightenOrDarken (useful for ). 2018-12-31 10:48:45 +11:00
Alec Thomas
881a441774 Don't keep trailing empty tokens when splitting tokens by line.
Fixes . Fixes .
2018-12-27 16:20:38 +11:00
Alec Thomas
fb4c38e204 Fix build (see ). 2018-11-08 17:16:58 +11:00
Randall C. O'Reilly
a4f179974b move SplitTokensIntoLines into chroma/iterator.go, fixes issue 2018-11-08 16:21:45 +11:00
Daniel Eloff
9c3abeae1d Tokens by value ()
This results in about a 8% improvement in speed.
2018-11-04 10:22:51 +11:00
Felix Knischewski
e36baa268a Add option to prevent surroundign pre tags 2018-09-18 19:44:44 +10:00
Kaushal Modi
371820dad6 Assign .gl class to GenericUnderline; add CSS rules for the same
'l' in gl is for under(l)ine, as the "gu" class is taken by
GenericSubheading.

- Rules for GenericUnderline are added to all the styles
- Make "Underline" style insert "text-decoration: underline" in CSS.

Fixes https://github.com/alecthomas/chroma/issues/159.
2018-08-01 17:28:52 -04:00
Alec Thomas
0961f82bc3 Fix nearest colour matching.
This was caused by precision loss due to using uint8. The cast to int64
was occurring in the wrong location.

Fixes .
2018-06-25 20:48:31 +10:00
Alec Thomas
3020e2ea8c Fix bug with nested newlines.
Fixes .

Also reinstitute lexer tests that disappeared during package split.
2018-03-03 10:16:21 +11:00
John Millikin
aaa96c6984 Avoid adding an HTML prefix to empty class names.
This makes the raw markup a bit cleaner when there's lots of `Text`
tokens.
2018-02-25 19:46:48 +11:00
John Millikin
d7ee3c10b0 Add newlines in line number spans when wrapping in an HTML table.
Since these are wrapped in a `<pre>`, newlines hint the browser that the
line numbers should be on separate lines. This helps when rendering
content with broken CSS, or in a text-only browser.
2018-02-25 17:52:15 +11:00
John Millikin
df4ec264da Render HTML class prefixes. 2018-02-18 14:58:46 +11:00
Alec Thomas
563aadc53c Moved lexers into alphabetical sub-packages.
This was done to speed up incremental compilation when working on
lexers. That is, modifying a single lexer will no longer require
recompiling all lexers.

This is a (slightly) backwards breaking change in that lexers are no
longer exported directly in the lexers package. The registry API is
"aliased" at the old location.
2018-02-15 21:09:02 +11:00
Alec Thomas
e4cd1649a3 Ensure that HTML code column expands to full width of container.
Fixes .
2018-02-11 21:14:56 +11:00
MunifTanjim
03fd03809c fix func compressStyle(s string) for CSS Shorthand properties 2018-02-11 19:10:59 +11:00
Alec Thomas
71ddf5511a Fix README for test fixtures. 2018-01-02 20:59:02 +11:00
Alec Thomas
e56590a815 Add data-driven test framework for lexers.
See .
2018-01-02 14:53:25 +11:00
Denis Brodbeck
c9f612c194 Fix broken css rules output
Strip leading semicolons in combination with line numbers.

fixes 
2017-12-11 21:20:14 -08:00
hexasoftware
03b0c0d6bb Changed terminal16m to semicolons ()
Most terminals seems to use semicolons in true colors:
https://gist.github.com/XVilka/8346728
2017-10-17 15:04:12 +11:00
Bjørn Erik Pedersen
02c4adc066 Add a chroma class wrapper when in "table mode" ()
This commits adds a div wrapper when linenumbers are formatted in table, to get the correct CSS matchers.

This commit also fixes some CSS table issues when tables are put into a larger context with other stylesheets:

* No borders.
* Overflow to fit in potentially narrower containers.

Fixes 
2017-10-14 20:02:40 +11:00
Depado
4a55aefee6 Adding HasClasses method for HTML formatter ()
* Adding HasClasses method for HTML formatter

* Removing helper function and simply export the field
2017-10-14 08:41:40 +11:00
Bjørn Erik Pedersen
27733ac753 Add table styled line numbers ()
Fixes 
2017-10-13 10:49:20 +11:00
Alec Thomas
0e0960930d Don't output trailing \n for HTML-only fragment.
See .
2017-09-30 14:45:37 +10:00
Alec Thomas
573c1d157d Ensure a newline exists at the end of files.
Fixes .
2017-09-29 21:59:52 +10:00
Alec Thomas
33f604c892 Always use CSS class from StandardTypes.
As opposed to remapping to classes that exist in the current style.
2017-09-27 22:05:47 +10:00
Alec Thomas
80d3b96869 Ensure class names from default set exist. 2017-09-27 22:01:03 +10:00
Alec Thomas
bc2d6680e4 Run gofmt -s over the codebase. 2017-09-26 22:05:55 +10:00
Alec Thomas
bdc1124369 Switch to Pygments-style CSS class names.
Add GitHub theme + CSS to style importer.
2017-09-25 21:46:25 +10:00
Alec Thomas
b0295f66bd Remove spurious newline in HTML output.
Fixes .
2017-09-25 15:25:32 +10:00
Alec Thomas
c984ca45c7 Add html.BaseLineNumber(n).
Fixes .
2017-09-24 20:33:50 +10:00