remove styling module
This commit is contained in:
parent
b51ce330ee
commit
2bf6273212
@ -13,7 +13,52 @@ from spip2md.spipobjects import (
|
|||||||
Article,
|
Article,
|
||||||
Rubrique,
|
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
|
# Query the DB to retrieve all sections without parent, sorted by publication date
|
||||||
|
@ -9,6 +9,7 @@ from peewee import BigAutoField, DateTimeField, ModelSelect
|
|||||||
from slugify import slugify
|
from slugify import slugify
|
||||||
from yaml import dump
|
from yaml import dump
|
||||||
|
|
||||||
|
from spip2md import BLUE, BOLD, GREEN, RED, YELLOW, highlight, indent, ss, style
|
||||||
from spip2md.config import CFG
|
from spip2md.config import CFG
|
||||||
from spip2md.converters import convert, link_document, unknown_chars
|
from spip2md.converters import convert, link_document, unknown_chars
|
||||||
from spip2md.database import (
|
from spip2md.database import (
|
||||||
@ -19,7 +20,6 @@ from spip2md.database import (
|
|||||||
SpipDocumentsLiens,
|
SpipDocumentsLiens,
|
||||||
SpipRubriques,
|
SpipRubriques,
|
||||||
)
|
)
|
||||||
from spip2md.styling import BLUE, BOLD, GREEN, RED, YELLOW, highlight, indent, ss, style
|
|
||||||
|
|
||||||
|
|
||||||
class SpipWritable:
|
class SpipWritable:
|
||||||
|
@ -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="")
|
|
Loading…
Reference in New Issue
Block a user