Skip to content

Commit c3ed5b5

Browse files
committed
Website: Auto-generate example header with component title, list of aliases and dependencies.
`overrideExampleHeader` can be used to generate only the component title.
1 parent 6861259 commit c3ed5b5

File tree

139 files changed

+57
-437
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+57
-437
lines changed

components.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var components = {
4444
},
4545
"markup": {
4646
"title": "Markup",
47+
"alias": ["html", "xml", "svg", "mathml"],
4748
"aliasTitles": {
4849
"html": "HTML",
4950
"xml": "XML",
@@ -58,12 +59,14 @@ var components = {
5859
},
5960
"clike": {
6061
"title": "C-like",
61-
"option": "default"
62+
"option": "default",
63+
"overrideExampleHeader": true
6264
},
6365
"javascript": {
6466
"title": "JavaScript",
65-
"option": "default",
66-
"require": "clike"
67+
"require": "clike",
68+
"alias": "js",
69+
"option": "default"
6770
},
6871
"abap": {
6972
"title": "ABAP",
@@ -130,6 +133,7 @@ var components = {
130133
},
131134
"batch": {
132135
"title": "Batch",
136+
"alias": "shell",
133137
"owner": "Golmote"
134138
},
135139
"bison": {
@@ -153,6 +157,7 @@ var components = {
153157
"csharp": {
154158
"title": "C#",
155159
"require": "clike",
160+
"alias": "dotnet",
156161
"owner": "mvalipour"
157162
},
158163
"cpp": {
@@ -200,6 +205,7 @@ var components = {
200205
"django": {
201206
"title": "Django/Jinja2",
202207
"require": "markup",
208+
"alias": "jinja2",
203209
"owner": "romanvm"
204210
},
205211
"docker": {
@@ -433,6 +439,7 @@ var components = {
433439
"opencl": {
434440
"title": "OpenCL",
435441
"require": "cpp",
442+
"overrideExampleHeader": true,
436443
"owner": "Milania1"
437444
},
438445
"oz": {
@@ -506,7 +513,7 @@ var components = {
506513
"owner": "multipetros"
507514
},
508515
"q": {
509-
"title": "Q",
516+
"title": "Q (kdb+ database)",
510517
"owner": "Golmote"
511518
},
512519
"qore": {
@@ -619,6 +626,7 @@ var components = {
619626
"typescript": {
620627
"title": "TypeScript",
621628
"require": "javascript",
629+
"alias": "ts",
622630
"owner": "vkbansal"
623631
},
624632
"vbnet": {

examples.js

+37-1
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,50 @@ function getFileContents(filepath) {
104104
});
105105
}
106106

107+
function buildContentsHeader(id) {
108+
var language = languages[id];
109+
var header = '<h1>' + language.title + '</h1>';
110+
if (language.overrideExampleHeader) {
111+
return header;
112+
}
113+
if (language.alias) {
114+
var alias = language.alias;
115+
if (Prism.util.type(alias) !== 'Array') {
116+
alias = [alias];
117+
}
118+
119+
header += '<p>To use this language, use one of the following classes:</p>';
120+
header += '<ul><li><code class="language-none">"language-' + id + '"</code></li>';
121+
alias.forEach(function (alias) {
122+
header += '<li><code class="language-none">"language-' + alias + '"</code></li>';
123+
});
124+
header += '</ul>';
125+
} else {
126+
header += '<p>To use this language, use the class <code class="language-none">"language-' + id + '"</code>.</p>';
127+
}
128+
if (language.require) {
129+
var require = language.require;
130+
if (Prism.util.type(require) !== 'Array') {
131+
require = [require];
132+
}
133+
134+
header += '<p><strong>Dependencies:</strong> The following dependencies need to be loaded before this component: ';
135+
header += require.map(function (dep) {
136+
return '<code class="language-none">' + dep + '</code>';
137+
}).join(', ');
138+
header += '.</p>';
139+
}
140+
return header;
141+
}
142+
107143
function update(id) {
108144
var language = languages[id];
109145
if (language.enabled) {
110146
if (!language.examplesPromise) {
111147
language.examplesPromise = getFileContents(language.examplesPath);
112148
}
113149
language.examplesPromise.then(function (contents) {
114-
examples[id].innerHTML = contents;
150+
examples[id].innerHTML = buildContentsHeader(id) + contents;
115151

116152
loadLanguage(id).then(function () {
117153
var elements = examples[id].querySelectorAll('code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code');

examples/prism-abap.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>ABAP</h1>
2-
<p>To use this language, use the class "language-abap".</p>
3-
41
<h2>Comments</h2>
52
<pre><code>
63
* Line Comments

examples/prism-actionscript.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>ActionScript</h1>
2-
<p>To use this language, use the class "language-actionscript".</p>
3-
41
<h2>Comments</h2>
52
<pre><code>// Single line comment
63
/* Multi-line

examples/prism-ada.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>Ada</h1>
2-
<p>To use this language, use the class "language-ada".</p>
3-
41
<h2>Strings</h2>
52
<pre><code>"foo ""bar"" baz"
63
"Multi-line strings are appended with a " &

examples/prism-apacheconf.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>Apache Configuration</h1>
2-
<p>To use this language, use the class "language-apacheconf".</p>
3-
41
<h2>Comments</h2>
52
<pre><code># This is a comment
63
# &lt;VirtualHost *:80>

examples/prism-apl.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>APL</h1>
2-
<p>To use this language, use the class "language-apl".</p>
3-
41
<h2>Comments</h2>
52
<pre><code>#!/usr/bin/env runapl
63
a←1 2 3 ⍝ this is a comment</code></pre>

examples/prism-applescript.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>AppleScript</h1>
2-
<p>To use this language, use the class "language-applescript".</p>
3-
41
<h2>Comments</h2>
52
<pre><code>-- Single line comment
63
#!/usr/bin/osascript

examples/prism-arduino.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>Arduino</h1>
2-
<p>To use this language, use the class "language-arduino".</p>
3-
41
<h2>Strings</h2>
52
<pre><code>"foo \"bar\" baz"
63
'foo \'bar\' baz'

examples/prism-arff.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>ARFF</h1>
2-
<p>To use this language, use the class "language-arff".</p>
3-
41
<h2>Comments</h2>
52
<pre><code>%
63
% Some comments

examples/prism-asciidoc.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>AsciiDoc</h1>
2-
<p>To use this language, use the class "language-asciidoc".</p>
3-
41
<h2>Comments</h2>
52
<pre><code>/////
63
Comment block

examples/prism-asm6502.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>6502 Assembly</h1>
2-
<p>To use this language, use the class "language-asm6502".</p>
3-
41
<h2>Comments</h2>
52
<pre><code>; This is a comment</code></pre>
63

examples/prism-aspnet.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>ASP.NET (C#)</h1>
2-
<p>To use this language, use the class "language-aspnet".</p>
3-
41
<h2>Comments</h2>
52
<pre><code><%-- This is a comment --%>
63
<%-- This is a

examples/prism-autohotkey.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>AutoHotkey</h1>
2-
<p>To use this language, use the class "language-autohotkey".</p>
3-
41
<h2>Comments</h2>
52
<pre><code>; This is a comment</code></pre>
63

examples/prism-autoit.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>AutoIt</h1>
2-
<p>To use this language, use the class "language-autoit".</p>
3-
41
<h2>Comments</h2>
52
<pre><code>; Single-line comment
63
#comments-start

examples/prism-bash.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>Bash</h1>
2-
<p>To use this language, use the class "language-bash".</p>
3-
41
<h2>Shebang</h2>
52
<pre><code>#!/bin/bash</code></pre>
63

examples/prism-basic.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>BASIC</h1>
2-
<p>To use this language, use the class "language-basic".</p>
3-
41
<p>Note: this component focuses on first and second-generation BASICs (such as MSX BASIC, GW-BASIC, SuperBASIC, QuickBASIC, PowerBASIC...).</p>
52

63
<h2>Comments</h2>

examples/prism-batch.html

-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
<h1>Batch</h1>
2-
<p>To use this language, use one of the following classes:</p>
3-
<ul>
4-
<li>"language-batch"</li>
5-
<li>"language-shell"</li>
6-
</ul>
7-
81
<h2>Comments</h2>
92
<pre><code>::
103
:: Foo bar

examples/prism-bison.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>Bison</h1>
2-
<p>To use this language, use the class "language-bison".</p>
3-
41
<h2>Comments</h2>
52
<pre><code>// Single-line comment
63
/* Multi-line

examples/prism-brainfuck.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>Brainfuck</h1>
2-
<p>To use this language, use the class "language-brainfuck".</p>
3-
41
<h2>Full example</h2>
52
<pre><code>+++++ +++ Set Cell #0 to 8
63
[

examples/prism-bro.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>Bro</h1>
2-
<p>To use this language, use the class "language-bro".</p>
3-
41
<h2>Comments</h2>
52
<pre><code># Single line comment
63
</code></pre>

examples/prism-c.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>C</h1>
2-
<p>To use this language, use the class "language-c".</p>
3-
41
<h2>Strings</h2>
52
<pre><code>"foo \"bar\" baz"
63
'foo \'bar\' baz'

examples/prism-clike.html

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
<h1>C-like</h1>
21
<p>The C-like component is not really a language on its own,
32
it is the basis of many other components. To use it directly, however,
4-
use the class "language-clike".</p>
3+
use the class <code class="language-none">"language-clike"</code>.</p>
54

65
<h2>Comments</h2>
76
<pre><code>// Single line comment

examples/prism-clojure.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>Clojure</h1>
2-
<p>To use this language, use the class "language-clojure".</p>
3-
41
<h2>Full example</h2>
52
<pre><code>
63
; This code is copied from https://learnxinyminutes.com/docs/clojure/

examples/prism-coffeescript.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>CoffeeScript</h1>
2-
<p>To use this language, use the class "language-coffeescript".</p>
3-
41
<h2>Comments</h2>
52
<pre><code># This is a comment
63
### This is a

examples/prism-cpp.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>C++</h1>
2-
<p>To use this language, use the class "language-cpp".</p>
3-
41
<h2>Strings</h2>
52
<pre><code>"foo \"bar\" baz"
63
'foo \'bar\' baz'

examples/prism-crystal.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>Crystal</h1>
2-
<p>To use this language, use the class "language-crystal".</p>
3-
41
<h2>Number literals with underscores and postfix</h2>
52
<pre><code>1_u32
63
123_456.789e-10_f64</code></pre>

examples/prism-csharp.html

-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
<h1>C#</h1>
2-
<p>To use this language, use one of the following classes:</p>
3-
<ul>
4-
<li>"language-csharp"</li>
5-
<li>"language-dotnet"</li>
6-
</ul>
7-
81
<h2>Comments</h2>
92
<pre><code>// Single line comment
103
/* Multi-line

examples/prism-csp.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>HTTP Content-Security-Policy header value</h1>
2-
<p>To use this language, use the class "language-csp".</p>
3-
41
<h2>A complete policy</h2>
52
<pre><code>default-src 'none';
63
script-src my.cdn.com;

examples/prism-css.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>CSS</h1>
2-
<p>To use this language, use the class "language-css".</p>
3-
41
<h2>Empty rule</h2>
52
<pre><code>*{} * {} p {}</code></pre>
63
<pre><code>ul,

examples/prism-d.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>D</h1>
2-
<p>To use this language, use the class "language-d".</p>
3-
41
<h2>Comments</h2>
52
<pre><code>// Single line comment
63
/* Multi-line

examples/prism-dart.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>Dart</h1>
2-
<p>To use this language, use the class "language-dart".</p>
3-
41
<h2>Comments</h2>
52
<pre><code>// Single line comment
63
/// Documentation single line comment

examples/prism-diff.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>Diff</h1>
2-
<p>To use this language, use the class "language-diff".</p>
3-
41
<h2>Normal Diff</h2>
52
<pre><code>7c7
63
&lt; qt: core

examples/prism-django.html

-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
<h1>Django/Jinja2</h1>
2-
<p>To use this language, use one of the following classes:</p>
3-
<ul>
4-
<li>"language-django"</li>
5-
<li>"language-jinja2"</li>
6-
</ul>
7-
81
<h2>Comment</h2>
92
<pre><code>{# This is a comment #}</code></pre>
103

examples/prism-docker.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>Docker</h1>
2-
<p>To use this language, use the class "language-docker".</p>
3-
41
<h2>Comments</h2>
52
<pre><code># These are the comments for a dockerfile.
63
# I want to make sure $(variables) don't break out,

examples/prism-eiffel.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>Eiffel</h1>
2-
<p>To use this language, use the class "language-eiffel".</p>
3-
41
<h2>Comments</h2>
52
<pre><code>-- A comment
63
</code></pre>

examples/prism-elixir.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>Elixir</h1>
2-
<p>To use this language, use the class "language-elixir".</p>
3-
41
<h2>Comments</h2>
52
<pre><code># This is a comment</code></pre>
63

examples/prism-elm.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>Elm</h1>
2-
<p>To user this language, use the class "language-elm".</p>
3-
41
<h2>Comments</h2>
52
<pre><code>-- Single line comment
63
{- Multi-line

examples/prism-erlang.html

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
<h1>Erlang</h1>
2-
<p>To use this language, use the class "language-erlang".</p>
3-
41
<h2>Comments</h2>
52
<pre><code>% This is a comment
63
%% coding: utf-8</code></pre>

0 commit comments

Comments
 (0)