Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docs): generate single-page doc from wiki #94

Merged
merged 76 commits into from Jul 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
cfd2f5a
feat(docs): generate single-page doc from wiki
sidvishnoi Jun 23, 2020
7a2edbb
better responsive images
sidvishnoi Jun 23, 2020
00676f4
add more wikis, fix special section id behaviour
sidvishnoi Jun 23, 2020
c39ea79
add .advisement if line contains warning
sidvishnoi Jun 23, 2020
886fb6c
edit link sends to _edit page on wiki
sidvishnoi Jun 23, 2020
c997266
add .def on table and dl
sidvishnoi Jun 23, 2020
5038a3d
add .note if line contains 'Note:'
sidvishnoi Jun 23, 2020
cf1013c
improve logic for searching Note and Warning
sidvishnoi Jun 23, 2020
fc336b4
add separate docs for noTOC and .notoc
sidvishnoi Jun 23, 2020
3a3f1b6
avoid adding .def to .head dl
sidvishnoi Jun 23, 2020
a05d9c9
change code highlight color in ToC
sidvishnoi Jun 23, 2020
566ac9e
Merge branch 'gh-pages' into docs
sidvishnoi Jun 30, 2020
7219c3f
use w3.org hosted respec
sidvishnoi Jun 30, 2020
0013290
fix no-link-warnings include link
sidvishnoi Jun 30, 2020
c42e219
support including links containing fragments
sidvishnoi Jun 30, 2020
e1464fd
do not remove section numbers from meh headings
sidvishnoi Jun 30, 2020
3750349
limit ToC depth per section
sidvishnoi Jun 30, 2020
8b8a607
automate minimum data-max-toc
sidvishnoi Jun 30, 2020
0b8505e
no need to remove things from ToC now :tada:
sidvishnoi Jun 30, 2020
a1d4521
add links to edit docs in header
sidvishnoi Jun 30, 2020
ecf799a
Add 'Getting Started' guide
sidvishnoi Jun 30, 2020
941db04
add github links
sidvishnoi Jun 30, 2020
b3f199f
add abstract
sidvishnoi Jun 30, 2020
c86e8e6
escape [[foo]]
sidvishnoi Jun 30, 2020
acbce57
add style for <kbd>
sidvishnoi Jun 30, 2020
9b16b7e
add webidl-guide
sidvishnoi Jun 30, 2020
b66c646
fix escaping [[foo]] and [[[foo]]]
sidvishnoi Jul 1, 2020
65d0601
allow linking to renamed data-include
sidvishnoi Jul 1, 2020
22abe86
fix: allow editing Editor's Guide also
sidvishnoi Jul 1, 2020
00167db
lets add one more level to ToC for Getting Started
sidvishnoi Jul 1, 2020
fe469fa
Add some more wiki pages
sidvishnoi Jul 1, 2020
470cd6b
update data-max-toc usage
sidvishnoi Jul 2, 2020
9cc4503
add a respec logo
sidvishnoi Jul 2, 2020
ba1112a
add static snapshots' guide
sidvishnoi Jul 2, 2020
84bbf5d
use better markdown processing from upstream
sidvishnoi Jul 6, 2020
ffac3c2
add markdown guide
sidvishnoi Jul 6, 2020
215841b
add html attributes section
sidvishnoi Jul 6, 2020
ecdd22e
fix(fixLinks): skip mailto: links
sidvishnoi Jul 6, 2020
ab7fb4f
add wiki links to nested sections also
sidvishnoi Jul 6, 2020
210f8b7
cleanup in postProcess
sidvishnoi Jul 6, 2020
97987d1
use respec default styles for code blocks
sidvishnoi Jul 6, 2020
6e3df19
reduce markdown guide toc depth
sidvishnoi Jul 7, 2020
9b89302
add gh-contributors
sidvishnoi Jul 7, 2020
b0bbd5b
Add data-max-toc
sidvishnoi Jul 7, 2020
a09b806
human sort html attributes
sidvishnoi Jul 7, 2020
71de693
escape [=term=] and {{term}} to avoiding linking
sidvishnoi Jul 8, 2020
efa3a9d
enable check-punctuation lint rule
sidvishnoi Jul 8, 2020
9082395
add removeOnSave
sidvishnoi Jul 8, 2020
d58b989
add shorthands guide
sidvishnoi Jul 8, 2020
2aa8529
improve escaping in tables, and for | pipes
sidvishnoi Jul 8, 2020
46e95c5
better escape |
sidvishnoi Jul 8, 2020
ec96b3d
cleanup a little
sidvishnoi Jul 8, 2020
a004bb3
use better data-include from upstream
sidvishnoi Jul 9, 2020
43bbba6
run src.html through tidy
sidvishnoi Jul 9, 2020
f7d892b
now we need less custom processing on includes
sidvishnoi Jul 9, 2020
2e70e29
cleanup: unescape |var| properly
sidvishnoi Jul 9, 2020
bd32841
fix: process markdown in notes and warnings
sidvishnoi Jul 9, 2020
f65ac68
use string.replaceAll, nits
sidvishnoi Jul 9, 2020
3349c86
nits
sidvishnoi Jul 9, 2020
7549e91
more nits and cleanup
sidvishnoi Jul 9, 2020
545fc5b
styles: add background to pre not part of example
sidvishnoi Jul 9, 2020
0dd3fe5
nit: fixIncludes
sidvishnoi Jul 9, 2020
99abbd2
Revert "add a respec logo"
sidvishnoi Jul 9, 2020
87172be
add proper canonicalURI
sidvishnoi Jul 9, 2020
30cdf29
Merge branch 'gh-pages' into docs
sidvishnoi Jul 10, 2020
a3af798
use respec-w3c from w3.org
sidvishnoi Jul 10, 2020
4d61dbf
nit: whitespace in comment
sidvishnoi Jul 10, 2020
554420a
remove aria-busy
sidvishnoi Jul 10, 2020
e920597
inline respecConfig in HTML
sidvishnoi Jul 10, 2020
f8cffc1
can't use string.replaceAll yet
sidvishnoi Jul 10, 2020
556ca44
do not remove copyright
sidvishnoi Jul 13, 2020
0c71b58
use cc0 license
sidvishnoi Jul 13, 2020
c3372d7
defer respec script
sidvishnoi Jul 13, 2020
60da3f7
fix fixLinks in exported doc
sidvishnoi Jul 13, 2020
2d4ba07
fix: support file uploads to spec-generator
sidvishnoi Jul 13, 2020
f4b6b19
fix WebIDL guide include
sidvishnoi Jul 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions .gitignore
@@ -1,7 +1,8 @@
.DS_Store
.env
.vscode
node_modules
data
ecosystem.config.js
node_modules
public/
data
.env
static/docs/index.html
359 changes: 359 additions & 0 deletions static/docs/src.html
@@ -0,0 +1,359 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>
ReSpec Documentation
</title>
<script src="https://www.w3.org/Tools/respec/respec-w3c" class="remove"
defer></script>
<script class="remove">
var respecConfig = {
edDraftURI: null,
editors: [
{
name: "ReSpec",
url: "https://github.com/w3c/respec",
},
],
license: "cc0",
lint: {
"no-http-props": false,
"check-punctuation": true,
},
preProcess: [addSectionIds, fixIncludes],
postProcess: [
fixLinks,
addWikiLinks,
fixMarkupPostprocess,
postProcessEnhance,
cleanup,
],
canonicalURI: "https://respec.org/docs/",
github: "w3c/respec",
otherLinks: [
{
key: "Edit this documentation",
data: [
{
value: "GitHub Wiki",
href: "https://github.com/w3c/respec/wiki",
},
{
value: "Single Page",
href:
"https://github.com/marcoscaceres/respec.org/tree/HEAD/static/docs",
},
],
},
],
};

function addSectionIds() {
const sections = document.querySelectorAll("section[data-include]:not([id])");
for (const section of sections) {
section.id = section.dataset.include;
}
}

function fixIncludes() {
for (const section of document.querySelectorAll("section[data-include]")) {
const { include } = section.dataset;
Object.assign(section.dataset, {
includeName: include,
includeFormat: "markdown",
oninclude: "fixMarkupOnInclude",
include: `https://raw.githubusercontent.com/wiki/w3c/respec/${include}.md`,
});
if (!section.hasAttribute("data-max-toc")) {
section.dataset.maxToc = section.querySelector("section") ? "2" : "1";
}
}
}

/**
* @param {*} _
* @param {string} content
*/
function fixMarkupOnInclude(_, content) {
const ZERO_WIDTH_SPACE = "&#8203;";
// Escape [[[foo]]] and [[foo]] by adding zero-width space. We remove these
// extraneous characters in postProcess, so users don't end up copy pasting
// them. Ugly, but other way is upstream changes for an extreme edge case.
content = content
.replace(/\[\[/g, `[${ZERO_WIDTH_SPACE}[${ZERO_WIDTH_SPACE}`)
// Similarly for [= term =], {{ term }}, [^elem^]
.replace(/\[=/g, `[${ZERO_WIDTH_SPACE}=`)
.replace(/{{/g, `{${ZERO_WIDTH_SPACE}{`)
.replace(/\[\^/g, `[${ZERO_WIDTH_SPACE}^`)
// and also escape | used for inline variables
.replace(/\`\\\|(\w+)/g, `\`\\|${ZERO_WIDTH_SPACE}$1`)
.replace(/(\w+)\\\|\`/g, `$1${ZERO_WIDTH_SPACE}\\|\``)
.replace(/\`\|(\w+)/g, `\`\\|${ZERO_WIDTH_SPACE}$1`)
.replace(/(\w+)\|\`/g, `$1${ZERO_WIDTH_SPACE}\\|\``);

// Add .note and .advisement classes based on line prefix
content = content
.split("\n")
.map(line => {
if (/^.{0,5}\s*Warning:/.test(line))
return `<div class="advisement">\n\n${line}</div>`;
if (/^.{0,5}\s*Note:/.test(line))
return `<div class="note">\n\n${line}</div>`;
return line;
})
.join("\n");

return content;
}

function fixMarkupPostprocess() {
for (const elem of document.querySelectorAll("code")) {
if (elem.innerHTML.includes("&amp;#8203;")) {
elem.innerHTML = elem.innerHTML.replace(/&amp;#8203;/g, "");
}
if (elem.innerHTML.includes("\\|")) {
elem.innerHTML = elem.innerHTML.replace(/\\\|/g, "|");
}
}
}

function postProcessEnhance() {
for (const elem of document.querySelectorAll("section dl, table")) {
elem.classList.add("def");
}
}

function fixLinks() {
/** @type {NodeListOf<HTMLAnchorElement>} */
const anchors = document.querySelectorAll(
"section a:not([href^=http]):not([href^='mailto:']):not([href^='#'])",
);
for (const a of anchors) {
const href = a.hash ? a.hash.slice(1) : a.pathname.split("/").pop();
if (document.getElementById(href)) {
a.href = `#${href}`;
} else if (document.getElementById(`id-${href}`)) {
// Special section IDs like "conformance" trigger ReSpec's "include"
// behaviour. We manually add `id-` prefix to overcome that.
a.href = `#id-${href}`;
} else if (document.querySelector(`[data-include-name="${href}"]`)) {
const { id } = document.querySelector(`[data-include-name="${href}"]`);
a.href = `#${id}`;
} else {
a.href = `https://github.com/w3c/respec/wiki/${href}`;
}
}
}

function addWikiLinks() {
const createWikiLink = includeName => {
const wikiLink = document.createElement("a");
wikiLink.href = `https://github.com/w3c/respec/wiki/${includeName}/_edit`;
const title = "Edit this section on Wiki";
wikiLink.title = title;
wikiLink.setAttribute("aria-label", title);
wikiLink.textContent = "馃摑 Edit";
wikiLink.classList.add("wiki-link");
return wikiLink;
};

for (const section of document.querySelectorAll("section")) {
const closest = section.closest("section[data-include-name]");
if (!closest) continue;
const { includeName } = closest.dataset;
const wikiLink = createWikiLink(includeName);
section.querySelector("h2, h3, h4, h5, h6").append(wikiLink);
}
}

function cleanup() {
const attributesToRemove = [
"data-max-toc",
"data-include-name",
"data-oninclude",
];
const selector = attributesToRemove.map(attr => `[${attr}]`).join(", ");
document.querySelectorAll(selector).forEach(el => {
attributesToRemove.forEach(attr => el.removeAttribute(attr));
});

document.getElementById("respec-dfn-panel").remove();
}
</script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<section id="abstract">
<p>
ReSpec is a JS library that makes it easier to write technical
specifications, or documents that tend to be technical in nature in
general. It was originally designed for the purpose of writing W3C
specifications, but has since grown to be able to support other outputs
as well.
</p>
</section>
<section data-max-toc="3" data-include-name="ReSpec-Editor's-Guide">
<h2>
Getting Started
</h2>
<section data-include="ReSpec-Editor's-Guide" data-include-replace=
"true"></section>
<section data-max-toc="1" data-include="WebIDL-Guide"></section>
</section>
<section data-max-toc="2" data-include="static-snapshots"></section>
<section data-max-toc="2" data-include="Shorthands-Guide"></section>
<section data-max-toc="1" data-include="markdown"></section>
<section>
<h2>
Configuration Options
</h2>
<section data-include="a11y"></section>
<section data-include="addSectionLinks"></section>
<section data-include="authors"></section>
<section data-include="caniuse"></section>
<section data-include="edDraftURI"></section>
<section data-include="editors"></section>
<section data-include="format"></section>
<section data-include="formerEditors"></section>
<section data-include="github"></section>
<section data-include="highlightVars"></section>
<section data-include="isPreview"></section>
<section data-include="license"></section>
<section data-include-name="lint" data-max-toc="2">
<section data-include="lint" data-include-replace="true"></section>
<section data-include="no-http-props"></section>
<section data-include="local-refs-exist"></section>
<section data-include="no-headingless-sections"></section>
<section data-include="no-unused-vars"></section>
<section data-include="check-punctuation"></section>
<section data-include="privsec-section"></section>
<section data-include="wpt-tests-exist"></section>
</section>
<section data-include="localBiblio"></section>
<section data-include="logos"></section>
<section data-include="maxTocLevel"></section>
<section data-include="mdn"></section>
<section data-include="modificationDate"></section>
<section data-include="noTOC"></section>
<section data-include="otherLinks"></section>
<section data-include="pluralize"></section>
<section data-include="postProcess"></section>
<section data-include="preProcess"></section>
<section data-include="publishDate"></section>
<section data-include="shortName"></section>
<section data-include="specStatus"></section>
<section data-include="subjectPrefix"></section>
<section data-include="subtitle"></section>
<section data-include="testSuiteURI"></section>
<section data-include="tocIntroductory"></section>
<section data-include="xref"></section>
</section>
<section>
<h2>
W3C Specific Configuration Options
</h2>
<section data-include="additionalCopyrightHolders"></section>
<section data-include="addPatentNote"></section>
<section data-include="alternateFormats"></section>
<section data-include="canonicalURI"></section>
<section data-include="charterDisclosureURI"></section>
<section data-include="copyrightStart"></section>
<section data-include="crEnd"></section>
<section data-include="doJsonLd"></section>
<section data-include="errata"></section>
<section data-include="group"></section>
<section data-include="implementationReportURI"></section>
<section data-include="lcEnd"></section>
<section data-include="level"></section>
<section data-include="noRecTrack"></section>
<section data-include="prevED"></section>
<section data-include="previousDiffURI"></section>
<section data-include="previousMaturity"></section>
<section data-include="previousPublishDate"></section>
<section data-include="prevRecShortname"></section>
<section data-include="prevRecURI"></section>
<section data-include="processVersion"></section>
<section data-include="submissionCommentNumber"></section>
<section data-include="wg"></section>
<section data-include="wgId"></section>
<section data-include="wgPatentURI"></section>
<section data-include="wgPublicList"></section>
<section data-include="wgURI"></section>
</section>
<section id="special-section-ids">
<h2>
Special `&lt;section&gt;` IDs
</h2>
<section id="id-conformance" data-include="conformance"></section>
<section id="id-gh-contributors" data-include="gh-contributors">
</section>
<section id="id-idl-index" data-include="idl-index"></section>
<section id="id-index" data-include="index"></section>
<section id="id-issue-summary" data-include="issue-summary"></section>
<section id="id-references" data-include="references"></section>
<section id="id-tof" data-include="tof"></section>
</section>
<section>
<h2>
Special element behaviour
</h2>
<section data-include="figure"></section>
<section data-include="h1-element"></section>
<section data-include="pre-and-code-elements"></section>
<section data-include="section"></section>
<section data-include="title"></section>
</section>
<section>
<h2>
CSS classes
</h2>
<section data-include="appendix"></section>
<section data-include="ednote"></section>
<section data-include="example"></section>
<section data-include="informative"></section>
<section data-include="introductory"></section>
<section data-include="issue"></section>
<section data-include="no-link-warnings"></section>
<section data-include="nohighlight"></section>
<section data-include="nolink"></section>
<section data-include="note"></section>
<section data-include="notoc-class"></section>
<section data-include="override"></section>
<section data-include="practice"></section>
<section data-include="practicedesc"></section>
<section data-include="practicelab"></section>
<section data-include="remove"></section>
<section data-include="removeOnSave"></section>
</section>
<section>
<h2>
HTML Attributes
</h2>
<section data-include="data-abbr"></section>
<section data-include="data-cite"></section>
<section data-include="data-dfn-for"></section>
<section data-include="data-dfn-type"></section>
<section data-include="data-export"></section>
<section data-include="data-format"></section>
<section data-include="data-include"></section>
<section data-include="data-include-format"></section>
<section data-include="data-include-replace"></section>
<section data-include="data-link-for"></section>
<section data-include="data-link-type"></section>
<section data-include="data-local-lt"></section>
<section data-include="data-lt"></section>
<section data-include="data-lt-no-plural"></section>
<section data-include="data-lt-noDefault"></section>
<section data-include="data-max-toc"></section>
<section data-include="data-number"></section>
<section data-include="data-oninclude"></section>
<section data-include="data-sort"></section>
<section data-include="data-tests"></section>
<section data-include="dir"></section>
<section data-include="lang"></section>
</section>
<section class="appendix" data-include="Ecosystem"></section>
<section class="appendix" data-include="person"></section>
</body>
</html>