From 2bf6273212a0fec0768fe05514d2c90f797f0e44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guilhem=20Faur=C3=A9?= Date: Fri, 26 May 2023 11:18:40 +0200 Subject: [PATCH] remove styling module --- spip2md/__init__.py | 47 +++++++++++++++++++++++++++++++++++++++++- spip2md/spipobjects.py | 2 +- spip2md/styling.py | 47 ------------------------------------------ 3 files changed, 47 insertions(+), 49 deletions(-) delete mode 100644 spip2md/styling.py diff --git a/spip2md/__init__.py b/spip2md/__init__.py index 7f41e8b..b194edc 100644 --- a/spip2md/__init__.py +++ b/spip2md/__init__.py @@ -13,7 +13,52 @@ from spip2md.spipobjects import ( Article, Rubrique, ) -from spip2md.styling import highlight, style + +# Define styles +BOLD = 1 # Bold +ITALIC = 3 # Italic +UNDER = 4 # Underline +# Define colors +RED = 91 # Red +GREEN = 92 # Green +YELLOW = 93 # Yellow +BLUE = 94 # Blue +C0 = 95 # Color +C1 = 96 # Color +C2 = 96 # Color + + +# Print a stylized string, without trailing newline +def style(string: str, *args: int, end: str = "") -> None: + esc = "\033[" # Terminal escape sequence, needs to be closed by "m" + if len(args) == 0: + params: str = "1;" # Defaults to bold + else: + params: str = "" + for a in args: + params += str(a) + ";" + print(esc + params[:-1] + "m" + string + esc + "0m", end=end) + + +# Print a string, highlighting every substring starting at start_stop[x][0] … +def highlight(string: str, *start_stop: tuple[int, int], end: str = "") -> None: + previous_stop = 0 + for start, stop in start_stop: + print(string[previous_stop:start], end="") + style(string[start:stop], BOLD, RED) + previous_stop = stop + print(string[previous_stop:], end=end) + + +# Plural ? +def ss(nb: int) -> str: + return "s" if nb > 1 else "" + + +# Indent with 2 spaces +def indent(nb: int = 1) -> None: + for _ in range(nb): + print(" ", end="") # Query the DB to retrieve all sections without parent, sorted by publication date diff --git a/spip2md/spipobjects.py b/spip2md/spipobjects.py index dc0cb09..3c1b76d 100644 --- a/spip2md/spipobjects.py +++ b/spip2md/spipobjects.py @@ -9,6 +9,7 @@ from peewee import BigAutoField, DateTimeField, ModelSelect from slugify import slugify from yaml import dump +from spip2md import BLUE, BOLD, GREEN, RED, YELLOW, highlight, indent, ss, style from spip2md.config import CFG from spip2md.converters import convert, link_document, unknown_chars from spip2md.database import ( @@ -19,7 +20,6 @@ from spip2md.database import ( SpipDocumentsLiens, SpipRubriques, ) -from spip2md.styling import BLUE, BOLD, GREEN, RED, YELLOW, highlight, indent, ss, style class SpipWritable: diff --git a/spip2md/styling.py b/spip2md/styling.py deleted file mode 100644 index bd95215..0000000 --- a/spip2md/styling.py +++ /dev/null @@ -1,47 +0,0 @@ -# SPIP website to plain Markdown files converter, Copyright (C) 2023 Guilhem Fauré -# pyright: strict -# Define styles -BOLD = 1 # Bold -ITALIC = 3 # Italic -UNDER = 4 # Underline -# Define colors -RED = 91 # Red -GREEN = 92 # Green -YELLOW = 93 # Yellow -BLUE = 94 # Blue -C0 = 95 # Color -C1 = 96 # Color -C2 = 96 # Color - - -# Print a stylized string, without trailing newline -def style(string: str, *args: int, end: str = "") -> None: - esc = "\033[" # Terminal escape sequence, needs to be closed by "m" - if len(args) == 0: - params: str = "1;" # Defaults to bold - else: - params: str = "" - for a in args: - params += str(a) + ";" - print(esc + params[:-1] + "m" + string + esc + "0m", end=end) - - -# Print a string, highlighting every substring starting at start_stop[x][0] … -def highlight(string: str, *start_stop: tuple[int, int], end: str = "") -> None: - previous_stop = 0 - for start, stop in start_stop: - print(string[previous_stop:start], end="") - style(string[start:stop], BOLD, RED) - previous_stop = stop - print(string[previous_stop:], end=end) - - -# Plural ? -def ss(nb: int) -> str: - return "s" if nb > 1 else "" - - -# Indent with 2 spaces -def indent(nb: int = 1) -> None: - for _ in range(nb): - print(" ", end="")