Die RTF -Ausgabe zeigt "{Apple0}" anstelle von fettem "Apple" in Libreoffice auf Ubuntu

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Die RTF -Ausgabe zeigt "{Apple0}" anstelle von fettem "Apple" in Libreoffice auf Ubuntu

by Anonymous » 27 Feb 2025, 05:00

Ich schreibe ein Python -Skript, um eine RTF -Datei mit Textauszügen mit einem fett geführten Suchbegriff zu generieren. Das Skript erzeugt erfolgreich die Auszüge mit dem Schlüsselwort, aber der Begriff ist nicht so fett wie beabsichtigt. "0" angehängt)
RAW -RTF -Text: {Apple0} (betrachtet in einem Texteditor)
Ich erwarte, dass {Apple0} {\ b Apple \ b0}, wobei \ b BOLD und \ B0 P0 P0 P0 P. PER RTF -Syntax startet. Mein Python -Code: < /p>

Code: Select all

import re

TERM = "Apple"
RTF_HEADER = r"{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fswiss\fcharset0 Calibri;}}\f0\fs22\par"
RTF_FOOTER = r"}"
BOLD_START = r"{\b "
BOLD_END = r"\b0}"

excerpt = "This is an Apple test."
term_pattern = re.compile(rf"\b{TERM}\b", re.IGNORECASE)
bolded_term = BOLD_START + TERM + BOLD_END  # Intended: {\b Apple\b0}
excerpt_bolded = term_pattern.sub(bolded_term, excerpt)

with open("output.rtf", "w", encoding="utf-8") as f:
f.write(RTF_HEADER + excerpt_bolded + RTF_FOOTER)

Top