Skip to content

Commit

Permalink
Display add-on docs using marked
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-src committed Jun 5, 2018
1 parent e4eb98e commit db4e0b6
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 9 deletions.
66 changes: 66 additions & 0 deletions _docs/api/addons.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
layout: default
---

<header id="docs-header"></header>

<article class="docs-content" id="docs-content"></article>

<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/es6-promise/dist/es6-promise.js"></script>
<script src="https://cdn.jsdelivr.net/npm/unfetch/dist/unfetch.umd.js"></script>

<script>
var header = document.getElementById('docs-header');
var content = document.getElementById('docs-content');

var params={};
window.location.search
.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(s, k, v) {
params[key] = decodeURIComponent(value);
});

if (!params.repo) {
window.alert('Error: url query is missing repo name');
}

params.page = params.page || 'docs/README.md';
var url = 'https://cdn.jsdelivr.net/gh/xtermjs/'
+ params.repo + '/' + params.page;

if (!window.Promise) {
window.Promise = ES6Promise;
}
if (!window.fetch) {
window.fetch = unfetch;
}

fetch(url)
.then(function (response) {
return response.text();
})
.then(function (body) {
content.innerHTML = marked(body);
document.title = content.getElementsByTagName('h1')[0].innerHTML;
header.innerHTML = '<h1><a href="' + location + '">'
+ document.title
+ '</a></h1>';
var anchors = content.getElementsByTagName('a');
for (var href, i = 0; i < anchors.length; i++) {
anchors[i].addEventListener('click', onClick);
}
})
.catch(function (error) {
content.innerHTML = '<p>Oops! There was a problem rendering the page.</p>'
+ '<p>' + error.message + '</p>';
});

function onClick(event) {
var href = event.target.getAttribute('href');
if (!/^(https?|#)/.test(href)) {
// split on hash
anchor.setAttribute('href', window.location.href.split(/[#?]/)[0]
+ '?repo=' + params.repo + '&page=' + encodeURIComponent(href));
}
}
</script>
22 changes: 16 additions & 6 deletions _includes/docs-category-article-list.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
<ul class="docs-list">
{% for doc in site.docs %}
{% if doc.category == include.category %}
<li>
<a href="{{ site.baseurl }}{{ doc.url }}">{{ doc.title }}</a>
</li>
{% endif %}
{% if doc.category == include.category %}
{% assign url = "{{ site.baseurl }}{{ doc.url }}" %}
<li>
{% unless include.category == "addons" %}
<a href="{{ url }}">{{ doc.title }}</a>
{% else %}
<a href="{{ url }}?repo=xterm.js-addon-attach">Attach</a>
<a href="{{ url }}?repo=xterm.js-addon-fit">Fit</a>
<a href="{{ url }}?repo=xterm.js-addon-fullscreen">Fullscreen</a>
<a href="{{ url }}?repo=xterm.js-addon-terminado">Terminado</a>
<a href="{{ url }}?repo=xterm.js-addon-winptycompat">WinptyCompat</a>
<a href="{{ url }}?repo=xterm.js-addon-zmodem">Zmodem</a>
{% endif %}

This comment has been minimized.

Copy link
@Tyriar

Tyriar Jun 6, 2018

Member

FYI if you do a review comment (via the PR files tab) instead of commenting on the makes it a little easier as a reviewer (plus I get less notifications 😄)

</li>
{% endif %}
{% endfor %}
</ul>
</ul>
5 changes: 2 additions & 3 deletions _pages/docs.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ <h2>Guides</h2>
{% include docs-category-article-list.html category="Guides" %}

<h2>API Reference</h2>
{% include docs-category-article-list.html category="API" %}
<h4>Modules</h4>
{% include docs-category-article-list.html category="API-modules" %}
<h4>Classes</h4>
{% include docs-category-article-list.html category="API-classes" %}
<h4>Interfaces</h4>
{% include docs-category-article-list.html category="API-interfaces" %}

<h4>Addons</h4>
{% include docs-category-article-list.html category="addon" %}
<h2>Addons</h2>
{% include docs-category-article-list.html category="addons" %}

0 comments on commit db4e0b6

Please sign in to comment.