-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Translated OnStage 2023 rules into AsciiDoc - minor fixes remaining
- Loading branch information
David Schwarz
committed
May 10, 2023
0 parents
commit 54cf0de
Showing
18 changed files
with
1,199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
mkdir -p tmp rules_documents | ||
|
||
set -euo pipefail | ||
|
||
OUTPUT_FILE=$1 | ||
cp $1.adoc tmp/$1.adoc | ||
|
||
cd tmp | ||
|
||
cp $OUTPUT_FILE.adoc _$OUTPUT_FILE.adoc | ||
python3 ../.ci/criticmarkup_to_adoc.py _$OUTPUT_FILE.adoc > $OUTPUT_FILE.adoc | ||
|
||
asciidoctor $OUTPUT_FILE.adoc | ||
asciidoctor -b docbook $OUTPUT_FILE.adoc | ||
|
||
mv $OUTPUT_FILE.html ../rules_documents/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
import re | ||
import sys | ||
import textwrap | ||
|
||
DELETION_REGEXP = re.compile(r'\{--(.*?)--\}', re.DOTALL) | ||
ADDITION_REGEXP = re.compile(r'\{\+\+(.*?)\+\+\}', re.DOTALL) | ||
SUBSTITUTION_REGEXP = re.compile(r'\{~~(.*?)~>(.*?)~~\}', re.DOTALL) | ||
|
||
|
||
class Deletor: | ||
|
||
def __init__(self, changes, note_fmt, replacement_fmt): | ||
self.n_deletions = 0 | ||
self.changes = changes | ||
self.note_fmt = note_fmt | ||
self.replacement_fmt = replacement_fmt | ||
|
||
def __call__(self, match): | ||
self.n_deletions += 1 | ||
|
||
def callback(n_deletions, match): | ||
m = match.group(1).replace('\n', ' ') | ||
txt = self.replacement_fmt.replace('{PREVIOUS}', m) | ||
note = self.note_fmt.replace('{PREVIOUS}', m) | ||
change_id = f'deletion-{n_deletions}' | ||
self.changes.append(change_id) | ||
return f'[[{change_id}, {note}]]\n{txt}' | ||
|
||
return callback(self.n_deletions, match) | ||
|
||
|
||
class Additor: | ||
|
||
def __init__(self, changes, note_fmt, replacement_fmt): | ||
self.n_additions = 0 | ||
self.changes = changes | ||
self.note_fmt = note_fmt | ||
self.replacement_fmt = replacement_fmt | ||
|
||
def __call__(self, match): | ||
self.n_additions += 1 | ||
|
||
def callback(n_additions, match): | ||
m = match.group(1).replace('\n', ' ') | ||
txt = self.replacement_fmt.replace('{CURRENT}', m) | ||
note = self.note_fmt.replace('{CURRENT}', m) | ||
change_id = f'addition-{n_additions}' | ||
self.changes.append(change_id) | ||
return f'[[{change_id}, {note}]]\n{txt}' | ||
|
||
return callback(self.n_additions, match) | ||
|
||
|
||
class Substituter: | ||
|
||
def __init__(self, changes, note_fmt, replacement_fmt, | ||
wrap_long_strings_at=None): | ||
self.n_substitutions = 0 | ||
self.changes = changes | ||
self.note_fmt = note_fmt | ||
self.replacement_fmt = replacement_fmt | ||
self.wrap_long_strings_at = wrap_long_strings_at | ||
|
||
def shorten(self, string): | ||
if self.wrap_long_strings_at is not None: | ||
return textwrap.shorten(string, | ||
self.wrap_long_strings_at, | ||
placeholder='...') | ||
return string | ||
|
||
def __call__(self, match): | ||
self.n_substitutions += 1 | ||
|
||
def callback(n_substitutions, match): | ||
previous = match.group(1).replace('\n', ' ') | ||
current = match.group(2).replace('\n', ' ') | ||
|
||
short_previous = self.shorten(previous) | ||
short_current = self.shorten(current) | ||
|
||
txt = self.replacement_fmt.replace('{CURRENT}', current) \ | ||
.replace('{PREVIOUS}', previous) | ||
note = self.note_fmt.replace('{CURRENT}', short_current) \ | ||
.replace('{PREVIOUS}', short_previous) | ||
|
||
change_id = f'substitution-{n_substitutions}' | ||
self.changes.append(change_id) | ||
return f'[[{change_id}, {note}]]\n{txt}' | ||
|
||
return callback(self.n_substitutions, match) | ||
|
||
|
||
class CriticMarkupPreprocessor: | ||
|
||
def __init__(self, | ||
change_listing_fmt='- {CHANGE}', | ||
addition_note_fmt='Added "{CURRENT}"', | ||
addition_replacement_fmt='{CURRENT}', | ||
deletion_note_fmt='Deleted "{PREVIOUS}"', | ||
deletion_replacement_fmt='(used to be "{PREVIOUS}")', | ||
substitution_note_fmt='Changed "{PREVIOUS}" to "{CURRENT}"', | ||
substitution_replacement_fmt='{CURRENT} (used to be "{PREVIOUS}")'): # noqa | ||
self.changes = [] | ||
self.change_listing_fmt = change_listing_fmt | ||
self.addition_note_fmt = addition_note_fmt | ||
self.addition_replacement_fmt = addition_replacement_fmt | ||
self.deletion_note_fmt = deletion_note_fmt | ||
self.deletion_replacement_fmt = deletion_replacement_fmt | ||
self.substitution_note_fmt = substitution_note_fmt | ||
self.substitution_replacement_fmt = substitution_replacement_fmt | ||
|
||
def convert(self, infile): | ||
d = Deletor(self.changes, | ||
self.deletion_note_fmt, | ||
self.deletion_replacement_fmt) | ||
a = Additor(self.changes, | ||
self.addition_note_fmt, | ||
self.addition_replacement_fmt) | ||
s = Substituter(self.changes, | ||
self.substitution_note_fmt, | ||
self.substitution_replacement_fmt) | ||
|
||
with open(infile) as f: | ||
instr = f.read() | ||
instr = DELETION_REGEXP.sub(d, instr) | ||
instr = ADDITION_REGEXP.sub(a, instr) | ||
instr = SUBSTITUTION_REGEXP.sub(s, instr) | ||
|
||
list_of_changes = [self.change_listing_fmt.replace('{CHANGE}', | ||
change) | ||
for change in self.changes] | ||
changes = '\n'.join(list_of_changes) | ||
|
||
instr = instr.replace('{+-~TOC-CHANGES~-+}', changes) | ||
return instr | ||
|
||
|
||
if __name__ == '__main__': | ||
cmp = CriticMarkupPreprocessor( | ||
change_listing_fmt='- <<{CHANGE}>>', | ||
addition_note_fmt='Added "{CURRENT}"', | ||
addition_replacement_fmt='[red]#*{CURRENT}*#', | ||
deletion_note_fmt='Deleted "{PREVIOUS}"', | ||
deletion_replacement_fmt='footnote:[In previous version this said "{PREVIOUS}"]', # noqa | ||
substitution_note_fmt='Changed "{PREVIOUS}" to "{CURRENT}"', | ||
substitution_replacement_fmt='[red]#*{CURRENT}*#\nfootnote:[In previous version this said "{PREVIOUS}"]' # noqa | ||
) | ||
print(cmp.convert(sys.argv[1])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
set -euo pipefail | ||
|
||
OUTPUT_FILE=$1 | ||
|
||
cp manual.sty tmp/ | ||
cp -r media tmp/ | ||
cd tmp | ||
|
||
# Apply custom styling to DocBook | ||
dblatex -T db2latex $OUTPUT_FILE.xml -t tex --texstyle=./manual.sty -p ../custom.xsl | ||
|
||
# Go through the generated .tex output, find the place where the preamble ends | ||
# (marked by the \mainmatter command) and create a file without it. | ||
cat $OUTPUT_FILE.tex | awk 'f;/\\mainmatter/{f=1}' > $OUTPUT_FILE"_without_preamble.tex" | ||
# Concat the standardized preamble with the "without_preamble" version of the file | ||
cat ../preamble.tex $OUTPUT_FILE"_without_preamble.tex" > $OUTPUT_FILE.tex | ||
texliveonfly $OUTPUT_FILE.tex | ||
pdflatex $OUTPUT_FILE.tex | ||
pdflatex $OUTPUT_FILE.tex | ||
|
||
mv $OUTPUT_FILE.pdf ../rules_documents/ | ||
|
||
cd .. | ||
rm -r tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
on: [push] | ||
jobs: | ||
build: | ||
name: build | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: build the rules | ||
run: | | ||
docker run -v $(pwd):/documents asciidoctor/docker-asciidoctor .ci/adoc-to-tex.sh onstage_rules | ||
docker run -v $(pwd):/documents mrshu/texlive-dblatex .ci/tex-to-pdf.sh onstage_rules | ||
mkdir -p dist/${GITHUB_REF#refs/heads/}/ | ||
cp -R ./media rules_documents/* dist/${GITHUB_REF#refs/heads/}/ | ||
- name: publish the rules | ||
uses: peaceiris/actions-gh-pages@v3 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: ./dist | ||
keep_files: True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
tmp/* | ||
rules_documents/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?xml version='1.0' encoding="iso-8859-1"?> | ||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'> | ||
<xsl:template match="phrase[@role='red']"> | ||
<xsl:text> | ||
\textcolor{red}{ | ||
</xsl:text> | ||
<xsl:apply-templates/> | ||
<xsl:text> | ||
} | ||
</xsl:text> | ||
</xsl:template> | ||
<xsl:template match="phrase[@role='blue-background']"> | ||
<xsl:text> | ||
\sethlcolor{blue}\hl{ | ||
</xsl:text> | ||
<xsl:apply-templates/> | ||
<xsl:text> | ||
} | ||
</xsl:text> | ||
</xsl:template> | ||
<xsl:template match="phrase[@role='green-background']"> | ||
<xsl:text> | ||
\sethlcolor{green}\hl{ | ||
</xsl:text> | ||
<xsl:apply-templates/> | ||
<xsl:text> | ||
} | ||
</xsl:text> | ||
</xsl:template> | ||
|
||
<xsl:template match="section/simpara"> | ||
<xsl:text> | ||
\p </xsl:text> | ||
<xsl:apply-templates/> | ||
<xsl:text> | ||
|
||
</xsl:text> | ||
</xsl:template> | ||
|
||
<xsl:template match="part|chapter|appendix| | ||
sect1|sect2|sect3|sect4|sect5|section" mode="label.markup"> | ||
<xsl:text>\ref{</xsl:text> | ||
<xsl:value-of select="(@id|@xml:id)[1]"/> | ||
<xsl:text>}</xsl:text> | ||
</xsl:template> | ||
|
||
|
||
<xsl:param name="xref.with.number.and.title" select="1"></xsl:param> | ||
|
||
<xsl:param name="local.l10n.xml" select="document('')"/> | ||
<l:i18n xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0"> | ||
<l:l10n xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" language="en"> | ||
<l:context name="xref-number-and-title"> | ||
<l:template name="section" text="Rule %n, %t"/> | ||
</l:context> | ||
</l:l10n> | ||
</l:i18n> | ||
|
||
</xsl:stylesheet> | ||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
%% | ||
%% This style is derivated from the db2latex one | ||
%% | ||
\NeedsTeXFormat{LaTeX2e} | ||
\ProvidesPackage{manual} | ||
|
||
|
||
% The defined options | ||
\DeclareOption{hyperlink}{ \def\DBKhyperlink{yes} } | ||
\DeclareOption{nohyperlink}{ \def\DBKhyperlink{no} } | ||
|
||
% Default values | ||
\ExecuteOptions{hyperlink} | ||
|
||
% If defined, process the options | ||
\ProcessOptions\relax | ||
|
||
%% Just use the original package and pass the options | ||
\RequirePackageWithOptions{db2latex} | ||
|
||
\renewcommand{\maketitle}{ | ||
|
||
\begin{center} | ||
{\LARGE \@title \par} | ||
\vskip 8em | ||
\end{center} | ||
|
||
% \pagestyle{empty} | ||
|
||
% \noindent | ||
% \textbf{\DBKtitle \\} | ||
% \ifx\DBKauthor\empty\else{by \DBKauthor \\}\fi | ||
% \hspace{0pt}\\ | ||
% \ifthenelse{\equal{\DBKedition}{}}{}{Edition \DBKedition \\} | ||
% \ifthenelse{\equal{\DBKpubdate}{}}{}{Published \DBKpubdate \\} | ||
% \ifthenelse{\equal{\DBKcopyright}{}}{}{\DBKcopyright \\} | ||
% \hspace{0pt}\\ | ||
% Now the legalnotice block | ||
% \DBKlegalblock | ||
% Ahoj | ||
% \newpage | ||
} | ||
|
||
\renewenvironment{DBKadmonition}[2] { | ||
% this code corresponds to the \begin{admonition} command | ||
\hspace{0mm}\newline\hspace*\fill\newline | ||
\noindent | ||
\setlength{\fboxsep}{5pt} | ||
\setlength{\admlength}{\linewidth} | ||
\addtolength{\admlength}{-2\fboxsep} | ||
\addtolength{\admlength}{-10\fboxrule} | ||
\admminipage{\admlength} | ||
~\\[1mm] | ||
\ifthenelse{\equal{#1}{}}{ | ||
\def\admgraph{false} | ||
}{ | ||
\def\admgraph{true} | ||
\includegraphics[width=1cm]{icons/#1} | ||
\addtolength{\admlength}{-1cm} | ||
\addtolength{\admlength}{-20pt} | ||
\begin{minipage}[lt]{\admlength} | ||
} | ||
\parskip=0.5\baselineskip \advance\parskip by 0pt plus 2pt | ||
} %done | ||
{ % this code corresponds to the \end{admonition} command | ||
\vspace{5mm} | ||
\ifthenelse{\equal{\admgraph}{false}}{}{ | ||
\end{minipage} | ||
} | ||
\endadmminipage | ||
\vspace{.5em} | ||
\par | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.