Author Topic: Parseing text (within paragraphs, withing text frames)  (Read 1611 times)

ancientgeek

  • Newbie
  • *
  • Posts: 2
  • Karma: 0
  • Scribus User
Parseing text (within paragraphs, withing text frames)
« on: October 12, 2014, 11:47:34 am »
I wish parse all the text within a Scribus document. I assume that I will have to traverse the pages, the text frames within the page, the paragraphs within the text frames, the characters within the paragraph.
I would then like to apply UI defined character styles to selected chunks of characters within each paragraph. The documents are books of plays with a few hundred pages.

FYI. I maintained compilers for 20 years and have nearly 100,000 lines of Python code, some of which relate to special purpose compilers for microprocessors.

I am trying to overcome the lack of character style importing from ODT. I can detect, by character syntax, the presence of stage directions, lighting tech notes, and sound tech notes, which must be cast to specific character styles within paragraphs with "dialog" style attached.

I notice that the SLA files are just XML. Maybe I should do this outside of Scribus?

Greg P

  • Newbie
  • *
  • Posts: 11
  • Karma: 0
  • Scribus User
Re: Parseing text (within paragraphs, withing text frames)
« Reply #1 on: October 12, 2014, 04:19:01 pm »
As a starting point, you might have a look at Autoquote, one of the scripts included with Scribus, and also on the wiki http://wiki.scribus.net/canvas/En%2Bemdash.py

Both of these scan a text frame at the atomic level, character by character, so one could go from there to match some string.
You can then use the setStyle() command to apply your style to selected text.

I have to say though that I don't know if Scripter is the way to go. From Story Editor, there is a Search/Replace function under Edit, which will search for a string and allow you to replace with altered text or style.

vltreude

  • Newbie
  • *
  • Posts: 23
  • Karma: 0
  • Scribus User
Re: Parseing text (within paragraphs, withing text frames)
« Reply #2 on: June 13, 2015, 06:58:42 pm »
I need to do a very similar task, the difference being that I'm not a python expert.
I was excited about the search/replace suggestion, but I don't think it will work for my purposes.
First of all, it doesn't appear to support regular expressions. I need to match the characters "<<" and ">>" and all the text in between.
Secondly, I'm trying to change the selected characters to italics. This would require a character style rather than a paragraph style. The latter would set my entire paragraph to italics, which I don't want to do.
Is my conclusion correct, or is there some feature I've missed?