-
Notifications
You must be signed in to change notification settings - Fork 1
/
render-webidl.sh
executable file
·105 lines (88 loc) · 1.84 KB
/
render-webidl.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
# Copyright 2022 British Broadcasting Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -o errexit
if [ "$1" == "-n" ]; then
SHOW_LINE_NUMBERS=true
shift
else
SHOW_LINE_NUMBERS=false
fi
WEBIDL_FILE=$1
NAME=$2
ALT_HREF=$3
ALT_TEXT=$4
RAW_HREF=$5
RAW_TEXT=$6
LINT=: # return true
cat <<EOF
---
layout: default
title: $NAME
---
<html>
<meta charset="UTF-8">
<h2>$NAME</h2>
EOF
if [ "$ALT_HREF" ]; then
cat <<EOF
<p>
<a href="$ALT_HREF">$ALT_TEXT</a>
</p>
EOF
fi
if [ "$RAW_HREF" ]; then
cat <<EOF
<p>
<a href="$RAW_HREF">$RAW_TEXT</a>
</p>
EOF
fi
cat <<EOF
<div id="json-render">
EOF
if $LINT "$WEBIDL_FILE" ; then
cat <<-EOF
<script type="text/javascript" src="codemirror/lib/codemirror.js"></script>
<link rel="stylesheet" href="codemirror/lib/codemirror.css">
<script src="codemirror/mode/webidl/webidl.js"></script>
<style>
.CodeMirror {
border-top: 1px solid black;
border-bottom: 1px solid black;
height: 500px;
}
</style>
<textarea id="mytextarea">
EOF
cat "$WEBIDL_FILE"
cat <<-EOF
</textarea>
<script>
window.editor_json = CodeMirror.fromTextArea(mytextarea, {
lineNumbers: $SHOW_LINE_NUMBERS,
matchBrackets: true
}
);
</script>
EOF
else # Failed lint so do minimal render
echo "<pre>"
cat "$WEBIDL_FILE"
echo "</pre>"
fi
cat <<-EOF
</div>
</html>
EOF