Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1607143 - Doc: run some post processing code to fix the url to me…
Browse files Browse the repository at this point in the history
…rmaid js r=championshuttler

Also bump to the latest version of mermaid js

Differential Revision: https://phabricator.services.mozilla.com/D62027
  • Loading branch information
sylvestre committed Feb 11, 2020
1 parent ba5497e commit 29b50b5
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion tools/moztreedocs/mach_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import fnmatch
import multiprocessing
import os
import re
import subprocess
import sys
import time
Expand Down Expand Up @@ -101,6 +102,9 @@ def build_docs(self, path=None, fmt='html', outdir=None, auto_open=True,
else:
print('\nGenerated documentation:\n%s' % savedir)

print('Post processing HTML files')
self._post_process_html(savedir)

if archive:
archive_path = os.path.join(outdir, '%s.tar.gz' % self.project)
create_tarball(archive_path, savedir)
Expand All @@ -126,7 +130,7 @@ def build_docs(self, path=None, fmt='html', outdir=None, auto_open=True,
server = Server()

sphinx_trees = self.manager.trees or {savedir: docdir}
for dest, src in sphinx_trees.items():
for _, src in sphinx_trees.items():
run_sphinx = partial(self._run_sphinx, src, savedir, fmt=fmt, jobs=jobs)
server.watch(src, run_sphinx)
server.serve(host=host, port=port, root=savedir,
Expand Down Expand Up @@ -169,6 +173,32 @@ def _run_sphinx(self, docdir, savedir, config=None, fmt='html', jobs=None):
args.extend(['-j', jobs])
return sphinx.cmd.build.build_main(args)

def _post_process_html(self, savedir):
"""
Perform some operations on the generated html to fix some URL
"""
MERMAID_VERSION = "8.4.4"
for root, _, files in os.walk(savedir):
for file in files:
if file.endswith(".html"):
p = os.path.join(root, file)

with open(p, 'r') as file:
filedata = file.read()

# Workaround https://bugzilla.mozilla.org/show_bug.cgi?id=1607143
# to avoid a CSP error
# This method should be removed once
# https://github.com/mgaitan/sphinxcontrib-mermaid/pull/37 is merged
# As sphinx-mermaid currently uses an old version, also force
# a more recent version
filedata = re.sub(r'https://unpkg.com/mermaid@.*/dist',
r'https://cdnjs.cloudflare.com/ajax/libs/mermaid/{}'
.format(MERMAID_VERSION), filedata)

with open(p, 'w') as file:
file.write(filedata)

@property
def manager(self):
if not self._manager:
Expand Down

0 comments on commit 29b50b5

Please sign in to comment.