fix(content): robust newline-to-br conversion across all content sources

Root cause: three config.json files (src, templates, host) had different
newline encodings (\n, \\n, raw newlines). The templates version had
double-escaped \\n\\n which survived the simple replace chain.

- Replace \n with <br> in all three config.json files
- Replace raw newlines with <br> in bundled host/voxvera/index.html
- Add _newlines_to_br() helper that handles all encoding variants:
  real newlines, literal \n, already-converted <br>, and mixed content
- Use the helper in all four HTML injection sites in cli.py

Co-Authored-By: Claude Opus 4.6 <[email protected]>
This commit is contained in:
thePR0M3TH3ANandClaude Opus 4.6 committed 2026-03-16 13:17:12 -04:00
1 parent 945557cd0f
commit 6189ae321e
5 files changed
+29 -19

No files matched your search

+25 -8
View File
@@ -44,6 +44,27 @@ DATA_DIR = Path(os.environ.get("VOXVERA_DIR", Path.home()))
CURRENT_LOCALE = {}
def _newlines_to_br(text: str) -> str:
"""Convert all forms of newline encoding to <br> for static HTML output.
Handles: real newlines, literal backslash-n (\\n), and any mix.
Idempotent — already-converted <br> tags are left alone.
"""
# 1. Literal two-character sequences: backslash + n → real newline
s = text.replace("\\n", "\n")
# 2. Real newlines → <br>
s = s.replace("\n", "<br>")
# 3. Collapse any triple+ <br> runs from trailing newlines
while "<br><br><br>" in s:
s = s.replace("<br><br><br>", "<br><br>")
# 4. Strip leading/trailing <br>
while s.startswith("<br>"):
s = s[4:]
while s.endswith("<br>"):
s = s[:-4]
return s
def _template_res(*parts) -> Traversable:
"""Return a Traversable for files under the packaged ``templates`` folder."""
if getattr(sys, 'frozen', False):
@@ -539,8 +560,7 @@ def build_assets(
# Support Markdown-style redaction ~~text~~
val_str = re.sub(r"~~(.*?)~~", r'<span class="redacted">\1</span>', str(value))
# Convert newlines to <br> so line breaks render in static HTML (no JS on Tor)
val_str = val_str.replace("\\n", "\n").replace("\n", "<br>")
val_str = _newlines_to_br(val_str)
html = html.replace(f"{{{{t_landing_{field}}}}}", val_str)
# 2. Statically replace config placeholders {{key}}
@@ -548,8 +568,7 @@ def build_assets(
val_str = str(value)
# Support Markdown-style redaction ~~text~~ for user fields too
val_str = re.sub(r"~~(.*?)~~", r'<span class="redacted">\1</span>', val_str)
# Convert newlines to <br> so line breaks render in static HTML (no JS on Tor)
val_str = val_str.replace("\\n", "\n").replace("\n", "<br>")
val_str = _newlines_to_br(val_str)
html = html.replace(f"{{{{{key}}}}}", val_str)
# Handle optional file attachment logic
@@ -1080,8 +1099,7 @@ def build_site():
# Support Markdown-style redaction ~~text~~
val_str = re.sub(r"~~(.*?)~~", r'<span class="redacted">\1</span>', str(value))
# Convert newlines to <br> so line breaks render in static HTML (no JS on Tor)
val_str = val_str.replace("\\n", "\n").replace("\n", "<br>")
val_str = _newlines_to_br(val_str)
html = html.replace(f"{{{{t_landing_{field}}}}}", val_str)
# 3. Update relative path for download
@@ -1089,8 +1107,7 @@ def build_site():
# 4. Inject site-specific config data (handles any remaining {{key}} placeholders)
for key, value in data.items():
val_str = str(value)
val_str = val_str.replace("\\n", "\n").replace("\n", "<br>")
val_str = _newlines_to_br(str(value))
html = html.replace(f"{{{{{key}}}}}", val_str)
os.makedirs(dest_site, exist_ok=True)
+1 -1
View File
@@ -4,7 +4,7 @@
"title": "TOP SECRET",
"subtitle": "DO ~~NOT~~ DISTRIBUTE",
"headline": "OPERATION VOX VERA",
"content": "Break free from censorship with VoxVera. An anonymous guerrilla marketing and message-spreading tool. Whether online or in the physical world, it can empower you to spread your ideas boldly, shielded by complete anonymity (if you host over Tor). Download the code, design a flyer site, host it online and amplify your message. \n\nUse memetic power to share your ideas in your school, workplace, online communities, or even globally. VoxVera ensures your message resonates far and wide, with tear-off sections featuring unique URLs and QR codes for easy reprinting. \n\nPrivacy can be maintained. Flyers can be shared via the Tor network, protecting hoster and users from censorship.\n\nJoin us in a revolution that values truth and transparency. Together, we can build a network of informed citizens who are unafraid to speak out.\n",
"content": "Break free from censorship with VoxVera. An anonymous guerrilla marketing and message-spreading tool. Whether online or in the physical world, it can empower you to spread your ideas boldly, shielded by complete anonymity (if you host over Tor). Download the code, design a flyer site, host it online and amplify your message.<br><br>Use memetic power to share your ideas in your school, workplace, online communities, or even globally. VoxVera ensures your message resonates far and wide, with tear-off sections featuring unique URLs and QR codes for easy reprinting.<br><br>Privacy can be maintained. Flyers can be shared via the Tor network, protecting hoster and users from censorship.<br><br>Join us in a revolution that values truth and transparency. Together, we can build a network of informed citizens who are unafraid to speak out.",
"url_message": "Get VoxVera and start spreading your message.",
"url": "https://github.com/PR0M3TH3AN/VoxVera",
"tear_off_link": "https://voxvera.org/",
+1 -8
View File
@@ -557,14 +557,7 @@
<h1 id="operation-title-2" data-i18n="landing.headline">OPERATION VOX VERA</h1>
<hr>
<div class="message">
<div class="text-container" id="main-content" contenteditable="false" data-i18n="landing.content">Break free from censorship with VoxVera. An anonymous guerrilla marketing and message-spreading tool. Whether online or in the physical world, it can empower you to spread your ideas boldly, shielded by complete anonymity (if you host over Tor). Download the code, design a flyer site, host it online and amplify your message.
Use memetic power to share your ideas in your school, workplace, online communities, or even globally. VoxVera ensures your message resonates far and wide, with tear-off sections featuring unique URLs and QR codes for easy reprinting.
Privacy can be maintained. Flyers can be shared via the Tor network, protecting hoster and users from censorship.
Join us in a revolution that values truth and transparency. Together, we can build a network of informed citizens who are unafraid to speak out.
</div>
<div class="text-container" id="main-content" contenteditable="false" data-i18n="landing.content">Break free from censorship with VoxVera. An anonymous guerrilla marketing and message-spreading tool. Whether online or in the physical world, it can empower you to spread your ideas boldly, shielded by complete anonymity (if you host over Tor). Download the code, design a flyer site, host it online and amplify your message.<br><br>Use memetic power to share your ideas in your school, workplace, online communities, or even globally. VoxVera ensures your message resonates far and wide, with tear-off sections featuring unique URLs and QR codes for easy reprinting.<br><br>Privacy can be maintained. Flyers can be shared via the Tor network, protecting hoster and users from censorship.<br><br>Join us in a revolution that values truth and transparency. Together, we can build a network of informed citizens who are unafraid to speak out.</div>
<div class="qr-code-body">
<div class="qr-code-url">
+1 -1
View File
@@ -4,7 +4,7 @@
"title": "TOP SECRET",
"subtitle": "DO ~~NOT~~ DISTRIBUTE",
"headline": "OPERATION VOX VERA",
"content": "Break free from censorship with VoxVera. An anonymous guerrilla marketing and message-spreading tool. Whether online or in the physical world, it can empower you to spread your ideas boldly, shielded by complete anonymity (if you host over Tor). Download the code, design a flyer site, host it online and amplify your message. \n\nUse memetic power to share your ideas in your school, workplace, online communities, or even globally. VoxVera ensures your message resonates far and wide, with tear-off sections featuring unique URLs and QR codes for easy reprinting. \n\nPrivacy can be maintained. Flyers can be shared via the Tor network, protecting hoster and users from censorship.\n\nJoin us in a revolution that values truth and transparency. Together, we can build a network of informed citizens who are unafraid to speak out.\n",
"content": "Break free from censorship with VoxVera. An anonymous guerrilla marketing and message-spreading tool. Whether online or in the physical world, it can empower you to spread your ideas boldly, shielded by complete anonymity (if you host over Tor). Download the code, design a flyer site, host it online and amplify your message.<br><br>Use memetic power to share your ideas in your school, workplace, online communities, or even globally. VoxVera ensures your message resonates far and wide, with tear-off sections featuring unique URLs and QR codes for easy reprinting.<br><br>Privacy can be maintained. Flyers can be shared via the Tor network, protecting hoster and users from censorship.<br><br>Join us in a revolution that values truth and transparency. Together, we can build a network of informed citizens who are unafraid to speak out.",
"url_message": "Get VoxVera and start spreading your message.",
"url": "https://github.com/PR0M3TH3AN/VoxVera",
"tear_off_link": "https://voxvera.org/",
+1 -1
View File
@@ -4,7 +4,7 @@
"title": "TOP SECRET",
"subtitle": "DO ~~NOT~~ DISTRIBUTE",
"headline": "OPERATION VOX VERA",
"content": "Break free from censorship with VoxVera. An anonymous guerrilla marketing and message-spreading tool. Whether online or in the physical world, it can empower you to spread your ideas boldly, shielded by complete anonymity (if you host over Tor). Download the code, design a flyer site, host it online and amplify your message.\\n\\nUse memetic power to share your ideas in your school, workplace, online communities, or even globally. VoxVera ensures your message resonates far and wide, with tear-off sections featuring unique URLs and QR codes for easy reprinting.\\n\\nPrivacy can be maintained. Flyers can be shared via the Tor network, protecting hoster and users from censorship.\\n\\nJoin us in a revolution that values truth and transparency. Together, we can build a network of informed citizens who are unafraid to speak out.\n",
"content": "Break free from censorship with VoxVera. An anonymous guerrilla marketing and message-spreading tool. Whether online or in the physical world, it can empower you to spread your ideas boldly, shielded by complete anonymity (if you host over Tor). Download the code, design a flyer site, host it online and amplify your message.<br><br>Use memetic power to share your ideas in your school, workplace, online communities, or even globally. VoxVera ensures your message resonates far and wide, with tear-off sections featuring unique URLs and QR codes for easy reprinting.<br><br>Privacy can be maintained. Flyers can be shared via the Tor network, protecting hoster and users from censorship.<br><br>Join us in a revolution that values truth and transparency. Together, we can build a network of informed citizens who are unafraid to speak out.",
"url_message": "Follow this link to learn more. Use Tor Browser.",
"url": "https://voxvera.org/",
"tear_off_link": "https://voxvera.org/",