From fc8115debe66eb23adde3b1a83acf53d3ac13357 Mon Sep 17 00:00:00 2001 From: Jendrik Seipp Date: Thu, 19 Dec 2024 20:23:43 +0100 Subject: [PATCH] Upgrade to txt2tags 3.9. --- .pre-commit-config.yaml | 2 +- CHANGELOG.md | 3 + dev/generate-help.py | 2 +- rednotebook/external/txt2tags.py | 2912 +++++++++--------------------- rednotebook/gui/exports.py | 2 +- rednotebook/gui/main_window.py | 8 +- rednotebook/gui/menu.py | 2 +- rednotebook/util/markup.py | 12 +- rednotebook/util/pango_markup.py | 2 +- tests/test_markup.py | 6 +- 10 files changed, 828 insertions(+), 2123 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c44b1023c..e0c765933 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -24,7 +24,7 @@ repos: rev: 24.8.0 hooks: - id: black - exclude: ^rednotebook/external/(spellcheck|elibintl).py + exclude: ^rednotebook/external/ # Imports sorter - repo: https://github.com/pycqa/isort diff --git a/CHANGELOG.md b/CHANGELOG.md index 10e026872..b3354f577 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 2.38 (unreleased) +* Upgrade to txt2tags 3.9 (@jendrikseipp). +* # 2.37 (2024-12-18) * Improve bidirectional text support in preview mode (#781, @metemaddar). diff --git a/dev/generate-help.py b/dev/generate-help.py index 54e920383..8a70f60b3 100755 --- a/dev/generate-help.py +++ b/dev/generate-help.py @@ -18,7 +18,7 @@ print( markup.convert( help_text, - "xhtml", + "html", DEFAULT_DATA_DIR, headers=["RedNotebook Documentation", version, ""], options={"toc": 1}, diff --git a/rednotebook/external/txt2tags.py b/rednotebook/external/txt2tags.py index ea8d9e69e..9b6feceb9 100644 --- a/rednotebook/external/txt2tags.py +++ b/rednotebook/external/txt2tags.py @@ -1,28 +1,12 @@ #!/usr/bin/env python # txt2tags - generic text conversion tool -# http://txt2tags.org +# https://txt2tags.org/ +# https://github.com/jendrikseipp/txt2tags # # Copyright 2001-2010 Aurelio Jargas # Copyright 2010-2019 Jendrik Seipp # -# This file is based on txt2tags version 2.6, but has been modified for -# RedNotebook. The changes compared to the upstream version are: -# -# * use spaces instead of tabs -# * support Python 3.6+ in addition to Python 2.7 -# * don't escape underscores in tagged and raw LaTeX text -# * don't use locale-dependent str.capitalize() -# * support SVG images -# -# License: http://www.gnu.org/licenses/gpl-2.0.txt -# Subversion: http://svn.txt2tags.org -# Bug tracker: http://bugs.txt2tags.org -# -######################################################################## -# -# BORING CODE EXPLANATION AHEAD -# -# Just read it if you wish to understand how the txt2tags code works. +# License: GPL2+ (http://www.gnu.org/licenses/gpl-2.0.txt) # ######################################################################## # @@ -58,17 +42,10 @@ # # These functions get information about the input file(s) and take # care of the init processing: -# get_infiles_config(), process_source_file() and convert_this_files() +# process_source_file() and convert_file() # ######################################################################## -# XXX Python coding warning -# Avoid common mistakes: -# - do NOT use newlist=list instead newlist=list[:] -# - do NOT use newdic=dic instead newdic=dic.copy() -# - do NOT use dic[key] instead dic.get(key) -# - do NOT use del dic[key] without has_key() before - # XXX Smart Image Align don't work if the image is a link # Can't fix that because the image is expanded together with the # link, at the linkbank filling moment. Only the image is passed @@ -80,7 +57,7 @@ # different background color. Still don't know how to fix it. # XXX TODO (maybe) -# New mark or macro which expands to an anchor full title. +# New mark which expands to an anchor full title. # It is necessary to parse the full document in this order: # DONE 1st scan: HEAD: get all settings, including %!includeconf # DONE 2nd scan: BODY: expand includes & apply %!preproc @@ -91,51 +68,23 @@ # One solution may be add the titles as postproc rules -############################################################################## - -# User config (1=ON, 0=OFF) - -USE_I18N = 1 # use gettext for i18ned messages? (default is 1) -COLOR_DEBUG = 1 # show debug messages in colors? (default is 1) -BG_LIGHT = 0 # your terminal background color is light (default is 0) -HTML_LOWER = 0 # use lowercased HTML tags instead upper? (default is 0) +import collections +import getopt +import os +import re +import sys ############################################################################## - -# These are all the core Python modules used by txt2tags (KISS!) -import re, os, sys, time, getopt - -# The CSV module is new in Python version 2.3 -try: - import csv -except ImportError: - csv = None - # Program information -my_url = "http://txt2tags.org" +my_url = "https://txt2tags.org" my_name = "txt2tags" -my_email = "verde@aurelio.net" -my_version = "2.6" - -# i18n - just use if available -if USE_I18N: - try: - import gettext - - # If your locale dir is different, change it here - cat = gettext.Catalog("txt2tags", localedir="/usr/share/locale/") - _ = cat.gettext - except: - _ = lambda x: x -else: - _ = lambda x: x +my_email = "jendrikseipp@gmail.com" +__version__ = "3.9" # FLAGS : the conversion related flags , may be used in %!options # OPTIONS : the conversion related options, may be used in %!options # ACTIONS : the other behavior modifiers, valid on command line only -# MACROS : the valid macros with their default values for formatting -# SETTINGS: global miscellaneous settings, valid on RC file only # NO_TARGET: actions that don't require a target specification # NO_MULTI_INPUT: actions that don't accept more than one input file # CONFIG_KEYWORDS: the valid %!key:val keywords @@ -143,111 +92,51 @@ # FLAGS and OPTIONS are configs that affect the converted document. # They usually have also a --no-