Skip to content

Commit

Permalink
Various label fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ascholerChemeketa committed Oct 24, 2024
1 parent 8497176 commit 9ed7418
Show file tree
Hide file tree
Showing 16 changed files with 11,647 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"editor.formatOnPaste": false
}
12 changes: 12 additions & 0 deletions fixup-caption.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="listing/statement">
<caption><xsl:apply-templates select="@*|node()"/></caption>
</xsl:template>
</xsl:stylesheet>
81 changes: 81 additions & 0 deletions fixups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# apply the xslt stylesheet to all available xml files

import subprocess
import lxml.etree as ET
import os
import re
from pathlib import Path
import pdb
import sys

xsl_filename = "warnings.xsl"
basedir = sys.argv[1]


def to_snake(name):
name = re.sub(r"(?<!^)(?=[A-Z])", "-", name).lower()
return name


# handles acronyms better
def camel_to_snake(name):
name = re.sub("(.)([A-Z][a-z]+)", r"\1-\2", name)
return re.sub("([a-z0-9])([A-Z])", r"\1-\2", name).lower()


def transform_one_page(root, xml_filename, fileonly):
if "toctree" in str(xml_filename):
return
try:
dom = ET.parse(xml_filename)
except Exception as e:
print(f"Failed to parse {xml_filename}")
print(e)
return
stringparams = {"filename": ET.XSLT.strparam(fileonly)}
folder = root.split("/")[-1].strip()
folder = camel_to_snake(folder)
stringparams["folder"] = ET.XSLT.strparam(folder)

xslt = ET.parse(xsl_filename)
transform = ET.XSLT(xslt)
try:
newdom = transform(
dom, **stringparams
) # can add an unparsed dictionary of stringparams
except Exception as e:
print(f"Failed to transform {xml_filename}")
print(e)
return

# print(ET.tostring(newdom, pretty_print=True).decode("utf8"))

# with open(xml_filename, "w") as ptfile:
# ptfile.write(ET.tostring(newdom, pretty_print=True).decode("utf8") + "\n")

# newroot = root.replace("book/build/xml/", "")
# ptx_filename = (
# str(xml_filename).replace(".xml", ".ptx").replace("book/build/xml/", "")
# )
# # maybe need to make folder
# if ptx_filename.startswith("/"):
# ptx_filename = ptx_filename[1:]
# fpath = Path(basedir) / "pretextNew" / Path(ptx_filename)
# print(" ", fpath)
# if "/" in ptx_filename:
# fpath.parent.mkdir(parents=True, exist_ok=True)

# with open(fpath, "w") as ptfile:
# ptfile.write(ET.tostring(newdom, pretty_print=True).decode("utf8"))


xmldir = Path(basedir)
if not xmldir.exists():
print(f"Directory {xmldir} does not exist")

# Recursively walk the tree
for root, dirs, files in os.walk(xmldir):
for file in files:
if ".ptx" in file and "toc" not in file:
# print(root + "/" + file)
transform_one_page(root, Path(os.path.join(root, file)), file)
249 changes: 249 additions & 0 deletions foo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
PTX:DEBUG : Parsed CLI args {'verbose': 3, 'config_file': None, 'component': 'all', 'format': 'html', 'publication_file': 'publication/publication.ptx', 'stringparams': [], 'extra_stylesheet': None, 'method': '', 'xmlid': 'chapter14_complex-numbers', 'server': None, 'data_dir': None, 'out': None, 'dir': 'output/html', 'abort': False, 'tgz': False, 'validate': False, 'xml_file': 'pretext/main.ptx'}
PTX:DEBUG : Python version: 3.10 (expecting 3.8 or newer)
PTX:DEBUG : PreTeXt distribution and xsl directories: /mnt/f/Programming/pretext, /mnt/f/Programming/pretext/xsl
PTX:INFO : parsing possible configuration files: ['/mnt/f/Programming/pretext/pretext/pretext.cfg', '/mnt/f/Programming/pretext/user/mbx.cfg', '/mnt/f/Programming/pretext/user/pretext.cfg']
PTX:DEBUG : configuration files actually used/read: ['/mnt/f/Programming/pretext/pretext/pretext.cfg']
PTX:INFO : using default configuration only
PTX:INFO : custom configuration file not used at /mnt/f/Programming/pretext/user/pretext.cfg
PTX:INFO : dictionary of executables/commands: {'latex': 'latex', 'pdflatex': 'pdflatex', 'xelatex': 'xelatex', 'asy': 'asy', 'mermaid': 'mmdc', 'sage': 'sage', 'pdfpng': 'convert', 'pdfeps': 'pdftops', 'node': 'node', 'liblouis': 'file2brl'}
PTX:INFO : verifying and expanding XML source file: pretext/main.ptx
PTX:INFO : input XML source file expanded to absolute path: /mnt/f/Programming/thinkcpp-rs/pretext/main.ptx
PTX:INFO : verifying and expanding publisher file: publication/publication.ptx
PTX:INFO : input publisher file expanded to absolute path: /mnt/f/Programming/thinkcpp-rs/publication/publication.ptx
PTX:INFO : verifying and expanding input directory: output/html
PTX:INFO : input directory expanded to absolute path: /mnt/f/Programming/thinkcpp-rs/output/html
PTX:INFO : Done examining environment and initializing setup info
PTX:INFO : discovering source file's directory name: /mnt/f/Programming/thinkcpp-rs/pretext
PTX:INFO : verifying and expanding input directory: /mnt/f/Programming/thinkcpp-rs/pretext/../generated-assets
PTX:INFO : input directory expanded to absolute path: /mnt/f/Programming/thinkcpp-rs/generated-assets
PTX:INFO : verifying and expanding input directory: /mnt/f/Programming/thinkcpp-rs/pretext/../assets
PTX:INFO : input directory expanded to absolute path: /mnt/f/Programming/thinkcpp-rs/assets
PTX:INFO : Runestone Services (via PreTeXt repository): version 7.3.3
PTX:INFO : Runestone Services (using newer, via online CDN query): version 7.4.3
PTX:INFO : Using existing Runestone Services located in /mnt/f/Programming/thinkcpp-rs/output/html/_static. Delete Runestone files there to force a fresh download.
PTX:INFO : converting /mnt/f/Programming/thinkcpp-rs/pretext/main.ptx to HTML in /tmp/ptx-t0m5g5um
PTX:INFO : XSL conversion of /mnt/f/Programming/thinkcpp-rs/pretext/main.ptx by /mnt/f/Programming/pretext/xsl/pretext-html.xsl
PTX:DEBUG : XSL conversion via /mnt/f/Programming/pretext/xsl/pretext-html.xsl of /mnt/f/Programming/thinkcpp-rs/pretext/main.ptx to None and/or into directory /tmp/ptx-t0m5g5um with parameters {'altrs-js': 'prefix-runtime.00db6230172ad960.bundle.js:prefix-347.8328b60515045466.bundle.js:prefix-runestone.aa624e4071d017c3.bundle.js', 'altrs-css': 'prefix-347.f9add1ca35d5ad93.css:prefix-runestone.f64dcc3632d7a0c3.css', 'altrs-cdn-url': 'https://runestone.academy/cdn/runestone/', 'altrs-version': '7.4.3', 'rs-local-files': 'yes', 'publisher': '/mnt/f/Programming/thinkcpp-rs/publication/publication.ptx', 'subtree': 'chapter14_complex-numbers'}
PTX:INFO : messages from the log for XSL processing:
PTX:INFO : * ========active-language==========
PTX:INFO : * program
PTX:INFO : * ========get-language==========
PTX:INFO : * label
PTX:INFO : * fourteentwo_editor22
PTX:INFO : * interactive
PTX:INFO : * activecode
PTX:INFO : * langauge
PTX:INFO : * python
PTX:INFO : * line-numbers
PTX:INFO : * yes
PTX:INFO : * original-id
PTX:INFO : * fourteentwo_editor22
PTX:INFO : * assembly-id
PTX:INFO : * fourteentwo_editor22
PTX:INFO : * authored-label
PTX:INFO : * unknown error
PTX:INFO : * unique-id
PTX:INFO : * fourteentwo_editor22
PTX:INFO : * ========no-language==========
PTX:INFO : * ========active-language==========
PTX:INFO : * program
PTX:INFO : * ========get-language==========
PTX:INFO : * label
PTX:INFO : * fourteentwo_editor22
PTX:INFO : * interactive
PTX:INFO : * activecode
PTX:INFO : * langauge
PTX:INFO : * python
PTX:INFO : * line-numbers
PTX:INFO : * yes
PTX:INFO : * original-id
PTX:INFO : * fourteentwo_editor22
PTX:INFO : * assembly-id
PTX:INFO : * fourteentwo_editor22
PTX:INFO : * authored-label
PTX:INFO : * unknown error
PTX:INFO : * unique-id
PTX:INFO : * fourteentwo_editor22
PTX:INFO : * ========no-language==========
PTX:INFO : * ========get-language==========
PTX:INFO : * label
PTX:INFO : * fourteentwo_editor22
PTX:INFO : * interactive
PTX:INFO : * activecode
PTX:INFO : * langauge
PTX:INFO : * python
PTX:INFO : * line-numbers
PTX:INFO : * yes
PTX:INFO : * original-id
PTX:INFO : * fourteentwo_editor22
PTX:INFO : * assembly-id
PTX:INFO : * fourteentwo_editor22
PTX:INFO : * authored-label
PTX:INFO : * unknown error
PTX:INFO : * unique-id
PTX:INFO : * fourteentwo_editor22
PTX:INFO : * ========no-language==========
PTX:INFO : * ========get-language==========
PTX:INFO : * original-id
PTX:INFO : * chapter14_complex-numbers-5
PTX:INFO : * assembly-id
PTX:INFO : * chapter14_complex-numbers-5
PTX:INFO : * unique-id
PTX:INFO : * chapter14_complex-numbers-5
PTX:INFO : * ========no-language==========
PTX:INFO : * ===================
PTX:INFO : * figure
PTX:INFO : * unknown error
PTX:INFO : * unknown error
PTX:INFO : * ========get-language==========
PTX:INFO : * original-id
PTX:INFO : * chapter14_complex-numbers-15
PTX:INFO : * assembly-id
PTX:INFO : * chapter14_complex-numbers-15
PTX:INFO : * unique-id
PTX:INFO : * chapter14_complex-numbers-15
PTX:INFO : * ========no-language==========
PTX:INFO : * ========active-language==========
PTX:INFO : * program
PTX:INFO : * ========get-language==========
PTX:INFO : * label
PTX:INFO : * fourteentwo_editor
PTX:INFO : * interactive
PTX:INFO : * activecode
PTX:INFO : * langauge
PTX:INFO : * python
PTX:INFO : * line-numbers
PTX:INFO : * yes
PTX:INFO : * original-id
PTX:INFO : * fourteentwo_editor
PTX:INFO : * assembly-id
PTX:INFO : * fourteentwo_editor
PTX:INFO : * authored-label
PTX:INFO : * unknown error
PTX:INFO : * unique-id
PTX:INFO : * fourteentwo_editor
PTX:INFO : * ========no-language==========
PTX:INFO : * ========active-language==========
PTX:INFO : * program
PTX:INFO : * ========get-language==========
PTX:INFO : * label
PTX:INFO : * fourteentwo_editor
PTX:INFO : * interactive
PTX:INFO : * activecode
PTX:INFO : * langauge
PTX:INFO : * python
PTX:INFO : * line-numbers
PTX:INFO : * yes
PTX:INFO : * original-id
PTX:INFO : * fourteentwo_editor
PTX:INFO : * assembly-id
PTX:INFO : * fourteentwo_editor
PTX:INFO : * authored-label
PTX:INFO : * unknown error
PTX:INFO : * unique-id
PTX:INFO : * fourteentwo_editor
PTX:INFO : * ========no-language==========
PTX:INFO : * ========get-language==========
PTX:INFO : * label
PTX:INFO : * fourteentwo_editor
PTX:INFO : * interactive
PTX:INFO : * activecode
PTX:INFO : * langauge
PTX:INFO : * python
PTX:INFO : * line-numbers
PTX:INFO : * yes
PTX:INFO : * original-id
PTX:INFO : * fourteentwo_editor
PTX:INFO : * assembly-id
PTX:INFO : * fourteentwo_editor
PTX:INFO : * authored-label
PTX:INFO : * unknown error
PTX:INFO : * unique-id
PTX:INFO : * fourteentwo_editor
PTX:INFO : * ========no-language==========
PTX:INFO : * ===================
PTX:INFO : * listing
PTX:INFO : * unknown error
PTX:INFO : * unknown error
PTX:INFO : * ========active-language==========
PTX:INFO : * program
PTX:INFO : * ========get-language==========
PTX:INFO : * xml:id
PTX:INFO : * fourteenthree_editor
PTX:INFO : * interactive
PTX:INFO : * activecode
PTX:INFO : * line-numbers
PTX:INFO : * yes
PTX:INFO : * original-id
PTX:INFO : * fourteenthree_editor
PTX:INFO : * assembly-id
PTX:INFO : * fourteenthree_editor
PTX:INFO : * label
PTX:INFO : * fourteenthree_editor
PTX:INFO : * unique-id
PTX:INFO : * fourteenthree_editor
PTX:INFO : * ========no-language==========
PTX:INFO : * ========active-language==========
PTX:INFO : * program
PTX:INFO : * ========get-language==========
PTX:INFO : * xml:id
PTX:INFO : * fourteenthree_editor
PTX:INFO : * interactive
PTX:INFO : * activecode
PTX:INFO : * line-numbers
PTX:INFO : * yes
PTX:INFO : * original-id
PTX:INFO : * fourteenthree_editor
PTX:INFO : * assembly-id
PTX:INFO : * fourteenthree_editor
PTX:INFO : * label
PTX:INFO : * fourteenthree_editor
PTX:INFO : * unique-id
PTX:INFO : * fourteenthree_editor
PTX:INFO : * ========no-language==========
PTX:INFO : * ========get-language==========
PTX:INFO : * xml:id
PTX:INFO : * fourteenthree_editor
PTX:INFO : * interactive
PTX:INFO : * activecode
PTX:INFO : * line-numbers
PTX:INFO : * yes
PTX:INFO : * original-id
PTX:INFO : * fourteenthree_editor
PTX:INFO : * assembly-id
PTX:INFO : * fourteenthree_editor
PTX:INFO : * label
PTX:INFO : * fourteenthree_editor
PTX:INFO : * unique-id
PTX:INFO : * fourteenthree_editor
PTX:INFO : * ========no-language==========
PTX:INFO : * ===================
PTX:INFO : * listing
PTX:INFO : * unknown error
PTX:INFO : * unknown error
PTX:INFO : * ========active-language==========
PTX:INFO : * exercise
PTX:INFO : * ========get-language==========
PTX:INFO : * exercise-customization
PTX:INFO : * inline
PTX:INFO : * exercise-interactive
PTX:INFO : * parson
PTX:INFO : * label
PTX:INFO : * question14_3_1
PTX:INFO : * numbered
PTX:INFO : * yes
PTX:INFO : * adaptive
PTX:INFO : * yes
PTX:INFO : * indentation
PTX:INFO : * hide
PTX:INFO : * original-id
PTX:INFO : * question14_3_1
PTX:INFO : * assembly-id
PTX:INFO : * question14_3_1
PTX:INFO : * authored-label
PTX:INFO : * unknown error
PTX:INFO : * unique-id
PTX:INFO : * question14_3_1
PTX:INFO : * ========no-language==========
PTX:INFO : successful application of /mnt/f/Programming/pretext/xsl/pretext-html.xsl
PTX:DEBUG : Temporary directories left behind for inspection: ['/tmp/ptx-t0m5g5um']
4 changes: 2 additions & 2 deletions pretext/Chapter1/first-program.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
this:</p>
<p>The <q>Hello, World.</q> program is a great place to start learning a new language. Observe the
program structure below.</p>
<listing xml:id="first_program_AC_list">
<listing label="first_program_AC_list">
<caption>
This program prints <q>Hello, World.</q> to the output.
</caption>
<program interactive="activecode" label="first_program_AC"
<program interactive="activecode"
line-numbers="yes">
<input><![CDATA[
#include <iostream>
Expand Down
2 changes: 1 addition & 1 deletion pretext/Chapter10/random-seeds.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
sample uses <c>ctime</c> as the syntax to do so is simpler.</p>
</note>

<listing>
<listing label="random-seeds-demo">
<caption>Try this program - it should print a different sequence of numbers each time you run
it. If you remove the srand call, it will generate the same sequence each time.</caption>
<program interactive="activecode">
Expand Down
2 changes: 1 addition & 1 deletion pretext/Chapter10/vector-functions.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
and store them in a vector till he inputs <c>-1</c>, and then display them. In such a case, we do
not know the size of the vector beforehand. So we need wish add new values to the end of a
vector as the user inputs them. We can use then vector function <c>push_back</c> for that purpose.</p>
<listing >
<listing label="vector-from-input">
<caption>A program that reads in numbers, adding each to a vector, until the user inputs -1.</caption>
<program>#include &lt;iostream&gt;
#include &lt;vector&gt;
Expand Down
2 changes: 1 addition & 1 deletion pretext/Chapter12/the-printdeck-function.ptx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
function that prints the contents of the vector. We have seen the
pattern for traversing a vector several times, so the following function
should be familiar:</p>
<listing xml:id="printdeck-code">
<listing xml:id="printdeck-code" label="printdeck-code">
<program>void printDeck(const vector&lt;Card&gt;&amp; deck) {
for (size_t i = 0; i &lt; deck.size(); i++) {
deck[i].print();
Expand Down
Loading

0 comments on commit 9ed7418

Please sign in to comment.