Skip to content

Commit d798e0f

Browse files
authored
Merge pull request #10 from keplersj/jest
Transition to Jest, Increase Languages Tested, and Fix Bug with Sub-Languages
2 parents 2d6d026 + de2b227 commit d798e0f

File tree

193 files changed

+11368
-105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

193 files changed

+11368
-105
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ node_js:
66
env:
77
global:
88
- FORCE_COLOR=1
9+
- OUTPUT_CODE_SAMPLES=1
910

1011
cache:
1112
directories:
@@ -17,10 +18,9 @@ install:
1718
script:
1819
- npm run lint
1920
- npm run build
20-
- npm run cover
21+
- npm run test
2122

2223
after_success:
23-
- nyc report --reporter=json
2424
- bash <(curl -s https://codecov.io/bash)
2525

2626
jobs:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ The theme is combined with the [default theme](http://cli-highlight.surge.sh/glo
7676
The default theme is still not colored a lot or optimized for many languages, PRs welcome!
7777

7878
## Supported Languages
79-
In theory, [all languages of highlight.js](https://highlightjs.org/static/demo/) are supported - I just did not adapt
80-
the default theme and wrote tests for all languages yet. My primary use case was SQL so that is supported well.
79+
[All languages of highlight.js](https://highlightjs.org/static/demo/) are supported.
80+
Check a [CI build](https://travis-ci.org/felixfbecker/cli-highlight) for examples of all the different languages and their highlighting.
8181

8282
## Contributing
8383
The module is written in TypeScript and can be compiled with `npm run build`.

package.json

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
"node": ">=4.0.0"
1818
},
1919
"scripts": {
20-
"test": "mocha dist/test",
21-
"cover": "nyc --all mocha dist/test",
20+
"test": "jest",
2221
"lint": "npm run tslint && npm run prettier",
2322
"tslint": "tslint -c tslint.json -p tsconfig.json",
2423
"prettier": "prettier --write --list-different '**/{*.ts,*.json,.prettierrc}'",
@@ -28,13 +27,21 @@
2827
"semantic-release": "semantic-release",
2928
"commitmsg": "validate-commit-msg"
3029
},
31-
"nyc": {
32-
"include": [
33-
"dist/**/*.js"
34-
],
35-
"exclude": [
36-
"dist/test/**/*.js",
37-
"dist/cli.js"
30+
"jest": {
31+
"collectCoverage": true,
32+
"mapCoverage": true,
33+
"transform": {
34+
"^.+\\.tsx?$": "ts-jest"
35+
},
36+
"testRegex": "(/test/.*|/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
37+
"testPathIgnorePatterns": ["/node_modules/", "/src/test/__fixtures__/"],
38+
"coverageReporters": ["json", "text"],
39+
"moduleFileExtensions": [
40+
"ts",
41+
"tsx",
42+
"js",
43+
"jsx",
44+
"json"
3845
]
3946
},
4047
"config": {
@@ -74,16 +81,16 @@
7481
"@sourcegraph/prettierrc": "^2.0.0",
7582
"@sourcegraph/tslint-config": "^9.0.3",
7683
"@types/highlight.js": "^9.12.1",
77-
"@types/mocha": "^2.2.44",
84+
"@types/jest": "^21.1.8",
7885
"@types/mz": "0.0.32",
7986
"@types/node": "^8.0.53",
8087
"@types/yargs": "^8.0.2",
8188
"cz-conventional-changelog": "^2.1.0",
8289
"husky": "^0.14.3",
83-
"mocha": "^4.0.1",
84-
"nyc": "^11.3.0",
90+
"jest": "^21.2.1",
8591
"prettier": "1.8.2",
8692
"semantic-release": "^10.0.0",
93+
"ts-jest": "^21.2.3",
8794
"tslint": "^5.8.0",
8895
"typedoc": "^0.9.0",
8996
"typescript": "^2.6.1",

src/index.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,17 @@ function colorizeNode(node: parse5.AST.HtmlParser2.Node, theme: Theme = {}): str
77
return (node as parse5.AST.HtmlParser2.TextNode).data
88
} else if (node.type === 'tag') {
99
const hljsClass = /hljs-(\w+)/.exec((node as parse5.AST.HtmlParser2.Element).attribs.class)
10-
const token = hljsClass[1]
11-
const nodeData = (node as parse5.AST.HtmlParser2.Element).childNodes
12-
.map(node => colorizeNode(node, theme))
13-
.join('')
14-
return ((theme as any)[token] || (DEFAULT_THEME as any)[token] || plain)(nodeData)
10+
if (hljsClass) {
11+
const token = hljsClass[1]
12+
const nodeData = (node as parse5.AST.HtmlParser2.Element).childNodes
13+
.map(node => colorizeNode(node, theme))
14+
.join('')
15+
return ((theme as any)[token] || (DEFAULT_THEME as any)[token] || plain)(nodeData)
16+
}
17+
18+
// Return the data itself when the class name isn't prefixed with a highlight.js token prefix.
19+
// This is common in instances of sublanguages (JSX, Markdown Code Blocks, etc.)
20+
return (node as parse5.AST.HtmlParser2.Element).childNodes.map(node => colorizeNode(node, theme)).join('')
1521
}
1622
}
1723

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ЗагрузитьИзФайла ext_module.txt // директива 7.7
2+
#Если Клиент ИЛИ НаКлиенте Тогда // инструкции препроцессора
3+
&НаКлиентеНаСервереБезКонтекста // директивы компиляции
4+
Функция ТолстыйКлиентОбычноеПриложение(Знач Параметр1 = Неопределено, // комментарий
5+
Параметр2 = "", ПараметрN = 123.45, ПарамNN) Экспорт // еще комментарий
6+
Попытка
7+
Результат_Булевы_Значения = Новый Структура("П1, П2", Истина, Ложь, NULL, Неопределено);
8+
Перейти ~МеткаGOTO; // комментарий
9+
РезультатТаблицаДат = Новый ТаблицаЗначений;
10+
РезультатТаблицаДат.Колонки.Добавить("Колонка1",
11+
Новый ОписаниеТипов("Дата", , ,
12+
Новый КвалификаторыДаты(ЧастиДаты.ДатаВремя));
13+
НС = РезультатТаблицаДат.Добавить(); НС["Колонка1"] = '20170101120000');
14+
Исключение
15+
ОписаниеОшибки = ОписаниеОшибки(); // встроенная функция
16+
Масс = Новый Массив; // встроенный тип
17+
Для Каждого Значение Из Масс Цикл
18+
Сообщить(Значение + Символы.ПС + "
19+
|продолжение строки"); // продолжение многострочной строки
20+
Продолжить; Прервать;
21+
КонецЦикла;
22+
СправочникСсылка = Справочники.Языки.НайтиПоНаименованию("ru"); // встроенные типы
23+
СправочникОбъект = СправочникСсылка.ПолучитьОбъект();
24+
ПеречислениеСсылка = Перечисления.ВидыМодификацииДанных.Изменен;
25+
ВызватьИсключение ОписаниеОшибки;
26+
КонецПопытки;
27+
~МеткаGOTO: // еще комментарий
28+
ВД = ВидДвиженияБухгалтерии.Дебет;
29+
КонецФункции // ТолстыйКлиентОбычноеПриложение()
30+
#КонецЕсли

src/test/__fixtures__/ABNF.abnf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; line comment
2+
3+
ruleset = [optional] *(group1 / group2 / SP) CRLF ; trailing comment
4+
5+
group1 = alt1
6+
group1 =/ alt2
7+
8+
alt1 = %x41-4D / %d78-90
9+
10+
alt2 = %b00100001
11+
12+
group2 = *1DIGIT / 2*HEXDIG / 3*4OCTET
13+
14+
optional = hex-codes
15+
/ literal
16+
/ sensitive
17+
/ insensitive
18+
19+
hex-codes = %x68.65.6C.6C.6F
20+
literal = "string literal"
21+
sensitive = %s"case-sensitive string"
22+
insensitive = %i"case-insensitive string"
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.text
2+
3+
.global connect
4+
connect:
5+
mov r3, #2 ; s->sin_family = AF_INET
6+
strh r3, [sp]
7+
ldr r3, =server_port ; s->sin_port = server_port
8+
ldr r3, [r3]
9+
strh r3, [sp, #2]
10+
ldr r3, =server_addr ; s->sin_addr = server_addr
11+
ldr r3, [r3]
12+
str r3, [sp, #4]
13+
mov r3, #0 ; bzero(&s->sin_zero)
14+
str r3, [sp, #8]
15+
str r3, [sp, #12]
16+
mov r1, sp ; const struct sockaddr *addr = sp
17+
18+
ldr r7, =connect_call
19+
ldr r7, [r7]
20+
swi #0
21+
22+
add sp, sp, #16
23+
pop {r0} ; pop sockfd
24+
25+
pop {r7}
26+
pop {fp, ip, lr}
27+
mov sp, ip
28+
bx lr
29+
30+
.data
31+
socket_call: .long 281
32+
connect_call: .long 283
33+
34+
/* all addresses are network byte-order (big-endian) */
35+
server_addr: .long 0x0100007f ; localhost
36+
server_port: .hword 0x0b1a
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
;* Title: Block Copy Routines
2+
;* Version: 1.1
3+
4+
.include "8515def.inc"
5+
6+
rjmp RESET ;reset handle
7+
8+
.def flashsize=r16 ;size of block to be copied
9+
10+
flash2ram:
11+
lpm ;get constant
12+
st Y+,r0 ;store in SRAM and increment Y-pointer
13+
adiw ZL,1 ;increment Z-pointer
14+
dec flashsize
15+
brne flash2ram ;if not end of table, loop more
16+
ret
17+
18+
.def ramtemp =r1 ;temporary storage register
19+
.def ramsize =r16 ;size of block to be copied

src/test/__fixtures__/Access Log.log

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20.164.151.111 - - [20/Aug/2015:22:20:18 -0400] "GET /mywebpage/index.php HTTP/1.1" 403 772 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.220 Safari/535.1"
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.example.dummy {
2+
import org.dummy.*;
3+
4+
/*define package inline interface*/
5+
public interface IFooBarzable {
6+
public function foo(... pairs):Array;
7+
}
8+
9+
public class FooBar implements IFooBarzable {
10+
static private var cnt:uint = 0;
11+
private var bar:String;
12+
13+
//constructor
14+
public function TestBar(bar:String):void {
15+
bar = bar;
16+
++cnt;
17+
}
18+
19+
public function foo(... pairs):Array {
20+
pairs.push(bar);
21+
return pairs;
22+
}
23+
}
24+
}

src/test/__fixtures__/Ada.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package body Sqlite.Simple is
2+
3+
Foo : int := int'Size;
4+
Bar : int := long'Size;
5+
6+
Error_Message_C : chars_ptr := Sqlite_Errstr (Error);
7+
Error_Message : String := Null_Ignore_Value (Error_Message_C);
8+
begin
9+
10+
Named : for Index in Foo..Bar loop
11+
Put ("Hi[]{}");
12+
end loop Named;
13+
14+
Foo := Bar;
15+
end Message;
16+
17+
end Sqlite.Simple;

src/test/__fixtures__/ApacheConf.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# rewrite`s rules for wordpress pretty url
2+
LoadModule rewrite_module modules/mod_rewrite.so
3+
RewriteCond %{REQUEST_FILENAME} !-f
4+
RewriteCond %{REQUEST_FILENAME} !-d
5+
RewriteRule . index.php [NC,L]
6+
7+
ExpiresActive On
8+
ExpiresByType application/x-javascript "access plus 1 days"
9+
10+
Order Deny,Allow
11+
Allow from All
12+
13+
<Location /maps/>
14+
RewriteMap map txt:map.txt
15+
RewriteMap lower int:tolower
16+
RewriteCond %{REQUEST_URI} ^/([^/.]+)\.html$ [NC]
17+
RewriteCond ${map:${lower:%1}|NOT_FOUND} !NOT_FOUND
18+
RewriteRule .? /index.php?q=${map:${lower:%1}} [NC,L]
19+
</Location>

src/test/__fixtures__/AppleScript.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
repeat 5 times
2+
if foo is greater than bar then
3+
display dialog "Hello there"
4+
else
5+
beep
6+
end if
7+
end repeat
8+
9+
(* comment (*nested comment*) *)
10+
on do_something(s, y)
11+
return {s + pi, y mod 4}
12+
end do_something
13+
14+
do shell script "/bin/echo 'hello'"

src/test/__fixtures__/Arduino.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
Blink
3+
Turns on an LED on for one second, then off for one second, repeatedly.
4+
5+
This example code is in the public domain.
6+
*/
7+
8+
// Pin 13 has an LED connected on most Arduino boards.
9+
// give it a name:
10+
int led = 13;
11+
12+
// the setup routine runs once when you press reset:
13+
void setup() {
14+
// initialize the digital pin as an output.
15+
pinMode(led, OUTPUT);
16+
}
17+
18+
// the loop routine runs over and over again forever:
19+
void loop() {
20+
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
21+
delay(1000); // wait for a second
22+
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
23+
delay(1000); // wait for a second
24+
}

src/test/__fixtures__/AsciiDoc.txt

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
Hello, World!
2+
============
3+
Author Name, <[email protected]>
4+
5+
you can write text http://example.com[with links], optionally
6+
using an explicit link:http://example.com[link prefix].
7+
8+
* single quotes around a phrase place 'emphasis'
9+
** alternatively, you can put underlines around a phrase to add _emphasis_
10+
* astericks around a phrase make the text *bold*
11+
* pluses around a phrase make it +monospaced+
12+
* `smart' quotes using a leading backtick and trailing single quote
13+
** use two of each for double ``smart'' quotes
14+
15+
- escape characters are supported
16+
- you can escape a quote inside emphasized text like 'here\'s johnny!'
17+
18+
term:: definition
19+
another term:: another definition
20+
21+
// this is just a comment
22+
23+
Let's make a break.
24+
25+
'''
26+
27+
////
28+
we'll be right with you
29+
30+
after this brief interruption.
31+
////
32+
33+
== We're back!
34+
35+
Want to see a image::images/tiger.png[Tiger]?
36+
37+
.Nested highlighting
38+
++++
39+
<this_is inline="xml"></this_is>
40+
++++
41+
42+
____
43+
asciidoc is so powerful.
44+
____
45+
46+
another quote:
47+
48+
[quote, Sir Arthur Conan Doyle, The Adventures of Sherlock Holmes]
49+
____
50+
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
51+
____
52+
53+
Getting Literal
54+
---------------
55+
56+
want to get literal? prefix a line with a space.
57+
58+
....
59+
I'll join that party, too.
60+
....
61+
62+
. one thing (yeah!)
63+
. two thing `i can write code`, and `more` wipee!
64+
65+
NOTE: AsciiDoc is quite cool, you should try it.

0 commit comments

Comments
 (0)