Skip to content

Commit

Permalink
Update Manubot on 2019-04-01
Browse files Browse the repository at this point in the history
Includes new interactive frontend

Updates Manubot Rootstock through the commit:
manubot/rootstock@fea9eb8

Based on upgrade instructions at
https://github.com/manubot/rootstock/blob/fea9eb80af4ca9d5a116f6c28a6b740272e3c0b9/SETUP.md#merging-upstream-rootstock-changes
  • Loading branch information
dhimmel committed Apr 1, 2019
2 parents e87ef2a + fea9eb8 commit 5d27751
Show file tree
Hide file tree
Showing 22 changed files with 3,415 additions and 157 deletions.
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ branches:
only:
- master
before_install:
- wget https://repo.continuum.io/miniconda/Miniconda3-4.5.11-Linux-x86_64.sh
- wget https://repo.continuum.io/miniconda/Miniconda3-4.5.12-Linux-x86_64.sh
--output-document miniconda.sh
- bash miniconda.sh -b -p $HOME/miniconda
- source $HOME/miniconda/etc/profile.d/conda.sh
- hash -r
- conda config --set always_yes yes --set changeps1 no
- conda info --all
- conda config
--set always_yes yes
--set changeps1 no
install:
- conda env create --quiet --file build/environment.yml
- conda list --name manubot
- conda activate manubot
script:
- sh build/build.sh
Expand All @@ -22,5 +24,5 @@ cache:
- ci/cache
after_success:
- test $TRAVIS_BRANCH = "master" &&
test $TRAVIS_PULL_REQUEST = "false" &&
test $TRAVIS_EVENT_TYPE = "push" &&
sh ci/deploy.sh
2 changes: 1 addition & 1 deletion build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ For example, use the command `BUILD_DOCX=true sh build/build.sh`.
To export DOCX for all Travis builds, set a [Travis environment variable](https://docs.travis-ci.com/user/environment-variables/#Defining-Variables-in-Repository-Settings).
Currently, equation numbers via `pandoc-eqnos` are not supported for DOCX output.
There is varying support for embedding images in DOCX output.
Please reference [Pull Request #40](https://github.com/greenelab/manubot-rootstock/pull/40) for possible solutions and continued discussion.
Please reference [Pull Request #40](https://github.com/manubot/rootstock/pull/40) for possible solutions and continued discussion.

## Environment

Expand Down
2 changes: 1 addition & 1 deletion build/assets/style.csl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title>Manubot</title>
<id>http://www.zotero.org/styles/manubot</id>
<link href="http://www.zotero.org/styles/manubot" rel="self"/>
<link href="https://github.com/greenelab/manubot-rootstock" rel="documentation"/>
<link href="https://github.com/manubot/rootstock" rel="documentation"/>
<author>
<name>Daniel Himmelstein</name>
<email>[email protected]</email>
Expand Down
13 changes: 11 additions & 2 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,20 @@ pandoc --verbose \
--bibliography=$BIBLIOGRAPHY_PATH \
--csl=$CSL_PATH \
--metadata link-citations=true \
--mathjax \
--include-after-body=build/themes/default.html \
--include-after-body=build/plugins/analytics.html \
--include-after-body=build/plugins/table-scroll.html \
--include-after-body=build/plugins/anchors.html \
--include-after-body=build/plugins/accordion.html \
--include-after-body=build/plugins/tooltips.html \
--include-after-body=build/plugins/jump-to-first.html \
--include-after-body=build/plugins/link-highlight.html \
--include-after-body=build/plugins/table-of-contents.html \
--include-after-body=build/plugins/lightbox.html \
--mathjax \
--variable math="" \
--include-after-body=build/plugins/math.html \
--include-after-body=build/plugins/hypothesis.html \
--include-after-body=build/plugins/analytics.html \
--output=output/manuscript.html \
$INPUT_PATH

Expand Down
10 changes: 6 additions & 4 deletions build/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@ channels:
- conda-forge
dependencies:
- conda-forge::cairo=1.14.12
- conda-forge::cairocffi=0.8.0
- conda-forge::cffi=1.11.5
- conda-forge::ghp-import=0.5.5
- conda-forge::jinja2=2.10
- conda-forge::jsonschema=2.6.0
- conda-forge::pandas=0.23.4
- conda-forge::pandoc=2.5
- conda-forge::pandas=0.24.0
- conda-forge::pandoc=2.6
- conda-forge::pango=1.40.14
- conda-forge::python=3.6.5
- conda-forge::psutil=5.5.1
- conda-forge::python=3.6.7
- conda-forge::pyyaml=3.13
- conda-forge::requests=2.21.0
- conda-forge::watchdog=0.8.3
- pip:
- errorhandler==2.0.1
- git+https://github.com/greenelab/manubot@552dd99aaa148365a29a87176fedd626d4642d3c
- git+https://github.com/manubot/manubot@4505db3fd8a9dc1ba26c36f3fea9accbf02d47d8
- jsonref==0.2
- opentimestamps-client==0.6.0
- opentimestamps==0.3.0
Expand Down
273 changes: 273 additions & 0 deletions build/plugins/accordion.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
<!-- accordion plugin -->

<script>
(function() {
// /////////////////////////
// DESCRIPTION
// /////////////////////////

// This Manubot plugin allows sections of content under <h2> headings
// to be collapsible.

// /////////////////////////
// OPTIONS
// /////////////////////////

// plugin name prefix for url parameters
const pluginName = 'accordion';

// default plugin options
const options = {
// whether to always start expanded ('false'), always start
// collapsed ('true'), or start collapsed when screen small ('auto')
startCollapsed: 'auto',
// whether plugin is on or not
enabled: 'true'
};

// change options above, or override with url parameter, eg:
// 'manuscript.html?pluginName-enabled=false'

// /////////////////////////
// SCRIPT
// /////////////////////////

// start script
function start() {
// run through each <h2> heading
const headings = document.querySelectorAll('h2');
for (const heading of headings) {
addArrow(heading);

// start expanded/collapsed based on option
if (
options.startCollapsed === 'true' ||
(options.startCollapsed === 'auto' && isSmallScreen())
)
collapseHeading(heading);
else
expandHeading(heading);
}

// attach hash change listener to window
window.addEventListener('hashchange', onHashChange);
}

// when hash (eg manuscript.html#introduction) changes
function onHashChange() {
const target = getHashTarget();
if (target)
goToElement(target);
}

// add arrow to heading
function addArrow(heading) {
// add arrow button
const arrow = document.createElement('button');
arrow.innerHTML = document.querySelector(
'.icon_angle_down'
).innerHTML;
arrow.classList.add('icon_button', 'accordion_arrow');
heading.insertBefore(arrow, heading.firstChild);

// attach click listener to heading and button
heading.addEventListener('click', onHeadingClick);
arrow.addEventListener('click', onArrowClick);
}

// determine if on mobile-like device with small screen
function isSmallScreen() {
return Math.min(window.innerWidth, window.innerHeight) < 480;
}

// scroll to and focus element
function goToElement(element, offset) {
// expand accordion section if collapsed
expandElement(element);
const y =
getRectInView(element).top -
getRectInView(document.documentElement).top -
(offset || 0);
// trigger any function listening for "onscroll" event
window.dispatchEvent(new Event('scroll'));
window.scrollTo(0, y);
element.focus();
}

// get element that is target of hash
function getHashTarget(link) {
const hash = link ? link.hash : window.location.hash;
const id = hash.slice(1);
let target = document.querySelector(
'[id="' + id + '"], [name="' + id + '"]'
);
if (!target)
return;

// if figure or table, modify target to get expected element
if (hash.indexOf('#fig:') === 0)
target = target.parentNode;
if (hash.indexOf('#tbl:') === 0)
target = target.nextElementSibling;

return target;
}

// when <h2> heading is clicked
function onHeadingClick(event) {
// only collapse if <h2> itself is target of click (eg, user did
// not click on anchor within <h2>)
if (event.target === this)
toggleCollapse(this);
}

// when arrow button is clicked
function onArrowClick() {
toggleCollapse(this.parentNode);
}

// collapse section if expanded, expand if collapsed
function toggleCollapse(heading) {
if (heading.dataset.collapsed === 'false')
collapseHeading(heading);
else
expandHeading(heading);
}

// elements to exclude from collapse, such as table of contents panel,
// hypothesis panel, etc
const exclude = '#toc_panel, div.annotator-frame, #lightbox_overlay';

// collapse section
function collapseHeading(heading) {
heading.setAttribute('data-collapsed', 'true');
const children = getChildren(heading);
for (const child of children)
child.setAttribute('data-collapsed', 'true');
}

// expand section
function expandHeading(heading) {
heading.setAttribute('data-collapsed', 'false');
const children = getChildren(heading);
for (const child of children)
child.setAttribute('data-collapsed', 'false');
}

// get list of elements between this <h2> and next <h2> or <h1>
// ("children" of the <h2> section)
function getChildren(heading) {
return nextUntil(heading, 'h2, h1', exclude);
}

// get position/dimensions of element or viewport
function getRectInView(element) {
let rect = {};
rect.left = 0;
rect.top = 0;
rect.right = document.documentElement.clientWidth;
rect.bottom = document.documentElement.clientHeight;
let style = {};

if (element instanceof HTMLElement) {
rect = element.getBoundingClientRect();
style = window.getComputedStyle(element);
}

const margin = {};
margin.left = parseFloat(style.marginLeftWidth) || 0;
margin.top = parseFloat(style.marginTopWidth) || 0;
margin.right = parseFloat(style.marginRightWidth) || 0;
margin.bottom = parseFloat(style.marginBottomWidth) || 0;

const border = {};
border.left = parseFloat(style.borderLeftWidth) || 0;
border.top = parseFloat(style.borderTopWidth) || 0;
border.right = parseFloat(style.borderRightWidth) || 0;
border.bottom = parseFloat(style.borderBottomWidth) || 0;

const newRect = {};
newRect.left = rect.left + margin.left + border.left;
newRect.top = rect.top + margin.top + border.top;
newRect.right = rect.right + margin.right + border.right;
newRect.bottom = rect.bottom + margin.bottom + border.bottom;
newRect.width = newRect.right - newRect.left;
newRect.height = newRect.bottom - newRect.top;

return newRect;
}

// get list of elements after a start element up to element matching
// query
function nextUntil(element, query, exclude) {
const elements = [];
while (element = element.nextElementSibling, element) {
if (element.matches(query))
break;
if (!element.matches(exclude))
elements.push(element);
}
return elements;
}

// get closest element before specified element that matches query
function firstBefore(element, query) {
while (
element &&
element !== document.body &&
!element.matches(query)
)
element = element.previousElementSibling || element.parentNode;

return element;
}

// check if element is part of collapsed heading
function isCollapsed(element) {
while (element && element !== document.body) {
if (element.dataset.collapsed === 'true')
return true;
element = element.parentNode;
}
return false;
}

// expand heading containing element if necesary
function expandElement(element) {
if (isCollapsed(element)) {
const heading = firstBefore(element, 'h2');
if (heading)
heading.click();
}
}

// load options from url parameters
function loadOptions() {
const url = window.location.search;
const params = new URLSearchParams(url);
for (const optionName of Object.keys(options)) {
const paramName = pluginName + '-' + optionName;
const param = params.get(paramName);
if (param !== '' && param !== null)
options[optionName] = param;
}
}
loadOptions();

// start script when document is finished loading
if (options.enabled === 'true')
window.addEventListener('load', start);
})();
</script>

<!-- angle down icon -->

<template class="icon_angle_down">
<!-- modified from: https://fontawesome.com/icons/angle-down -->
<svg width="16" height="16" viewBox="0 0 448 512">
<path
fill="currentColor"
d="M207.029 381.476L12.686 187.132c-9.373-9.373-9.373-24.569 0-33.941l22.667-22.667c9.357-9.357 24.522-9.375 33.901-.04L224 284.505l154.745-154.021c9.379-9.335 24.544-9.317 33.901.04l22.667 22.667c9.373 9.373 9.373 24.569 0 33.941L240.971 381.476c-9.373 9.372-24.569 9.372-33.942 0z"
></path>
</svg>
</template>
7 changes: 3 additions & 4 deletions build/plugins/analytics.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<!-- Insert Analytics Script Below -->
<script>
</script>
<!-- End Analytics Script -->
<!-- analytics plugin -->

<!-- copy and paste code from Google Analytics or similar service here -->
Loading

0 comments on commit 5d27751

Please sign in to comment.