Rust docs: Split up the preview from the syntax highlighting

The preview is now in sixtyfps-docs-preview.html and the highlighting in
sixtyfps-docs-highlight.html. This faciliates reusing the preview from
C++ while using a different HTML file later for syntax highlighting.

Relates to #282
Needed for #281
This commit is contained in:
Simon Hausmann 2021-07-07 13:44:33 +02:00
parent b1c680ca13
commit 77898796da
6 changed files with 45 additions and 45 deletions

View file

@ -305,7 +305,7 @@ jobs:
# allow deprecated warning because we are using nightly and some things might be deprecated in nightly
# for which the stable alternative is not yet available
RUSTFLAGS: -D warnings -W deprecated
RUSTDOCFLAGS: --html-in-header=/home/runner/work/sixtyfps/sixtyfps/api/sixtyfps-rs/sixtyfps-docs-integration.html -D warnings -W deprecated
RUSTDOCFLAGS: --html-in-header=/home/runner/work/sixtyfps/sixtyfps/api/sixtyfps-rs/sixtyfps-docs-preview.html --html-in-header=/home/runner/work/sixtyfps/sixtyfps/api/sixtyfps-rs/sixtyfps-docs-highlight.html -D warnings -W deprecated
SIXTYFPS_NO_QT: 1
CARGO_INCREMENTAL: false
MDBOOK_VERSION: 0.4.10

View file

@ -1,5 +1,5 @@
{% extends "!layout.html" %}
{% block scripts %}
{{ super() }}
{% include "../../../sixtyfps-rs/sixtyfps-docs-integration.html" %}
{% include "../../../sixtyfps-rs/sixtyfps-docs-preview.html" %}
{% endblock %}

View file

@ -31,4 +31,4 @@ pin-weak = "1"
rustc_version = "0.4"
[package.metadata.docs.rs]
rustdoc-args = [ "--html-in-header", "sixtyfps-docs-integration.html" ]
rustdoc-args = [ "--html-in-header", "sixtyfps-docs-preview.html", "--html-in-header", "sixtyfps-docs-highlight.html" ]

View file

@ -0,0 +1,40 @@
<!--
This file is used to add syntax highlighting of the `.60` snippets in the generated rustdoc documentation.
It can be injected via the `--html-in-header sixtyfps-docs-highlight.html` option of rustdoc.
-->
<link rel="stylesheet" href="https://sixtyfps.io/highlight-default.css">
<script src="https://sixtyfps.io/highlight.pack.js"></script>
<script src="https://sixtyfps.io/highlight_60.js"></script>
<script>
window.addEventListener("DOMContentLoaded", () => {
// Only highlight .60 blocks, leave the others to rustdoc
for (dot60Block of document.querySelectorAll("pre code.language-60")) {
hljs.highlightBlock(dot60Block)
}
// Some of the rustdoc selectors require the pre element to have the rust class
for (codeBlock of document.querySelectorAll(".language-60.hljs")) {
codeBlock.parentElement.classList.add("rust")
}
// Change the hljs generated classes to the rustdoc
// ones, so that the highlighting adjusts to the theme correctly.
const highlightJSToRustDoc = [
["comment", "comment"],
["number", "number"],
["symbol", "struct"], // width:
["keyword", "kw"],
["built_in", "primitive"],
["string", "string"],
["title", "fnname"], // Foo :=
["type", "type"]
];
for ([hljs_class, rustdoc_class] of highlightJSToRustDoc) {
for (titleElement of document.querySelectorAll(`.hljs-${hljs_class}`)) {
titleElement.classList.remove(`hljs-${hljs_class}`);
titleElement.classList.add(rustdoc_class);
}
}
});
</script>

View file

@ -1,6 +1,6 @@
<!--
This file is used to add preview of the `.60` snippets in the generated rustdoc documentation.
It can be injected via the `--html-in-header sixtyfps-docs-integration.html` option of rustdoc.
It can be injected via the `--html-in-header sixtyfps-docs-preview.html` option of rustdoc.
-->
<script type="module">
"use strict";
@ -58,44 +58,4 @@
}
fix_markdown_links()
</script>
<link rel="stylesheet" href="https://sixtyfps.io/highlight-default.css">
<script src="https://sixtyfps.io/highlight.pack.js"></script>
<script src="https://sixtyfps.io/highlight_60.js"></script>
<script>
// If we're running in rustdoc, change the hljs generated classes to the rustdoc
// ones, so that the highlighting adjusts to the theme correctly.
if (window.localStorage.getItem("rustdoc-theme") !== null) {
window.addEventListener("DOMContentLoaded", () => {
// Only highlight .60 blocks, leave the others to rustdoc
for (dot60Block of document.querySelectorAll("pre code.language-60")) {
hljs.highlightBlock(dot60Block)
}
// Some of the rustdoc selectors require the pre element to have the rust class
for (codeBlock of document.querySelectorAll(".language-60.hljs")) {
codeBlock.parentElement.classList.add("rust")
}
const highlightJSToRustDoc = [
["comment", "comment"],
["number", "number"],
["symbol", "struct"], // width:
["keyword", "kw"],
["built_in", "primitive"],
["string", "string"],
["title", "fnname"], // Foo :=
["type", "type"]
];
for ([hljs_class, rustdoc_class] of highlightJSToRustDoc) {
for (titleElement of document.querySelectorAll(`.hljs-${hljs_class}`)) {
titleElement.classList.remove(`hljs-${hljs_class}`);
titleElement.classList.add(rustdoc_class);
}
}
});
} else {
hljs.initHighlightingOnLoad();
}
</script>

View file

@ -125,7 +125,7 @@ html to the documentation with the `--html-in-header` rustdoc flag.
Here is how to build the documentation to include preview of the .60 files.
```sh
RUSTDOCFLAGS="--html-in-header=$PWD/api/sixtyfps-rs/sixtyfps-docs-integration.html" cargo +nightly doc --no-deps
RUSTDOCFLAGS="--html-in-header=$PWD/api/sixtyfps-rs/sixtyfps-docs-preview.html --html-in-header=$PWD/api/sixtyfps-rs/sixtyfps-docs-highlight.html" cargo +nightly doc --no-deps
```
### C++ doc