View Issue Details

IDProjectCategoryView StatusLast Update
0017360ScribusScripterpublic2025-02-25 16:18
Reporterale Assigned To 
PrioritynormalSeverityminorReproducibilityN/A
Status newResolutionopen 
Product Version1.7.0.svn 
Summary0017360: deprecate insertHtmlText() and replace it by one or several "better" functions with better arguments
Descriptioncurrently, insertHtmlText():

- can only insert content from files and not from strings
- does not default to utf-8 as encoding
- does not provide a way to set the encoding (and it's not clearly defined how the encoding is detected)
- can insert content from any supported file format (i've tested it with a markdown file)
- the type of the content depends on the extension of the file
- in the UI the corresponding function is found under "import" and "get text", not "insert".

i'd like to suggest to deprecate this function.

in place of it, i'd like to propose a new function with several named optional arguments:

insertFormattedText(
  source: the filename (path) or the content to be inserted
  [name=None]: the name of the target frame (by default the current selected frame)
  [encoding=None]: if not defined, the encoding is automatically detected from the content (if possible; the default should be utf-8)
  [format=None]: if not defined the format is guessed from the extension (default behavior is '.txt')
  [read_file=True]: if true, the source is a filename; otherwise, source contains the content to be inserted
  [style_prefix=None]: if None, the name of the frame is used;
)

this having been said, if i recall correctly, some of the formats supported by scribus have a pop up asking for more settings.
i still have to check if those differ between formats: if it's the case, it might be better to have one function per format...
(if we need multiple functions, we might keep insertHtmlText() and complete it with the additional arguments)
TagsNo tags attached.
PatchNo

Activities

jirib

2025-02-24 23:04

reporter   ~0052118

IIUC it is just calling `gt.launchImporter', see https://github.com/scribusproject/scribus/blob/b2420e8808a525af5db5ec1ee4a33e0d75f3a7c8/scribus/plugins/scriptplugin/cmdtext.cpp#L669 .

Note, my C++ knowledge is limited.

However, I imported an ODT file with para/char styles and everything was nicely imported!

So, it seems to me s/importHtmlText/importTextFile/ is good enough :-)

jirib

2025-02-24 23:05

reporter   ~0052119

Since it is not exclusively about HTML, IMO it is a kind of bug and a quick solution would be to create a new function name to end this confusion.

ale

2025-02-25 16:18

manager   ~0052122

yes it imports anything, but, as an example, you cannot import from a temporary file, if that file has not the "correct" extension.

and if you already have a string -- as an example to make it simple to insert formatted text by using some inline html --, the only way to insert it, is by using a temporary file...

also, 99% of the files inserted will be utf-8... but there is no way to force the import to use that (and, as wrote above, it's not clear to me, how the encoding is detected).

finally, nice that in your example it worked well.
in the case i had to solve, it was not that way.

i don't recall the details, but it was a simple generated text that needed to be imported into scribus and i had to go through multiple hops to get the text into scribus.
it was rather painful.

Issue History

Date Modified Username Field Change
2025-01-01 11:00 ale New Issue
2025-01-01 11:51 ale Summary deprecate insertHtmlText() and replace it by one or several "better" functions with a => deprecate insertHtmlText() and replace it by one or several "better" functions with better arguments
2025-02-24 23:04 jirib Note Added: 0052118
2025-02-24 23:05 jirib Note Added: 0052119
2025-02-25 16:18 ale Note Added: 0052122