Skip to content

Commit 5dbb86a

Browse files
Merge pull request #613 from stephenplusplus/spp--docs-markdown-styling
docs: syntax highlight from markdown
2 parents 0ba8b88 + 79a525a commit 5dbb86a

4 files changed

Lines changed: 68 additions & 4 deletions

File tree

docs/authorization.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ With `gcloud-node` it's incredibly easy to get authorized and start using Google
44

55
If you are running this client on Google Compute Engine, we handle authorization for you with no configuration. You just need to make sure that when you [set up the GCE instance][gce-how-to], you add the correct scopes for the APIs you want to access.
66

7-
``` js
7+
```js hljs-class
88
var config = {
99
projectId: 'grape-spaceship-123'
1010
};
@@ -26,7 +26,7 @@ If you are not running this client on Google Compute Engine, you need a Google D
2626
* If you want to use a new service account, click on **Create new Client ID** and select **Service account**. After the account is created, you will be prompted to download the JSON key file that the library uses to authorize your requests.
2727
* If you want to generate a new key for an existing service account, click on **Generate new JSON key** and download the JSON key file.
2828

29-
``` js
29+
``` js hljs-class
3030
var config = {
3131
projectId: 'grape-spaceship-123',
3232
keyFilename: '/path/to/keyfile.json'

docs/site/components/authorization/authorization.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
<div subpage
1616
header-templateUrl="authorization-header.html"
1717
title="Authorization">
18-
<btf-markdown ng-include="'authorization.md'"></btf-markdown>
18+
<btf-markdown highlight-markdown ng-include="'authorization.md'"></btf-markdown>
1919
</div>

docs/site/components/subpage/subpage-directive.js

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
angular
2-
.module('gcloud.subpage', ['gcloud.header'])
2+
.module('gcloud.subpage', ['gcloud.header', 'hljs'])
3+
34
.directive('subpage', function($rootScope, $location, $http, $parse, getLinks, versions) {
45
'use strict';
56

@@ -34,4 +35,62 @@ angular
3435
}
3536
}
3637
};
38+
})
39+
40+
// A special class used in our MD files to tell the front end to syntax
41+
// highlight the code blocks.
42+
.directive('hljsClass', function() {
43+
'use strict';
44+
45+
return {
46+
// Concept borrowed from:
47+
// http://www.bennadel.com/blog/2748-compiling-transcluded-content-in-angularjs-directives.htm
48+
//
49+
// <div class="hljs-class">
50+
// var hi = 'there'; <!-- We want this!
51+
// </div>
52+
//
53+
// We want to replace that with:
54+
//
55+
// <div hljs language="javascript" source="var hi = 'there';"></div>
56+
//
57+
// To get the content we want, we have to use a higher priority than
58+
// another same-named directive that uses transclude. This is our only
59+
// chance to get it before it's clobbered.
60+
priority: 1500.1,
61+
restrict: 'C',
62+
compile: function(element, attrs) {
63+
attrs._contents = element.text();
64+
}
65+
};
66+
})
67+
68+
.directive('hljsClass', function() {
69+
'use strict';
70+
71+
return {
72+
priority: 1500,
73+
restrict: 'C',
74+
transclude: true,
75+
template: '<div hljs language="javascript" source="contents"></div>',
76+
compile: function(element) {
77+
return function($scope, element, attrs) {
78+
$scope.contents = attrs._contents;
79+
};
80+
}
81+
}
82+
})
83+
84+
// Re-compile the Markdown, this time having the "hljs-class" blocks picked
85+
// up.
86+
.directive('highlightMarkdown', function($compile) {
87+
'use strict';
88+
89+
return {
90+
link: function(scope, element, attrs) {
91+
scope.$watch(attrs.ngInclude, function() {
92+
$compile(element.contents())(scope);
93+
}, true);
94+
}
95+
};
3796
});

docs/site/css/main.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ pre {
141141
line-height: 1.6em;
142142
}
143143

144+
[hljs] > pre {
145+
margin: 0 !important;
146+
font-size: 1em;
147+
}
148+
144149
pre,
145150
code {
146151
font-family: Monaco, 'Droid Sans Mono', monospace !important;

0 commit comments

Comments
 (0)