From 3bff7cbac16b543931bae2265436bab8816d7329 Mon Sep 17 00:00:00 2001 From: Guillem Perez Date: Tue, 3 Nov 2015 10:19:26 +0100 Subject: [PATCH 1/5] Internal port conf --- client/src/app/main/robochat.service.js | 2 +- server/src/main/java/com/woorea/robochat/RoboChat.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/app/main/robochat.service.js b/client/src/app/main/robochat.service.js index 352c190..edd0f83 100644 --- a/client/src/app/main/robochat.service.js +++ b/client/src/app/main/robochat.service.js @@ -2,7 +2,7 @@ export class RoboChat { constructor (listener) { - let ws = new WebSocket("ws://localhost:8080/realtime") + let ws = new WebSocket("ws://localhost:8000/realtime") ws.onopen = (event) => { console.log(event); diff --git a/server/src/main/java/com/woorea/robochat/RoboChat.java b/server/src/main/java/com/woorea/robochat/RoboChat.java index 37be25e..ab9b254 100644 --- a/server/src/main/java/com/woorea/robochat/RoboChat.java +++ b/server/src/main/java/com/woorea/robochat/RoboChat.java @@ -89,7 +89,7 @@ public static void main( String[] args ) { }); - server.requestHandler(router::accept).listen(8080); + server.requestHandler(router::accept).listen(8000); } From a69b20eb04a8badc209182c7e02c503eea036973 Mon Sep 17 00:00:00 2001 From: Guillem Perez Date: Wed, 4 Nov 2015 13:07:19 +0100 Subject: [PATCH 2/5] highlight module added --- client/src/app/index.module.js | 13 +++++++++++-- client/src/app/main/main.jade | 3 +++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/client/src/app/index.module.js b/client/src/app/index.module.js index de7d269..b88994b 100644 --- a/client/src/app/index.module.js +++ b/client/src/app/index.module.js @@ -10,15 +10,24 @@ import { NavbarDirective } from '../app/components/navbar/navbar.directive'; import { MalarkeyDirective } from '../app/components/malarkey/malarkey.directive'; import { roboChatMessagesDirective } from './main/robochat.messages.directive'; -angular.module('client', ['ngAnimate', 'ngCookies', 'ngTouch', 'ngSanitize', 'ngMessages', 'ngAria', 'ui.router', 'ui.bootstrap', 'toastr']) +angular.module('client', ['ngAnimate', 'ngCookies', 'ngTouch', 'ngSanitize', 'ngMessages', 'ngAria', 'ui.router', 'ui.bootstrap', 'toastr', 'hljs']) .constant('malarkey', malarkey) .constant('moment', moment) .config(config) .config(routerConfig) + .config(function (hljsServiceProvider) { + hljsServiceProvider.setOptions({ + // replace tab with 4 spaces + tabReplace: ' ' + }); + }) .run(runBlock) .service('githubContributor', GithubContributorService) .service('webDevTec', WebDevTecService) .controller('MainController', MainController) .directive('acmeNavbar', NavbarDirective) .directive('acmeMalarkey', MalarkeyDirective) - .directive('robochatMessages', roboChatMessagesDirective); + .directive('robochatMessages', roboChatMessagesDirective){ + //hljs.initHighlighting(); +}; +//hljs.initHighlighting(); diff --git a/client/src/app/main/main.jade b/client/src/app/main/main.jade index 33ef628..3d8a1a5 100644 --- a/client/src/app/main/main.jade +++ b/client/src/app/main/main.jade @@ -8,6 +8,7 @@ div li(data-ng-repeat="developer in main.robochat.developers") span.status(data-ng-class="developer.status") span(data-ng-bind="'@' + developer.name") + div(hljs no-scape) footer div#content header @@ -23,6 +24,8 @@ div span.member(data-ng-bind="message.member") span.timestamp(data-ng-bind="message.ts | date:'HH:mm:ss'") div(data-ng-bind="message.text") + div(hljs no-scape ng-bind-html="message.text" ) + div(hljs no-scape ng-bind-html-unsafe="message.text" ) footer footer textarea(data-ng-model="main.message" ng-keyup="$event.keyCode == 13 && main.post()") From cea5bcb21f12469a03290b927c0326ac43e837d4 Mon Sep 17 00:00:00 2001 From: Guillem Perez Date: Thu, 5 Nov 2015 11:25:47 +0100 Subject: [PATCH 3/5] Highlight code working and detect if is code or text --- client/bower.json | 4 +++- client/src/app/index.module.js | 17 +++++++------- .../app/main/highlight.message.directive.js | 23 +++++++++++++++++++ client/src/app/main/main.jade | 5 +--- 4 files changed, 35 insertions(+), 14 deletions(-) create mode 100644 client/src/app/main/highlight.message.directive.js diff --git a/client/bower.json b/client/bower.json index 3f50fae..079aa26 100644 --- a/client/bower.json +++ b/client/bower.json @@ -15,7 +15,9 @@ "angular-toastr": "~1.5.0", "moment": "~2.10.6", "animate.css": "~3.4.0", - "angular": "~1.4.2" + "angular": "~1.4.2", + "highlightjs": "~8.8.0", + "angular-highlightjs": "~0.4.3" }, "devDependencies": { "angular-mocks": "~1.4.2" diff --git a/client/src/app/index.module.js b/client/src/app/index.module.js index b88994b..7bbbaa6 100644 --- a/client/src/app/index.module.js +++ b/client/src/app/index.module.js @@ -9,6 +9,7 @@ import { WebDevTecService } from '../app/components/webDevTec/webDevTec.service' import { NavbarDirective } from '../app/components/navbar/navbar.directive'; import { MalarkeyDirective } from '../app/components/malarkey/malarkey.directive'; import { roboChatMessagesDirective } from './main/robochat.messages.directive'; +import { highlightMessageDirective } from './main/highlight.message.directive'; angular.module('client', ['ngAnimate', 'ngCookies', 'ngTouch', 'ngSanitize', 'ngMessages', 'ngAria', 'ui.router', 'ui.bootstrap', 'toastr', 'hljs']) .constant('malarkey', malarkey) @@ -16,18 +17,16 @@ angular.module('client', ['ngAnimate', 'ngCookies', 'ngTouch', 'ngSanitize', 'ng .config(config) .config(routerConfig) .config(function (hljsServiceProvider) { - hljsServiceProvider.setOptions({ - // replace tab with 4 spaces - tabReplace: ' ' - }); - }) + hljsServiceProvider.setOptions({ + // replace tab with 4 spaces + tabReplace: ' ' + }); + }) .run(runBlock) .service('githubContributor', GithubContributorService) .service('webDevTec', WebDevTecService) .controller('MainController', MainController) .directive('acmeNavbar', NavbarDirective) .directive('acmeMalarkey', MalarkeyDirective) - .directive('robochatMessages', roboChatMessagesDirective){ - //hljs.initHighlighting(); -}; -//hljs.initHighlighting(); + .directive('robochatMessages', roboChatMessagesDirective) + .directive('highlightMessage',['$compile', highlightMessageDirective]); diff --git a/client/src/app/main/highlight.message.directive.js b/client/src/app/main/highlight.message.directive.js new file mode 100644 index 0000000..7094f8e --- /dev/null +++ b/client/src/app/main/highlight.message.directive.js @@ -0,0 +1,23 @@ +export function highlightMessageDirective( $compile ) { + + return { + scope: { }, + link: function(scope, el, attr) { + var onlyRunOne = scope.$watch( + function(scope) { + return scope.$eval(attr.compile); + }, + function(value) { + var content = el.text(); + var pattern = new RegExp(/[~`\^\[\]\\/{}|\\<>]/); + if(pattern.test(content)){ + el.html(""); + el.append(""+content+""); + $compile(el.contents())(scope); + } + // Angular un-watch + onlyRunOne(); + }); + } + }; +} \ No newline at end of file diff --git a/client/src/app/main/main.jade b/client/src/app/main/main.jade index 3d8a1a5..48c0e75 100644 --- a/client/src/app/main/main.jade +++ b/client/src/app/main/main.jade @@ -8,7 +8,6 @@ div li(data-ng-repeat="developer in main.robochat.developers") span.status(data-ng-class="developer.status") span(data-ng-bind="'@' + developer.name") - div(hljs no-scape) footer div#content header @@ -23,9 +22,7 @@ div header span.member(data-ng-bind="message.member") span.timestamp(data-ng-bind="message.ts | date:'HH:mm:ss'") - div(data-ng-bind="message.text") - div(hljs no-scape ng-bind-html="message.text" ) - div(hljs no-scape ng-bind-html-unsafe="message.text" ) + div(ng-bind="message.text" highlight-message="") footer footer textarea(data-ng-model="main.message" ng-keyup="$event.keyCode == 13 && main.post()") From c6881fa4a8df0b401c3c34786cf19323cc0b6fb0 Mon Sep 17 00:00:00 2001 From: Guillem Perez Date: Thu, 5 Nov 2015 11:29:37 +0100 Subject: [PATCH 4/5] Default ports --- client/src/app/main/robochat.service.js | 2 +- server/src/main/java/com/woorea/robochat/RoboChat.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/src/app/main/robochat.service.js b/client/src/app/main/robochat.service.js index edd0f83..352c190 100644 --- a/client/src/app/main/robochat.service.js +++ b/client/src/app/main/robochat.service.js @@ -2,7 +2,7 @@ export class RoboChat { constructor (listener) { - let ws = new WebSocket("ws://localhost:8000/realtime") + let ws = new WebSocket("ws://localhost:8080/realtime") ws.onopen = (event) => { console.log(event); diff --git a/server/src/main/java/com/woorea/robochat/RoboChat.java b/server/src/main/java/com/woorea/robochat/RoboChat.java index ab9b254..37be25e 100644 --- a/server/src/main/java/com/woorea/robochat/RoboChat.java +++ b/server/src/main/java/com/woorea/robochat/RoboChat.java @@ -89,7 +89,7 @@ public static void main( String[] args ) { }); - server.requestHandler(router::accept).listen(8000); + server.requestHandler(router::accept).listen(8080); } From 1590f94d3b313266588a314f24290f5efcc6c60b Mon Sep 17 00:00:00 2001 From: Guillem Perez Date: Fri, 6 Nov 2015 12:31:00 +0100 Subject: [PATCH 5/5] Parse code when start with triple-backticks, allowing to coexist text with code and multiple and diferent code --- .../app/main/highlight.message.directive.js | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/client/src/app/main/highlight.message.directive.js b/client/src/app/main/highlight.message.directive.js index 7094f8e..07942c0 100644 --- a/client/src/app/main/highlight.message.directive.js +++ b/client/src/app/main/highlight.message.directive.js @@ -8,12 +8,22 @@ export function highlightMessageDirective( $compile ) { return scope.$eval(attr.compile); }, function(value) { - var content = el.text(); - var pattern = new RegExp(/[~`\^\[\]\\/{}|\\<>]/); - if(pattern.test(content)){ + var content = el.text(); + var codeParts = content.split("```").filter(function(el) {return el.length != 0}); + var startCode = (content.indexOf("```")==0) + if(codeParts.length>1 || startCode){ el.html(""); - el.append(""+content+""); - $compile(el.contents())(scope); + + codeParts.forEach(function(part, it){ + if(startCode != (it%2)){ + console.log("is Code"); + el.append(""+part+""); + }else{ + el.append(part); + } + console.log(it, part); + }); + $compile(el.contents())(scope); } // Angular un-watch onlyRunOne();