Skip to content

Commit

Permalink
feat: Add support for math notation in kramdown-rfc (#368)
Browse files Browse the repository at this point in the history
This change adds utftex and tex2svg.
Fixes #352
  • Loading branch information
kesara authored Aug 14, 2023
1 parent 2226fd0 commit 22e4704
Show file tree
Hide file tree
Showing 9 changed files with 1,723 additions and 10 deletions.
16 changes: 15 additions & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
sudo tar zxf mmark_*.tgz -C /bin/
wget https://github.com/ietf-tools/bap/archive/refs/heads/master.zip
unzip -q master.zip -d /tmp/bap
wget https://github.com/bartp5/libtexprintf/archive/refs/tags/v1.25.zip
unzip -q -q v1.25.zip -d /tmp/
- name: Build bap
working-directory: /tmp/bap/bap-master/
Expand All @@ -39,6 +41,17 @@ jobs:
sudo make
sudo cp aex bap /bin
- name: Build utftex
working-directory: /tmp/libtexprintf-1.25
env:
LD_LIBRARY_PATH: /usr/local/lib
run: |
sudo ldconfig
sudo apt-get install -y autoconf pkg-config libtool
sudo ./autogen.sh
sudo ./configure
sudo make install
# Python
- name: Set up Python 3.10
uses: actions/setup-python@v3
Expand Down Expand Up @@ -66,7 +79,8 @@ jobs:
run: pyflakes at tests
- name: Run tests and collect coverage
env:
PATH: $PATH:/bin:./node_modules/.bin/
PATH: $PATH:/usr/local/bin:/bin:./node_modules/.bin/
LD_LIBRARY_PATH: /usr/local/lib
run: |
coverage run -m unittest discover tests
coverage xml
Expand Down
21 changes: 18 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ LABEL maintainer="Kesara Rathnayake <kesara@staff.ietf.org>"

ENV DEBIAN_FRONTEND noninteractive
ENV PATH=$PATH:./node_modules/.bin
ENV LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
# Disable local file read for kramdown-rfc
ENV KRAMDOWN_SAFE=1

Expand All @@ -12,22 +13,26 @@ SHELL ["/bin/bash", "-o", "pipefail", "-c"]

RUN apt-get update && \
apt-get install -y \
autoconf \
software-properties-common \
gcc \
wget \
ruby \
python3.10 \
python3-pip \
pkg-config \
libtool \
libpango-1.0-0 \
wdiff \
rfcdiff \
npm \
gawk \
bison \
flex && \
rm -rf /var/lib/apt/lists/* /var/log/dpkg.log && \
apt-get autoremove -y && \
apt-get clean -y
rm -rf /var/lib/apt/lists/* /var/log/dpkg.log && \
apt-get autoremove -y && \
apt-get clean -y && \
ldconfig

# Install required fonts
RUN mkdir -p ~/.fonts/opentype && \
Expand Down Expand Up @@ -63,6 +68,16 @@ RUN arch=$(arch | sed s/aarch64/arm64/ | sed s/x86_64/amd64/) && \
tar zxf mmark_*.tgz -C /bin/ && \
rm mmark_*.tgz

# Install utftex
RUN export UTFTEX=libtexprintf-1.25 && \
wget -q https://github.com/bartp5/libtexprintf/archive/refs/tags/v1.25.zip && \
unzip -q v1.25.zip -d /tmp/ && \
cd /tmp/$UTFTEX && \
./autogen.sh && \
./configure && \
make install && \
rm -r /tmp/$UTFTEX /usr/src/app/v1.25.zip

COPY Gemfile Gemfile.lock LICENSE README.md api.yml constraints.txt package-lock.json package.json requirements.txt .
COPY at ./at

Expand Down
6 changes: 6 additions & 0 deletions api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -860,3 +860,9 @@ paths:
rfcdiff:
type: string
description: rfcdiff version
utftex:
type: string
description: utftex version
tex2svg:
type: string
description: tex2svg version
6 changes: 4 additions & 2 deletions at/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
from at.utils.version import (
get_aasvg_version, get_idnits_version, get_id2xml_version,
get_iddiff_version, get_mmark_version, get_kramdown_rfc_version,
get_rfcdiff_version, get_svgcheck_version, get_weasyprint_version,
get_xml2rfc_version)
get_rfcdiff_version, get_svgcheck_version, get_tex2svg_version,
get_utftex_version, get_weasyprint_version, get_xml2rfc_version)

BAD_REQUEST = 400
VERSION_INFORMATION = {
Expand All @@ -37,6 +37,8 @@
'aasvg': get_aasvg_version(),
'svgcheck': get_svgcheck_version(),
'rfcdiff': get_rfcdiff_version(),
'tex2svg': get_tex2svg_version(),
'utftex': get_utftex_version(),
'bap': '1.4'} # bap does not provide a switch to get version

bp = Blueprint('api', __name__, url_prefix='/api')
Expand Down
36 changes: 36 additions & 0 deletions at/utils/version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from logging import getLogger
from subprocess import run as proc_run, CalledProcessError
from re import search

from weasyprint import __version__ as weasyprint_version
from xml2rfc import __version__ as xml2rfc_version
Expand Down Expand Up @@ -132,3 +133,38 @@ def get_rfcdiff_version(logger=getLogger()):
logger.info('rfcdiff error: {}'.format(
output.stderr.decode('utf-8')))
return None


def get_tex2svg_version(logger=getLogger()):
'''Return tex2svg version'''

output = proc_run(args=['tex2svg', '--version'], capture_output=True)

try:
output.check_returncode()
return output.stdout.decode('utf-8').strip()
except CalledProcessError: # pragma: no cover
logger.info('tex2svg error: {}'.format(
output.stderr.decode('utf-8')))
return None


def get_utftex_version(logger=getLogger()):
'''Return utftex version'''

output = proc_run(args=['utftex', '--version'], capture_output=True)

try:
output.check_returncode()
match = search(
r'This is utftex version (\d+\.\d+)',
output.stdout.decode('utf-8').strip())
if match:
return match.group(1)
else:
logger.info('utftex error: Could not find version.')
return None
except CalledProcessError: # pragma: no cover
logger.info('utftex error: {}'.format(
output.stderr.decode('utf-8')))
return None
Loading

0 comments on commit 22e4704

Please sign in to comment.