Skip to content

Commit bbbd0a5

Browse files
committed
Adjust HTML Docs
- Section IDs, with handy anchor links - Multiple filters for levels - Table rendering, block quote size - Nicer loading (hide un-rendered content) - Code highlighting (only for Rust, of course!) - Fix parsing of descriptions that have a newline after the section title (lead to duplicating the title, e.g., "Examples", in the content)
1 parent ba9eda7 commit bbbd0a5

File tree

2 files changed

+111
-66
lines changed

2 files changed

+111
-66
lines changed

util/export.py

100644100755
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,17 @@ def parseLintDef(level, comment, name):
5252
match = re.match(lint_subheadline, line)
5353
if match:
5454
last_section = match.groups()[0]
55-
text = match and match.groups()[1] or line
56-
55+
if match:
56+
text = match.groups()[1]
57+
else:
58+
text = line
59+
5760
if not last_section:
5861
warn("Skipping comment line as it was not preceded by a heading")
5962
debug("in lint `%s`, line `%s`" % name, line)
6063

61-
lint['docs'][last_section] = (lint['docs'].get(last_section, "") + "\n" + text).strip()
62-
64+
lint['docs'][last_section] = (lint['docs'].get(last_section, "") + "\n" + text).strip()
65+
6366
return lint
6467

6568
def parse_file(d, f):
@@ -124,4 +127,4 @@ def main():
124127
info("wrote JSON for great justice")
125128

126129
if __name__ == "__main__":
127-
main()
130+
main()

util/gh-pages/index.html

Lines changed: 103 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,141 @@
11
<!DOCTYPE html>
22
<html lang="en">
33
<head>
4-
<meta charset="UTF-8">
4+
<meta charset="UTF-8"/>
5+
<meta name="viewport" content="width=device-width, initial-scale=1"/>
6+
57
<title>Clippy</title>
68

7-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.1/css/bootstrap.min.css"/>
8-
<meta name="viewport" content="width=device-width, initial-scale=1"/>
9+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css"/>
10+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/styles/github.min.css"/>
11+
<style>
12+
blockquote { font-size: 1em; }
13+
[ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak { display: none !important; }
14+
.panel .anchor { display: none; }
15+
.panel:hover .anchor { display: inline; color: #fff; }
16+
</style>
917
</head>
1018
<body>
1119
<div class="container" ng-app="clippy" ng-controller="lintList">
1220
<div class="page-header">
1321
<h1>ALL the Clippy Lints</h1>
1422
</div>
1523

16-
<div class="alert alert-info" role="alert" ng-if="loading">
17-
Loading&#x2026;
18-
</div>
19-
<div class="alert alert-danger" role="alert" ng-if="error">
20-
Error loading commits!
21-
</div>
24+
<noscript>
25+
<div class="alert alert-danger" role="alert">
26+
Sorry, this site only works with JavaScript!
27+
</div>
28+
</noscript>
2229

23-
<div class="panel panel-default" ng-show="data">
24-
<div class="panel-body row">
25-
<div class="col-md-6 form-inline">
26-
<div class="form-group">
27-
<label for="filter-level">Level</label>
28-
<select class="form-control" id="filter-level" ng-model="level.level">
29-
<option value="">All</option>
30-
<option value="Allow">Allow</option>
31-
<option value="Warn">Warn</option>
32-
<option value="Deny">Deny</option>
33-
</select>
30+
<div ng-cloak>
31+
32+
<div class="alert alert-info" role="alert" ng-if="loading">
33+
Loading&#x2026;
34+
</div>
35+
<div class="alert alert-danger" role="alert" ng-if="error">
36+
Error loading lints!
37+
</div>
38+
39+
<div class="panel panel-default" ng-show="data">
40+
<div class="panel-body row">
41+
<div class="col-md-6 form-inline">
42+
<div class="form-group form-group-lg">
43+
<div class="checkbox" ng-repeat="(level, enabled) in levels" style="margin-right: 0.6em">
44+
<label>
45+
<input type="checkbox" ng-model="levels[level]" />
46+
{{level}}
47+
</label>
48+
</div>
49+
</div>
3450
</div>
35-
</div>
36-
<div class="col-md-6">
37-
<div class="input-group">
38-
<span class="input-group-addon" id="filter-label">Filter:</span>
39-
<input type="text" class="form-control" placeholder="Keywords or search string" aria-describedby="filter-label" ng-model="search" />
40-
<span class="input-group-btn">
41-
<button class="btn btn-default" type="button" ng-click="search = ''">
42-
Clear
43-
</button>
44-
</span>
51+
<div class="col-md-6">
52+
<div class="input-group">
53+
<span class="input-group-addon" id="filter-label">Filter:</span>
54+
<input type="text" class="form-control" placeholder="Keywords or search string" aria-describedby="filter-label" ng-model="search" />
55+
<span class="input-group-btn">
56+
<button class="btn btn-default" type="button" ng-click="search = ''">
57+
Clear
58+
</button>
59+
</span>
60+
</div>
4561
</div>
4662
</div>
4763
</div>
48-
</div>
4964

50-
<article class="panel panel-default" ng-repeat="lint in data | filter:level | filter:search | orderBy:'id' track by lint.id">
51-
<header class="panel-heading" ng-click="open[lint.id] = !open[lint.id]">
52-
<button class="btn btn-default btn-sm pull-right" style="margin-top: -6px;">
53-
<span ng-show="open[lint.id]">&minus;</span>
54-
<span ng-hide="open[lint.id]">&plus;</span>
55-
</button>
56-
57-
<h2 class="panel-title">
58-
{{lint.id}}
59-
<span ng-if="lint.level == 'Allow'" class="label label-info">Allow</span>
60-
<span ng-if="lint.level == 'Warn'" class="label label-warning">Warn</span>
61-
<span ng-if="lint.level == 'Deny'" class="label label-danger">Deny</span>
62-
</h2>
63-
</header>
64-
65-
<ul class="list-group" ng-if="lint.docs" ng-class="{collapse: true, in: open[lint.id]}">
66-
<li class="list-group-item" ng-repeat="(title, text) in lint.docs">
67-
<h4 class="list-group-item-heading">
68-
{{title}}
69-
</h4>
70-
<div class="list-group-item-text" ng-bind-html="text | markdown"></div>
71-
</li>
72-
</ul>
73-
</article>
65+
<article class="panel panel-default" id="{{lint.id}}" ng-repeat="lint in data | filter:byLevels | filter:search | orderBy:'id' track by lint.id">
66+
<header class="panel-heading" ng-click="open[lint.id] = !open[lint.id]">
67+
<button class="btn btn-default btn-sm pull-right" style="margin-top: -6px;">
68+
<span ng-show="open[lint.id]">&minus;</span>
69+
<span ng-hide="open[lint.id]">&plus;</span>
70+
</button>
71+
72+
<h2 class="panel-title">
73+
{{lint.id}}
74+
75+
<span ng-if="lint.level == 'Allow'" class="label label-info">Allow</span>
76+
<span ng-if="lint.level == 'Warn'" class="label label-warning">Warn</span>
77+
<span ng-if="lint.level == 'Deny'" class="label label-danger">Deny</span>
78+
79+
<a href="#{{lint.id}}" class="anchor label label-default">&para;</a>
80+
</h2>
81+
</header>
82+
83+
<ul class="list-group" ng-if="lint.docs" ng-class="{collapse: true, in: open[lint.id]}">
84+
<li class="list-group-item" ng-repeat="(title, text) in lint.docs">
85+
<h4 class="list-group-item-heading">
86+
{{title}}
87+
</h4>
88+
<div class="list-group-item-text" ng-bind-html="text | markdown"></div>
89+
</li>
90+
</ul>
91+
</article>
92+
</div>
7493
</div>
7594

7695
<a href="https://github.com/Manishearth/rust-clippy">
7796
<img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"/>
7897
</a>
7998

80-
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.2/marked.min.js"></script>
99+
<script src="https://cdnjs.cloudflare.com/ajax/libs/markdown-it/7.0.0/markdown-it.min.js"></script>
100+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/highlight.min.js"></script>
101+
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/languages/rust.min.js"></script>
81102
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.12/angular.min.js"></script>
82103
<script>
83104
(function () {
105+
var md = window.markdownit({
106+
html: true,
107+
linkify: true,
108+
typographer: true,
109+
highlight: function (str, lang) {
110+
if (lang && hljs.getLanguage(lang)) {
111+
try {
112+
return '<pre class="hljs"><code>' +
113+
hljs.highlight(lang, str, true).value +
114+
'</code></pre>';
115+
} catch (__) {}
116+
}
117+
118+
return '<pre class="hljs"><code>' + md.utils.escapeHtml(str) + '</code></pre>';
119+
}
120+
});
121+
84122
angular.module("clippy", [])
85123
.filter('markdown', function ($sce) {
86124
return function (text) {
87-
if (typeof text !== 'string') {
88-
text = ''
89-
};
90-
91125
return $sce.trustAsHtml(
92-
marked(text)
126+
md.render(text || '')
127+
// Oh deer, what a hack :O
128+
.replace('<table', '<table class="table"')
93129
);
94130
};
95131
})
96132
.controller("lintList", function ($scope, $http) {
133+
// Level filter
134+
$scope.levels = {Allow: true, Warn: true, Deny: true};
135+
$scope.byLevels = function (lint) {
136+
return $scope.levels[lint.level];
137+
};
138+
97139
// Get data
98140
$scope.open = {};
99141
$scope.loading = true;

0 commit comments

Comments
 (0)