diff --git a/css/glowingbear.css b/css/glowingbear.css index bee10d0..ca11870 100644 --- a/css/glowingbear.css +++ b/css/glowingbear.css @@ -926,3 +926,9 @@ img.emojione { [ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak { display: none !important; } + +code { + padding: 0px 2px; + color: #444; + border: 1pt solid #444; +} \ No newline at end of file diff --git a/css/themes/dark.css b/css/themes/dark.css index c03e47a..da260c8 100644 --- a/css/themes/dark.css +++ b/css/themes/dark.css @@ -2114,6 +2114,11 @@ button.close:hover { font-weight: bold; } +code { + background-color: #444; + color: #fff; +} + /* */ /* Mobile layout */ /* */ diff --git a/index.html b/index.html index d76b4b5..94c3d11 100644 --- a/index.html +++ b/index.html @@ -317,7 +317,7 @@ npm run build-electron-{windows, darwin, linux} <>
+ --> diff --git a/js/filters.js b/js/filters.js index 027acbe..61f13c0 100644 --- a/js/filters.js +++ b/js/filters.js @@ -59,6 +59,17 @@ weechat.filter('inlinecolour', function() { }; }); +// Calls the 'linky' filter unless the disable flag is set. Useful for things like join/quit messages, +// so you don't accidentally click a mailto: on someone's hostmask. +weechat.filter('conditionalLinkify', ['$filter', function($filter) { + return function(text, disable) { + if (!text || disable) { + return text; + } + return $filter('linky')(text, '_blank', {rel:'noopener noreferrer'}); + }; +}]); + // apply a filter to an HTML string's text nodes, and do so with not exceedingly terrible performance weechat.filter('DOMfilter', ['$filter', '$sce', function($filter, $sce) { // To prevent nested anchors, we need to know if a filter is going to create them. @@ -226,4 +237,19 @@ weechat.filter('prefixlimit', function() { }; }); +weechat.filter('codify', function() { + return function(text) { + // The groups of this regex are: + // 1. Start of line or space, to prevent codifying weird`stuff` like this + // 2. Opening single or triple backticks (not 2, not more than 3) + // 3. The code block, does not start with another backtick, non-greedy expansion + // 4. The closing backticks, identical to group 2 + var re = /(^|\s)(```|`)([^`].*?)\2/g; + return text.replace(re, function(match, ws, open, code) { + var rr = ws + '' + open + '' + code + '' + open + ''; + return rr; + }); + }; +}); + })(); diff --git a/package.json b/package.json index 04feae0..45a2842 100644 --- a/package.json +++ b/package.json @@ -7,12 +7,12 @@ "main": "electron-main.js", "license": "GPLv3", "devDependencies": { - "bower": "^1.8", + "bower": "^1.8.8", "electron-packager": "^12.2.0", "http-server": "^0.11", "jasmine-core": "^3.1", "jshint": "^2.9.6", - "karma": "^3.1.1", + "karma": "^4.2.0", "karma-jasmine": "~1.1", "karma-junit-reporter": "^1.2", "karma-phantomjs-launcher": "^1.0.0", diff --git a/test/unit/filters.js b/test/unit/filters.js index 2b1358f..ebd6e39 100644 --- a/test/unit/filters.js +++ b/test/unit/filters.js @@ -92,4 +92,45 @@ describe('Filters', function() { // I.e. if we ever got this far, the bug is fixed. })); }); + + describe('codify', function() { + it('should not mess up text', inject(function(codifyFilter) { + expect(codifyFilter('foo')).toEqual('foo'); + })); + + it('should codify single snippets', inject(function(codifyFilter) { + expect(codifyFilter('z `foo` z')).toEqual('z `foo` z'); + expect(codifyFilter('z `a` z')).toEqual('z `a` z'); + expect(codifyFilter('z ```foo``` z')).toEqual('z ```foo``` z'); + })); + + it('should codify multiple snippets', inject(function(codifyFilter) { + expect(codifyFilter('z `foo` z `bar` `baz`')).toEqual('z `foo` z `bar` `baz`'); + })); + + it('should not codify empty snippets', inject(function(codifyFilter) { + expect(codifyFilter('``')).toEqual('``'); + })); + + it('should not codify single backticks', inject(function(codifyFilter) { + expect(codifyFilter('foo`bar')).toEqual('foo`bar'); + })); + + + it('should not codify double backticks', inject(function(codifyFilter) { + expect(codifyFilter('some ``non-code``')).toEqual('some ``non-code``'); + })); + + + it('should not codify pseudo-fancy quotes', inject(function(codifyFilter) { + expect(codifyFilter('some ``fancy qoutes\'\'')).toEqual('some ``fancy qoutes\'\''); + })); + + it('should not codify stuff in the middle of a word or URL', inject(function(codifyFilter) { + expect(codifyFilter('https://foo.bar/`wat`')).toEqual('https://foo.bar/`wat`'); + expect(codifyFilter('Weird`ness`')).toEqual('Weird`ness`'); + })); + + + }); });