I had exactly the same question - and it is possible, if a little finicky - so adding this for anyone else looking in the future. You need Scribus 1.5.6 to use the setCharacterStyles method
Given a text frame with some content - you need to:
- get all the text
- find the position of the text you want to be in superscript
- select the text
- set the style to a character style that has superscript
- move to the next one ..
A bit of brute force in this method - but it worked for me:
# Text markers that can be used to identify where to apply superscript
# ORDINALS = ["0th", "1st", "2nd", "3rd", "4th", "5th", "6th", "7th", "8th", "9th"]
# Character style already defined in my document
# additionalNotesSuperscriptCharStyle = "Additional Note Superscript"
# notesFrame is the selected Text Frame
for superscript in ORDINALS :
# find the ordinal text in the content of the frame - don't have to care about unicode any more
superscriptPosition = getAllText(notesFrame).find(superscript)
while (superscriptPosition > -1) :
superscriptPosition += 1 # increment - so the number is not selected
selectText(superscriptPosition, 2, notesFrame) # all of the ordinals are 2 characters, use calculated length if needed for others
setCharacterStyle(additionalNotesSuperscriptCharStyle, notesFrame) # character style must exist
selectText(0,0,notesFrame) # deselect the text just styled
superscriptPosition = getAllText(notesFrame).find(superscript, superscriptPosition) # find the next ordinal from the current position
Lots of ways to improve that, you could probably use a regex. You could also optionally dynamically create the character style based on the selected text - this is needed if the frame contains multiple paragraph or character styles.
cheers
Rob