Skip to content
This repository was archived by the owner on Jul 21, 2021. It is now read-only.

Commit e0ec3cf

Browse files
committed
Adding flag for turn off/on unsafe markdown
1 parent 45dfb82 commit e0ec3cf

15 files changed

+849
-79
lines changed

Gruntfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ module.exports = function (grunt) {
3030
'bower_components/angular-ui-codemirror/ui-codemirror.js',
3131
'bower_components/angular-marked/angular-marked.js',
3232
'bower_components/angular-highlightjs/angular-highlightjs.js',
33+
'bower_components/angular-sanitize/angular-sanitize.js',
3334
'bower_components/jszip/jszip.js',
3435
'bower_components/slug/slug.js',
3536
'bower_components/FileSaver/FileSaver.js',

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ In *Single View* mode you will be able to see only documentation or try-it.
108108

109109
<raml-console src="path-to-raml" documentation-collapsed></raml-console>
110110

111+
### Allowing Unsafe Markdown
112+
113+
*Unsafe Markdown* will be disable by default, if you want to allow unsafe contet check the following example:
114+
115+
<raml-console src="path-to-raml" allow-unsafe-markdown></raml-console>
116+
111117
## Development
112118

113119
### Prerequisites

bower.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"angular-highlightjs": "~0.3.2",
1111
"angular-marked": "0.0.18",
1212
"angular-ui-codemirror": "0.1.6",
13+
"angular-sanitize": "~1.3.17",
1314
"codemirror": "~3.15.0",
1415
"crypto-js": "https://crypto-js.googlecode.com/files/CryptoJS%20v3.1.2.zip",
1516
"FileSaver": "*",

dist/scripts/api-console-vendor.js

Lines changed: 722 additions & 27 deletions
Large diffs are not rendered by default.

dist/scripts/api-console-vendor.min.js

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/scripts/api-console.js

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
'RAML.Security',
2020
'hc.marked',
2121
'ui.codemirror',
22-
'hljs'
22+
'hljs',
23+
'ngSanitize'
2324
]).config(['hljsServiceProvider', function (hljsServiceProvider) {
2425
hljsServiceProvider.setOptions({
2526
classPrefix: 'raml-console-hljs-'
@@ -358,6 +359,34 @@
358359
}]);
359360
})();
360361

362+
(function () {
363+
'use strict';
364+
365+
RAML.Directives.markdown = function() {
366+
return {
367+
restrict: 'A',
368+
scope: {
369+
markdown: '='
370+
},
371+
controller: ['$scope', '$sanitize', '$window', '$element', function($scope, $sanitize, $window, $element) {
372+
$scope.$watch('markdown', function (markdown) {
373+
var allowUnsafeMarkdown = $scope.$parent.allowUnsafeMarkdown;
374+
var html = $window.marked(markdown || '', RAML.Settings.marked);
375+
376+
if (!allowUnsafeMarkdown) {
377+
html = $sanitize(html);
378+
}
379+
380+
$element.html(html);
381+
});
382+
}]
383+
};
384+
};
385+
386+
angular.module('RAML.Directives')
387+
.directive('markdown', RAML.Directives.markdown);
388+
})();
389+
361390
(function () {
362391
'use strict';
363392

@@ -1752,6 +1781,11 @@
17521781
$scope.resourcesCollapsed = false;
17531782
$scope.documentationCollapsed = false;
17541783
$scope.credentials = {};
1784+
$scope.allowUnsafeMarkdown = false;
1785+
1786+
if ($attrs.hasOwnProperty('allowUnsafeMarkdown')) {
1787+
$scope.allowUnsafeMarkdown = true;
1788+
}
17551789

17561790
if ($attrs.hasOwnProperty('singleView')) {
17571791
$scope.singleView = true;
@@ -5198,14 +5232,14 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
51985232
" <div id=\"request-documentation\" class=\"raml-console-resource-panel-primary-row raml-console-resource-panel-content raml-console-is-active\" ng-class=\"{'raml-console-is-active':showRequestDocumentation}\">\n" +
51995233
" <h3 class=\"raml-console-resource-heading-a\">Description</h3>\n" +
52005234
"\n" +
5201-
" <p marked=\"methodInfo.description\" opts=\"markedOptions\" class=\"raml-console-marked-content\"></p>\n" +
5235+
" <p markdown=\"methodInfo.description\" class=\"raml-console-marked-content\"></p>\n" +
52025236
"\n" +
52035237
" <section class=\"raml-console-resource-section\" id=\"docs-uri-parameters\" ng-if=\"resource.uriParametersForDocumentation\">\n" +
52045238
" <h3 class=\"raml-console-resource-heading-a\">URI Parameters</h3>\n" +
52055239
"\n" +
52065240
" <div class=\"raml-console-resource-param\" id=\"docs-uri-parameters-{{uriParam[0].displayName}}\" ng-repeat=\"uriParam in resource.uriParametersForDocumentation\">\n" +
52075241
" <h4 class=\"raml-console-resource-param-heading\">{{uriParam[0].displayName}}<span class=\"raml-console-resource-param-instructional\">{{parameterDocumentation(uriParam[0])}}</span></h4>\n" +
5208-
" <p marked=\"uriParam[0].description\" opts=\"markedOptions\" class=\"raml-console-marked-content\"></p>\n" +
5242+
" <p markdown=\"uriParam[0].description\" class=\"raml-console-marked-content\"></p>\n" +
52095243
"\n" +
52105244
" <p ng-if=\"uriParam[0].example\">\n" +
52115245
" <span class=\"raml-console-resource-param-example\"><b>Example:</b> {{uriParam[0].example}}</span>\n" +
@@ -5219,7 +5253,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
52195253
" <div class=\"raml-console-resource-param\" ng-repeat=\"header in methodInfo.headers.plain\" ng-if=\"!header[0].isFromSecurityScheme\">\n" +
52205254
" <h4 class=\"raml-console-resource-param-heading\">{{header[0].displayName}}<span class=\"raml-console-resource-param-instructional\">{{parameterDocumentation(header[0])}}</span></h4>\n" +
52215255
"\n" +
5222-
" <p marked=\"header[0].description\" opts=\"markedOptions\" class=\"raml-console-marked-content\"></p>\n" +
5256+
" <p markdown=\"header[0].description\" class=\"raml-console-marked-content\"></p>\n" +
52235257
"\n" +
52245258
" <p ng-if=\"header[0].example\">\n" +
52255259
" <span class=\"raml-console-resource-param-example\"><b>Example:</b> {{header[0].example}}</span>\n" +
@@ -5233,7 +5267,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
52335267
" <div class=\"raml-console-resource-param\" ng-repeat=\"queryParam in methodInfo.queryParameters\" ng-if=\"!queryParam[0].isFromSecurityScheme\">\n" +
52345268
" <h4 class=\"raml-console-resource-param-heading\">{{queryParam[0].displayName}}<span class=\"raml-console-resource-param-instructional\">{{parameterDocumentation(queryParam[0])}}</span></h4>\n" +
52355269
"\n" +
5236-
" <p marked=\"queryParam[0].description\" opts=\"markedOptions\" class=\"raml-console-marked-content\"></p>\n" +
5270+
" <p markdown=\"queryParam[0].description\" class=\"raml-console-marked-content\"></p>\n" +
52375271
"\n" +
52385272
" <p ng-if=\"queryParam[0].example\">\n" +
52395273
" <span class=\"raml-console-resource-param-example\"><b>Example:</b> {{queryParam[0].example}}</span>\n" +
@@ -5247,15 +5281,15 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
52475281
" <li class=\"raml-console-documentation-scheme\" ng-class=\"{'raml-console-is-active':isSchemeSelected(value)}\" ng-click=\"selectDocumentationScheme(value)\" ng-repeat=\"(key, value) in securitySchemes\">{{value.name}}</li>\n" +
52485282
" </ol>\n" +
52495283
"\n" +
5250-
" <p ng-if\"documentationSchemeSelected.description\" marked=\"documentationSchemeSelected.description\" opts=\"markedOptions\" class=\"raml-console-marked-content\"></p>\n" +
5284+
" <p ng-if\"documentationSchemeSelected.description\" markdown=\"documentationSchemeSelected.description\" class=\"raml-console-marked-content\"></p>\n" +
52515285
"\n" +
52525286
" <section class=\"raml-console-resource-section raml-console-scheme-headers\" ng-if=\"documentationSchemeSelected.describedBy.headers\">\n" +
52535287
" <h4 class=\"raml-console-resource-heading-a\">Headers</h4>\n" +
52545288
"\n" +
52555289
" <div class=\"raml-console-resource-param\" ng-repeat=\"(key, header) in documentationSchemeSelected.describedBy.headers\">\n" +
52565290
" <h4 class=\"raml-console-resource-param-heading\">{{key}}<span class=\"raml-console-resource-param-instructional\">{{parameterDocumentation(header)}}</span></h4>\n" +
52575291
"\n" +
5258-
" <p marked=\"header.description\" opts=\"markedOptions\" class=\"raml-console-marked-content\"></p>\n" +
5292+
" <p markdown=\"header.description\" class=\"raml-console-marked-content\"></p>\n" +
52595293
"\n" +
52605294
" <p ng-if=\"header.example\">\n" +
52615295
" <span class=\"raml-console-resource-param-example\"><b>Example:</b> {{header.example}}</span>\n" +
@@ -5269,7 +5303,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
52695303
" <div class=\"raml-console-resource-param\" ng-repeat=\"(key, queryParameter) in documentationSchemeSelected.describedBy.queryParameters\">\n" +
52705304
" <h4 class=\"raml-console-resource-param-heading\">{{key}}<span class=\"raml-console-resource-param-instructional\">{{parameterDocumentation(queryParameter)}}</span></h4>\n" +
52715305
"\n" +
5272-
" <p marked=\"queryParameter.description\" opts=\"markedOptions\" class=\"raml-console-marked-content\"></p>\n" +
5306+
" <p markdown=\"queryParameter.description\" class=\"raml-console-marked-content\"></p>\n" +
52735307
"\n" +
52745308
" <p ng-if=\"queryParameter.example\">\n" +
52755309
" <span class=\"raml-console-resource-param-example\"><b>Example:</b> {{queryParameter.example}}</span>\n" +
@@ -5282,7 +5316,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
52825316
"\n" +
52835317
" <div class=\"raml-console-resource-param\" ng-repeat=\"(code, info) in documentationSchemeSelected.describedBy.responses\">\n" +
52845318
" <h4 class=\"raml-console-resource-param-heading\">{{code}}</h4>\n" +
5285-
" <p marked=\"info.description\" opts=\"markedOptions\" class=\"raml-console-marked-content\"></p>\n" +
5319+
" <p markdown=\"info.description\" class=\"raml-console-marked-content\"></p>\n" +
52865320
" </div>\n" +
52875321
" </section>\n" +
52885322
"\n" +
@@ -5310,7 +5344,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
53105344
" <div class=\"raml-console-resource-param\" ng-repeat=\"formParam in methodInfo.body[currentBodySelected].formParameters\">\n" +
53115345
" <h4 class=\"raml-console-resource-param-heading\">{{formParam[0].displayName}}<span class=\"raml-console-resource-param-instructional\">{{parameterDocumentation(formParam[0])}}</span></h4>\n" +
53125346
"\n" +
5313-
" <p marked=\"formParam[0].description\" opts=\"markedOptions\" class=\"raml-console-marked-content\"></p>\n" +
5347+
" <p markdown=\"formParam[0].description\" class=\"raml-console-marked-content\"></p>\n" +
53145348
"\n" +
53155349
" <p ng-if=\"formParam[0].example\">\n" +
53165350
" <span class=\"raml-console-resource-param-example\"><b>Example:</b> {{formParam[0].example}}</span>\n" +
@@ -5352,7 +5386,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
53525386
" <h3 class=\"raml-console-resource-heading-a\">Status {{code}}</h3>\n" +
53535387
"\n" +
53545388
" <div class=\"raml-console-resource-response\">\n" +
5355-
" <p marked=\"methodInfo.responses[code].description\" opts=\"markedOptions\" class=\"raml-console-marked-content\"></p>\n" +
5389+
" <p markdown=\"methodInfo.responses[code].description\" class=\"raml-console-marked-content\"></p>\n" +
53565390
" </div>\n" +
53575391
"\n" +
53585392
" <div class=\"raml-console-resource-response\" ng-if=\"methodInfo.responses[code].headers\">\n" +
@@ -5361,7 +5395,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
53615395
" <div class=\"raml-console-resource-param\" ng-repeat=\"header in methodInfo.responses[code].headers\">\n" +
53625396
" <h4 class=\"raml-console-resource-param-heading\">{{header[0].displayName}} <span class=\"raml-console-resource-param-instructional\">{{header[0].type}}</span></h4>\n" +
53635397
"\n" +
5364-
" <p marked=\"header[0].description\" opts=\"markedOptions\" class=\"raml-console-marked-content\"></p>\n" +
5398+
" <p markdown=\"header[0].description\" class=\"raml-console-marked-content\"></p>\n" +
53655399
" </div>\n" +
53665400
" </div>\n" +
53675401
"\n" +
@@ -5427,7 +5461,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
54275461
" <span class=\"raml-console-sidebar-input-tooltip-container\" ng-if=\"param.definitions[0].description\" ng-class=\"{'raml-console-sidebar-input-tooltip-container-enum': param.definitions[0].enum}\">\n" +
54285462
" <button tabindex=\"-1\" class=\"raml-console-sidebar-input-tooltip\"><span class=\"raml-console-visuallyhidden\">Show documentation</span></button>\n" +
54295463
" <span class=\"raml-console-sidebar-tooltip-flyout\">\n" +
5430-
" <span marked=\"param.definitions[0].description\" opts=\"markedOptions\" class=\"raml-console-marked-content\"></span>\n" +
5464+
" <span markdown=\"param.definitions[0].description\" class=\"raml-console-marked-content\"></span>\n" +
54315465
" </span>\n" +
54325466
" </span>\n" +
54335467
"\n" +
@@ -5614,7 +5648,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
56145648
"\n" +
56155649
" <div class=\"raml-console-resource-panel raml-console-documentation-content\" ng-if=\"documentationEnabled\">\n" +
56165650
" <div class=\"raml-console-resource-panel-wrapper\">\n" +
5617-
" <div class=\"raml-console-documentation-section-content raml-console-marked-content\" marked=\"getDocumentationContent(doc.content, selectedDocumentSection)\" opts=\"markedOptions\"></div>\n" +
5651+
" <div class=\"raml-console-documentation-section-content raml-console-marked-content\" markdown=\"getDocumentationContent(doc.content, selectedDocumentSection)\"></div>\n" +
56185652
" </div>\n" +
56195653
" </div>\n" +
56205654
"\n" +
@@ -5721,7 +5755,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
57215755
" <span class=\"raml-console-sidebar-input-tooltip-container\" ng-if=\"param.definitions[0].description\">\n" +
57225756
" <button tabindex=\"-1\" class=\"raml-console-sidebar-input-tooltip\"><span class=\"raml-console-visuallyhidden\">Show documentation</span></button>\n" +
57235757
" <span class=\"raml-console-sidebar-tooltip-flyout\">\n" +
5724-
" <span marked=\"param.definitions[0].description\" opts=\"markedOptions\" class=\"raml-console-marked-content\"></span>\n" +
5758+
" <span markdown=\"param.definitions[0].description\" class=\"raml-console-marked-content\"></span>\n" +
57255759
" </span>\n" +
57265760
" </span>\n" +
57275761
"\n" +
@@ -5901,7 +5935,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
59015935
"\n" +
59025936
" <span ng-hide=\"methodInfo.is\" ng-if=\"resource.traits\" class=\"raml-console-flag raml-console-resource-heading-flag\"><b>Traits:</b> {{readResourceTraits(resource.traits)}}</span>\n" +
59035937
"\n" +
5904-
" <span class=\"raml-console-resource-level-description raml-console-marked-content\" marked=\"resource.description\" opts=\"markedOptions\"></span>\n" +
5938+
" <span class=\"raml-console-resource-level-description raml-console-marked-content\" markdown=\"resource.description\"></span>\n" +
59055939
"\n" +
59065940
" </div>\n" +
59075941
" <method-list></method-list>\n" +
@@ -5925,7 +5959,7 @@ angular.module('ramlConsoleApp').run(['$templateCache', function($templateCache)
59255959
"\n" +
59265960
" <span ng-hide=\"methodInfo.is\" ng-if=\"resource.traits\" class=\"raml-console-flag raml-console-resource-heading-flag\"><b>Traits:</b> {{readResourceTraits(resource.traits)}}</span>\n" +
59275961
"\n" +
5928-
" <span class=\"raml-console-resource-level-description raml-console-marked-content\" marked=\"resource.description\" opts=\"markedOptions\"></span>\n" +
5962+
" <span class=\"raml-console-resource-level-description raml-console-marked-content\" markdown=\"resource.description\"></span>\n" +
59295963
" </div>\n" +
59305964
"\n" +
59315965
" <method-list></method-list>\n" +

dist/scripts/api-console.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/app/app.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
'RAML.Security',
2020
'hc.marked',
2121
'ui.codemirror',
22-
'hljs'
22+
'hljs',
23+
'ngSanitize'
2324
]).config(['hljsServiceProvider', function (hljsServiceProvider) {
2425
hljsServiceProvider.setOptions({
2526
classPrefix: 'raml-console-hljs-'

0 commit comments

Comments
 (0)