Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Run-level content in python-docx?

Tags:

python-docx

I am a bit confused about the concept of 'Run-level content' in python-docx.. I get that if I wanna check whether a paragraph is in bold or not, I need to check the run.bold, but what exactly is it? The official definition is: A run is the object most closely associated with inline content; text, pictures, and other items that are flowed between the block-item boundaries within a paragraph.

So, is it singular character level content in the paragraph? am I missing anything here?

like image 376
Phillysteak Avatar asked Jan 26 '23 13:01

Phillysteak


1 Answers

A simple way to understand a run in Word is a sequence of characters that all share the same character formatting.

So if you have a sentence like this and want a bold word to appear, you can't tell the sentence to be bold (that would bold too much) and you don't want to tell each individual character to be bold (that would bold too-little at a time).

So you group the characters into runs and apply character formatting to the run (and that is juuuust right :).

The example sentence would need three runs. One before the bold word, one for the bold word itself, and one for after the bold word. The middle run would be set bold; the other two would have no special formatting.

There are more things to know about runs, like they are subordinate to a paragraph (so the same run can't start in one paragraph and end in another), but this is the main gist of the concept.

like image 198
scanny Avatar answered Mar 04 '23 23:03

scanny