Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/isagalaev/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
amckibben committed Jul 12, 2016
2 parents 517cfef + a33fad5 commit c13c696
Show file tree
Hide file tree
Showing 26 changed files with 273 additions and 84 deletions.
193 changes: 112 additions & 81 deletions demo/demo.js
Original file line number Diff line number Diff line change
@@ -1,88 +1,119 @@
function resizeLists() {
var
categories = $('#categories'),
styles = $('#styles');
categories.css('max-height', $(window).height() / 4);
categories.perfectScrollbar('update');
styles.height($(window).height() - styles.position().top - 20);
styles.perfectScrollbar('update');
}

function selectCategory(category) {
$('#languages div').each(function(i, div) {
div = $(div);
if (div.hasClass(category)) {
var code = div.find('code');
if (!code.hasClass('hljs')) {
hljs.highlightBlock(code.get(0));
(function() {
'use strict';

var $window = $(window),
$languages = $('#languages div'),
$linkTitle = $('link[title]'),
$categoryContainer = $('#categories'),
$styleContainer = $('#styles');

function resizeLists() {
var screenHeight = $window.height()

$categoryContainer.css('max-height', screenHeight / 4);
$categoryContainer.perfectScrollbar('update');
$styleContainer.height(
screenHeight - $styleContainer.position().top - 20
);
$styleContainer.perfectScrollbar('update');
}

function selectCategory(category) {
$languages.each(function(i, language) {
var $language = $(language);

if ($language.hasClass(category)) {
var code = $language.find('code');

if (!code.hasClass('hljs')) {
hljs.highlightBlock(code.get(0));
}

$language.show();
} else {
$language.hide();
}
div.show();
} else {
div.hide();
}
});
});

$(document).scrollTop(0);
}

$(document).scrollTop(0);
}

function categoryKey(c) {
return c === 'common' ? '' : c === 'misc' ? 'z' : c === 'all' ? 'zz' : c;
}

function initCategories() {
var categories = {};
$('#languages div').each(function(i, div) {
if (!div.className) {
div.className += 'misc';
}
div.className += ' all';
div.className.split(' ').forEach(function(c) {
categories[c] = (categories[c] || 0) + 1;
function categoryKey(c) {
return c === 'common' ? '' : c === 'misc' ? 'z' : c === 'all' ? 'zz' : c;
}

function initCategories() {
var $categories, categoryNames;
var categories = {};

$languages.each(function(i, div) {
if (!div.className) {
div.className += 'misc';
}
div.className += ' all';
div.className.split(' ').forEach(function(c) {
categories[c] = (categories[c] || 0) + 1;
});
});
});
var ul = $('#categories');
var category_names = Object.keys(categories);
category_names.sort(function(a, b) {
a = categoryKey(a);
b = categoryKey(b);
return a < b ? -1 : a > b ? 1 : 0;
});
category_names.forEach(function(c) {
ul.append('<li data-category="' + c + '">' + c + ' (' + categories[c] +')</li>');
});
$('#categories li').click(function(e) {
$('#categories li').removeClass('current');
$(this).addClass('current');
selectCategory($(this).data('category'));
});
$('#categories li:first-child').click();
ul.perfectScrollbar();
}

function selectStyle(style) {
$('link[title]').each(function(i, link) {
link.disabled = (link.title != style);
});
}
categoryNames = Object.keys(categories);

function initStyles() {
var ul = $('#styles');
$('link[title]').each(function(i, link) {
ul.append('<li>' + link.title + '</li>');
});
$('#styles li').click(function(e) {
$('#styles li').removeClass('current');
$(this).addClass('current');
selectStyle($(this).text());
});
$('#styles li:first-child').click();
ul.perfectScrollbar();
}
categoryNames.sort(function(a, b) {
a = categoryKey(a);
b = categoryKey(b);
return a < b ? -1 : a > b ? 1 : 0;
});

categoryNames.forEach(function(c) {
$categoryContainer.append(
'<li data-category="' + c + '">' + c + ' (' + categories[c] +')</li>'
);
});

$categories = $categoryContainer.find('li');

$categories.click(function() {
var $category = $(this);

$categories.removeClass('current');
$category.addClass('current');
selectCategory($category.data('category'));
});

$categories.first().click();
$categoryContainer.perfectScrollbar();
}

$(document).ready(function() {
initCategories();
initStyles();
$(window).resize(resizeLists);
resizeLists();
});
function selectStyle(style) {
$linkTitle.each(function(i, link) {
link.disabled = (link.title !== style);
});
}

function initStyles() {
var $styles;

$linkTitle.each(function(i, link) {
$styleContainer.append('<li>' + link.title + '</li>');
});

$styles = $styleContainer.find('li');

$styles.click(function() {
var $style = $(this);

$styles.removeClass('current');
$style.addClass('current');
selectStyle($style.text());
});
$styles.first().click();
$styleContainer.perfectScrollbar();
}

$(function() {
initCategories();
initStyles();
$window.resize(resizeLists);
resizeLists();
});
}).call(this);
2 changes: 2 additions & 0 deletions docs/css-classes-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ Language names and aliases
+-------------------------+---------------------------------------------------+
| Stylus | stylus, styl |
+-------------------------+---------------------------------------------------+
| SubUnit | subunit |
+-------------------------+---------------------------------------------------+
| Swift | swift |
+-------------------------+---------------------------------------------------+
| Test Anything Protocol | tap |
Expand Down
4 changes: 3 additions & 1 deletion src/highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,9 @@ https://highlightjs.org/
function highlight(name, value, ignore_illegals, continuation) {

function subMode(lexeme, mode) {
for (var i = 0; i < mode.contains.length; i++) {
var i, length;

for (i = 0, length = mode.contains.length; i < length; i++) {
if (testRe(mode.contains[i].beginRe, lexeme)) {
return mode.contains[i];
}
Expand Down
4 changes: 2 additions & 2 deletions src/languages/elm.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ function(hljs) {
return {
keywords:
'let in if then else case of where module import exposing ' +
'type alias as infix infixl infixr port effect command',
'type alias as infix infixl infixr port effect command subscription',
contains: [

// Top-level constructions.

{
beginKeywords: 'port effect module', end: 'exposing',
keywords: 'port effect module where command exposing',
keywords: 'port effect module where command subscription exposing',
contains: [LIST, COMMENT],
illegal: '\\W\\.|;'
},
Expand Down
40 changes: 40 additions & 0 deletions src/languages/subunit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Language: SubUnit
Author: Sergey Bronnikov <[email protected]>
Website: https://bronevichok.ru/
*/

function(hljs) {
var DETAILS = {
className: 'string',
begin: '\\[\n(multipart)?', end: '\\]\n'
};
var TIME = {
className: 'string',
begin: '\\d{4}-\\d{2}-\\d{2}(\\s+)\\d{2}:\\d{2}:\\d{2}\.\\d+Z'
};
var PROGRESSVALUE = {
className: 'string',
begin: '(\\+|-)\\d+'
};
var KEYWORDS = {
className: 'keyword',
relevance: 10,
variants: [
{ begin: '^(test|testing|success|successful|failure|error|skip|xfail|uxsuccess)(:?)\\s+(test)?' },
{ begin: '^progress(:?)(\\s+)?(pop|push)?' },
{ begin: '^tags:' },
{ begin: '^time:' }
],
};
return {
aliases: ['subunit'],
case_insensitive: true,
contains: [
DETAILS,
TIME,
PROGRESSVALUE,
KEYWORDS
]
};
}
18 changes: 18 additions & 0 deletions test/detect/subunit/default.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
progress: 28704
time: 2016-07-05 12:17:02.290433Z
test: bzrlib.doc.api.DocFileTest(/usr/lib64/python2.7/site-packages/bzrlib/doc/api/branch.txt)
time: 2016-07-05 12:17:02.314892Z
successful: bzrlib.doc.api.DocFileTest(/usr/lib64/python2.7/site-packages/bzrlib/doc/api/branch.txt)
time: 2016-07-05 12:17:02.314939Z
time: 2016-07-05 12:17:02.314991Z
test: bzrlib.doc.api.DocFileTest(/usr/lib64/python2.7/site-packages/bzrlib/doc/api/transport.txt)
time: 2016-07-05 12:17:02.315665Z
successful: bzrlib.doc.api.DocFileTest(/usr/lib64/python2.7/site-packages/bzrlib/doc/api/transport.txt)
time: 2016-07-05 12:17:02.315691Z
time: 2016-07-05 12:17:02.315770Z
test: bzrlib.tests.blackbox.test_add.TestAdd.test_add_control_dir(pre-views)
time: 2016-07-05 12:17:02.368936Z
successful: bzrlib.tests.blackbox.test_add.TestAdd.test_add_control_dir(pre-views) [ multipart
]
time: 2016-07-05 12:17:02.368993Z
time: 2016-07-05 12:17:02.369079Z
2 changes: 2 additions & 0 deletions test/markup/subunit/subunit-errorline.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<span class="hljs-keyword">error: test</span> simplename
<span class="hljs-keyword">error: test</span> simple name
2 changes: 2 additions & 0 deletions test/markup/subunit/subunit-errorline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
error: test simplename
error: test simple name
4 changes: 4 additions & 0 deletions test/markup/subunit/subunit-failureline.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<span class="hljs-keyword">failure: test</span> simplename1
<span class="hljs-keyword">failure test</span> simplename1
<span class="hljs-keyword">failure: test</span> simple name1
<span class="hljs-keyword">failure test</span> simple name1
4 changes: 4 additions & 0 deletions test/markup/subunit/subunit-failureline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
failure: test simplename1
failure test simplename1
failure: test simple name1
failure test simple name1
7 changes: 7 additions & 0 deletions test/markup/subunit/subunit-progressline.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<span class="hljs-keyword">progress: </span><span class="hljs-string">+5</span>
<span class="hljs-keyword">progress: </span><span class="hljs-string">+12</span>
<span class="hljs-keyword">progress: </span>29
<span class="hljs-keyword">progress: </span><span class="hljs-string">-3</span>
<span class="hljs-keyword">progress: </span><span class="hljs-string">-91</span>
<span class="hljs-keyword">progress: push</span>
<span class="hljs-keyword">progress: pop</span>
7 changes: 7 additions & 0 deletions test/markup/subunit/subunit-progressline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
progress: +5
progress: +12
progress: 29
progress: -3
progress: -91
progress: push
progress: pop
3 changes: 3 additions & 0 deletions test/markup/subunit/subunit-skipline.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<span class="hljs-keyword">skip test</span> simplename
<span class="hljs-keyword">skip: test</span> simple name
<span class="hljs-keyword">skip test</span> simple name
3 changes: 3 additions & 0 deletions test/markup/subunit/subunit-skipline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
skip test simplename
skip: test simple name
skip test simple name
8 changes: 8 additions & 0 deletions test/markup/subunit/subunit-successline.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<span class="hljs-keyword">success test</span> simplename1
<span class="hljs-keyword">success: test</span> simplename2
<span class="hljs-keyword">successful test</span> simplename3
<span class="hljs-keyword">successful: test</span> simplename4
<span class="hljs-keyword">success test</span> simple name1
<span class="hljs-keyword">success: test</span> simple name2
<span class="hljs-keyword">successful test</span> simple name3
<span class="hljs-keyword">successful: test</span> simple name4
8 changes: 8 additions & 0 deletions test/markup/subunit/subunit-successline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
success test simplename1
success: test simplename2
successful test simplename3
successful: test simplename4
success test simple name1
success: test simple name2
successful test simple name3
successful: test simple name4
5 changes: 5 additions & 0 deletions test/markup/subunit/subunit-tagline.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<span class="hljs-keyword">tags:</span> fuzz unit beta functional
<span class="hljs-keyword">tags:</span> -functional basic -beta
<span class="hljs-keyword">tags:</span> -unit
<span class="hljs-keyword">tags:</span> unit
<span class="hljs-keyword">tags:</span> ddd
5 changes: 5 additions & 0 deletions test/markup/subunit/subunit-tagline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
tags: fuzz unit beta functional
tags: -functional basic -beta
tags: -unit
tags: unit
tags: ddd
10 changes: 10 additions & 0 deletions test/markup/subunit/subunit-testline.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<span class="hljs-keyword">test: test</span> basicsuite1
<span class="hljs-keyword">testing: test</span> basicsuite1
<span class="hljs-keyword">test test</span> basicsuite1
<span class="hljs-keyword">testing test</span> basicsuite1
<span class="hljs-keyword">test: test</span> basic suite1
<span class="hljs-keyword">testing: test</span> basic suite1
<span class="hljs-keyword">test test</span> basic suite1
<span class="hljs-keyword">testing test</span> basic suite1
<span class="hljs-keyword">testing test</span> basic
<span class="hljs-keyword">test test</span> 222
10 changes: 10 additions & 0 deletions test/markup/subunit/subunit-testline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
test: test basicsuite1
testing: test basicsuite1
test test basicsuite1
testing test basicsuite1
test: test basic suite1
testing: test basic suite1
test test basic suite1
testing test basic suite1
testing test basic
test test 222
3 changes: 3 additions & 0 deletions test/markup/subunit/subunit-timeline.expect.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<span class="hljs-keyword">time:</span> <span class="hljs-string">2016-03-13 18:12:37.231080Z</span>
<span class="hljs-keyword">time:</span> <span class="hljs-string">1917-10-25 09:05:37.231080Z</span>
<span class="hljs-keyword">time:</span> <span class="hljs-string">1984-03-24 07:02:09.231080Z</span>
3 changes: 3 additions & 0 deletions test/markup/subunit/subunit-timeline.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
time: 2016-03-13 18:12:37.231080Z
time: 1917-10-25 09:05:37.231080Z
time: 1984-03-24 07:02:09.231080Z
Loading

0 comments on commit c13c696

Please sign in to comment.