cerises: Added word wrapping
This commit is contained in:
+10
-4
@@ -1,11 +1,12 @@
|
|||||||
# This file is named that because I am eating cherries :3
|
# This file is named that because I am eating cherries :3
|
||||||
|
|
||||||
import json
|
import json
|
||||||
|
import textwrap
|
||||||
|
|
||||||
with open("cerisesfonts/h1.json", "r") as file:
|
with open("cerisesfonts/h1.json", "r") as file:
|
||||||
font_h1 = json.load(file)
|
font_h1 = json.load(file)
|
||||||
|
|
||||||
def process(text: str) -> str:
|
def process(text: str, wrap_width: int = None) -> str:
|
||||||
lines = text.split("\n")
|
lines = text.split("\n")
|
||||||
inside_code_block = False
|
inside_code_block = False
|
||||||
for i, line in enumerate(lines):
|
for i, line in enumerate(lines):
|
||||||
@@ -17,9 +18,14 @@ def process(text: str) -> str:
|
|||||||
for char in line[2:]:
|
for char in line[2:]:
|
||||||
if char in font_h1:
|
if char in font_h1:
|
||||||
char_data = font_h1[char].split("\n")
|
char_data = font_h1[char].split("\n")
|
||||||
for i2, data_line in enumerate(final_data):
|
if wrap_width and len(final_data[-2]) + len(char_data[0]) > wrap_width:
|
||||||
final_data[i2] = data_line + char_data[i2]
|
final_data.extend(["", ""])
|
||||||
|
final_data[-2] = final_data[-2] + char_data[0]
|
||||||
|
final_data[-1] = final_data[-1] + char_data[1]
|
||||||
lines[i] = "\n".join(final_data)
|
lines[i] = "\n".join(final_data)
|
||||||
|
if line[0:2] != "# ":
|
||||||
|
lines[i] = "\n".join(textwrap.wrap(lines[i], wrap_width, tabsize=2))s
|
||||||
|
|
||||||
return "\n".join(lines)
|
return "\n".join(lines)
|
||||||
|
|
||||||
# print(process("# Hello Guys 123\nThis is a cool Markdown file. Isn't it so cool?\n```\nThis is a code block\n# This is a code comment, not a heading!\n```"))
|
print(process("# Hello Guys 123\nThis is a cool Markdown file. Isn't it so cool?\n```\nThis is a code block\n# This is a code comment, not a heading!\n```", wrap_width=16))
|
||||||
Reference in New Issue
Block a user