Skip to content

Commit

Permalink
Merge pull request phpmentoring#29 from phpmentoring/feature/markdown
Browse files Browse the repository at this point in the history
Feature/markdown
  • Loading branch information
dragonmantank committed Jun 19, 2015
2 parents bad17f1 + 42fad49 commit 048ef63
Show file tree
Hide file tree
Showing 16 changed files with 516 additions and 40 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"symfony/translation": "~2.6",
"symfony/security-csrf": "~2.6",
"symfony/form": "~2.6",
"mockery/mockery": "0.9.*"
"mockery/mockery": "0.9.*",
"erusev/parsedown": "1.5.3",
"ezyang/htmlpurifier": "4.6.0"
},
"require-dev": {
"phpunit/phpunit": "4.6.*",
Expand Down
87 changes: 85 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

196 changes: 196 additions & 0 deletions public/css/prism.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
/* http://prismjs.com/download.html?themes=prism&languages=markup+css+clike+javascript+apacheconf+c+coffeescript+css-extras+dart+gherkin+git+go+haml+handlebars+http+ini+less+php+php-extras+python+jsx+ruby+scss+sql+twig+yaml&plugins=line-numbers+autolinker+show-language */
/**
* prism.js default theme for JavaScript, CSS and HTML
* Based on dabblet (http://dabblet.com)
* @author Lea Verou
*/

code[class*="language-"],
pre[class*="language-"] {
color: black;
text-shadow: 0 1px white;
font-family: Consolas, Monaco, 'Andale Mono', monospace;
direction: ltr;
text-align: left;
white-space: pre;
word-spacing: normal;
word-break: normal;
line-height: 1.5;

-moz-tab-size: 4;
-o-tab-size: 4;
tab-size: 4;

-webkit-hyphens: none;
-moz-hyphens: none;
-ms-hyphens: none;
hyphens: none;
}

pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection,
code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection {
text-shadow: none;
background: #b3d4fc;
}

pre[class*="language-"]::selection, pre[class*="language-"] ::selection,
code[class*="language-"]::selection, code[class*="language-"] ::selection {
text-shadow: none;
background: #b3d4fc;
}

@media print {
code[class*="language-"],
pre[class*="language-"] {
text-shadow: none;
}
}

/* Code blocks */
pre[class*="language-"] {
padding: 1em;
margin: .5em 0;
overflow: auto;
}

:not(pre) > code[class*="language-"],
pre[class*="language-"] {
background: #f5f2f0;
}

/* Inline code */
:not(pre) > code[class*="language-"] {
padding: .1em;
border-radius: .3em;
}

.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
color: slategray;
}

.token.punctuation {
color: #999;
}

.namespace {
opacity: .7;
}

.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol,
.token.deleted {
color: #905;
}

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
color: #690;
}

.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string {
color: #a67f59;
background: hsla(0, 0%, 100%, .5);
}

.token.atrule,
.token.attr-value,
.token.keyword {
color: #07a;
}

.token.function {
color: #DD4A68;
}

.token.regex,
.token.important,
.token.variable {
color: #e90;
}

.token.important,
.token.bold {
font-weight: bold;
}
.token.italic {
font-style: italic;
}

.token.entity {
cursor: help;
}

pre.line-numbers {
position: relative;
padding-left: 3.8em;
counter-reset: linenumber;
}

pre.line-numbers > code {
position: relative;
}

.line-numbers .line-numbers-rows {
position: absolute;
pointer-events: none;
top: 0;
font-size: 100%;
left: -3.8em;
width: 3em; /* works for line-numbers below 1000 lines */
letter-spacing: -1px;
border-right: 1px solid #999;

-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;

}

.line-numbers-rows > span {
pointer-events: none;
display: block;
counter-increment: linenumber;
}

.line-numbers-rows > span:before {
content: counter(linenumber);
color: #999;
display: block;
padding-right: 0.8em;
text-align: right;
}
.token a {
color: inherit;
}
pre[class*='language-'] {
position: relative;
}
pre[class*='language-'][data-language]::before {
content: attr(data-language);
color: black;
background-color: #CFCFCF;
display: inline-block;
position: absolute;
top: 0;
right: 0;
font-size: 0.9em;
border-radius: 0 0 0 5px;
padding: 0 0.5em;
text-shadow: none;
}
48 changes: 42 additions & 6 deletions public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,70 @@ mentoringApp.filter('mentorTags', function() {
}
});

controllers.MentorSearchController = function($scope, $http) {
mentoringApp.filter('unsafe', function ($sce) {
return $sce.trustAsHtml;
});

mentoringApp.directive('markdownPreview', function ($http, $sce, $timeout) {
return {
replace: true,
link: function ($scope, element, attrs) {
$scope.generatePreview = function () {
$scope.loading = true;
var body = $('#' + attrs.rawBody).val();
$http.post('/api/v0/to-markdown', {raw: body}).success(function (data) {
$scope.loading = false;
if (!("markdown" in data)) {
$scope.loadingError = true;
} else {
$scope.preview = $sce.trustAsHtml(data.markdown);
$timeout(function () {
Prism.highlightAll();
}, 50);
}
}).error(function (data, status, headers, config) {
$scope.loading = false;
$scope.loadingError = true;
});
};
$('#' + attrs.generateClick).click(function () {
$scope.generatePreview();
});
},
template: '<div calss="markdown_preview"><div data-ng-show="!loading"> <span class="markdown_preview" ng-bind-html="preview" data-ng-show="!loadingError"></span> <div class="alert alert-danger" role="alert" data-ng-show="loadingError"> <strong>Oops!</strong> There was an error while trying to generate your preview. </div> </div> <div data-ng-show="loading"> <p>Loading...</p> </div></div>'
};
});

controllers.MentorSearchController = function($scope, $http, $timeout) {
$scope.mentors = [];
$scope.loadingError = false;

$http.get('/api/v0/mentors').
success(function(data, status, headers, config){
$scope.mentors = data;
$timeout(function () {
Prism.highlightAll();
}, 50);
}).
error(function(data, status, headers, config) {
$scope.loadingError = true;
});

console.log($scope.mentors);
};

controllers.ApprenticeSearchController = function($scope, $http) {
controllers.ApprenticeSearchController = function($scope, $http, $timeout) {
$scope.apprentices = [];
$scope.loadingError = false;

$http.get('/api/v0/apprentices').
success(function(data, status, headers, config){
$scope.apprentices = data;
$timeout(function () {
Prism.highlightAll();
}, 50);
}).
error(function(data, status, headers, config) {
$scope.loadingError = true;
});

console.log($scope.mentors);
};

mentoringApp.controller(controllers);
31 changes: 31 additions & 0 deletions public/js/vendor/prism.js

Large diffs are not rendered by default.

Loading

0 comments on commit 048ef63

Please sign in to comment.