A text run array
If an HTML template has the config.xml text_format parameter set to runs then text will formatted using an array. This article provides a brief introduction to how the array is structured and what some examples look like.
If you just plan on using xhtml as the setting for text_format then you don't need to worry about the information in this article.
Below you will see some basic example text followed by the print_r output for the array in PHP. Each paragraph in the text becomes a key in the array. The first paragraph starts at [0].
A paragraph can have properties. For example, meta->style can be code which means the paragraph should be formatted as code. Or the style->list_style might be set to disc in which case it is a bulleted list.
Each paragraph is then broken up into runs. A run is a run of text that shares the same properties, such as color and style. Whenever a property of the text changes a new entry is added to the runs array for the paragraph.
By organizing the text this way you can iterate through a text run array in a straightforward way and format the according to the specification of the format you are exporting to.
Example text 1
This is some example text.
This is another paragraph in the example text.
Text run array 1
Array
(
[0] => stdClass Object
(
[metadata] => stdClass Object
(
[style] =>
)
[runs] => Array
(
[0] => stdClass Object
(
[style] => stdClass Object
(
[color] =>
[font_family] =>
[font_size] =>
[font_styles] =>
[text_shift] =>
[link] =>
)
[metadata] => stdClass Object
(
[style] =>
)
[text] => This is some
)
[1] => stdClass Object
(
[style] => stdClass Object
(
[color] =>
[font_family] =>
[font_size] =>
[font_styles] => bold,italic
[text_shift] =>
[link] =>
)
[metadata] => stdClass Object
(
[style] =>
)
[text] => example
)
[2] => stdClass Object
(
[style] => stdClass Object
(
[color] =>
[font_family] =>
[font_size] =>
[font_styles] =>
[text_shift] =>
[link] =>
)
[metadata] => stdClass Object
(
[style] =>
)
[text] => text.
)
)
[style] => stdClass Object
(
[align] =>
[list_depth] => 0
[list_style] =>
[list_index] => 0
[left_indent] => 0
)
)
[1] => stdClass Object
(
[metadata] => stdClass Object
(
[style] =>
)
[runs] => Array
(
[0] => stdClass Object
(
[style] => stdClass Object
(
[color] =>
[font_family] =>
[font_size] =>
[font_styles] =>
[text_shift] =>
[link] =>
)
[metadata] => stdClass Object
(
[style] =>
)
[text] => This is another paragraph in the example text.
)
)
[style] => stdClass Object
(
[align] =>
[list_depth] => 0
[list_style] =>
[list_index] => 0
[left_indent] => 0
)
)
)
More extensive example
Below is a more extensive example that uses lists and code.
Example text 2
This is some introductory text.
- List item
- List item
The text continues on.
- List item
- List item
- List item
- List item
Some more text.
- List item with hard coded start number.
This is some code.
Text run array 2
Array
(
[0] => stdClass Object
(
[metadata] => stdClass Object
(
[style] =>
)
[runs] => Array
(
[0] => stdClass Object
(
[style] => stdClass Object
(
[color] =>
[font_family] =>
[font_size] =>
[font_styles] =>
[text_shift] =>
)
[text] => This is
)
[1] => stdClass Object
(
[style] => stdClass Object
(
[color] =>
[font_family] =>
[font_size] =>
[font_styles] => italic
[text_shift] =>
)
[text] => some
)
[2] => stdClass Object
(
[style] => stdClass Object
(
[color] =>
[font_family] =>
[font_size] =>
[font_styles] =>
[text_shift] =>
)
[text] =>
)
[3] => stdClass Object
(
[style] => stdClass Object
(
[color] =>
[font_family] =>
[font_size] =>
[font_styles] => bold,italic
[text_shift] =>
)
[text] => introductory
)
[4] => stdClass Object
(
[style] => stdClass Object
(
[color] =>
[font_family] =>
[font_size] =>
[font_styles] =>
[text_shift] =>
)
[text] => text.
)
)
[style] => stdClass Object
(
[align] =>
[list_depth] => 0
[list_style] =>
[list_index] => 0
)
)
[1] => stdClass Object
(
[metadata] => stdClass Object
(
[style] =>
)
[runs] => Array
(
[0] => stdClass Object
(
[style] => stdClass Object
(
[color] =>
[font_family] =>
[font_size] =>
[font_styles] =>
[text_shift] =>
)
[text] => List item
)
)
[style] => stdClass Object
(
[align] =>
[list_depth] => 1
[list_style] => disc
[list_index] => 0
)
)
[2] => stdClass Object
(
[metadata] => stdClass Object
(
[style] =>
)
[runs] => Array
(
[0] => stdClass Object
(
[style] => stdClass Object
(
[color] =>
[font_family] =>
[font_size] =>
[font_styles] =>
[text_shift] =>
)
[text] => List item
)
)
[style] => stdClass Object
(
[align] =>
[list_depth] => 1
[list_style] => disc
[list_index] => 0
)
)
[3] => stdClass Object
(
[metadata] => stdClass Object
(
[style] =>
)
[runs] => Array
(
[0] => stdClass Object
(
[style] => stdClass Object
(
[color] =>
[font_family] =>
[font_size] =>
[font_styles] =>
[text_shift] =>
)
[text] => The text
)
[1] => stdClass Object
(
[style] => stdClass Object
(
[color] => 255,7,44
[font_family] =>
[font_size] =>
[font_styles] =>
[text_shift] =>
)
[text] => continues
)
[2] => stdClass Object
(
[style] => stdClass Object
(
[color] =>
[font_family] =>
[font_size] =>
[font_styles] =>
[text_shift] =>
)
[text] => on.
)
)
[style] => stdClass Object
(
[align] =>
[list_depth] => 0
[list_style] =>
[list_index] => 0
)
)
[4] => stdClass Object
(
[metadata] => stdClass Object
(
[style] =>
)
[runs] => Array
(
[0] => stdClass Object
(
[style] => stdClass Object
(
[color] =>
[font_family] =>
[font_size] =>
[font_styles] =>
[text_shift] =>
)
[text] => List item
)
)
[style] => stdClass Object
(
[align] =>
[list_depth] => 1
[list_style] => decimal
[list_index] => 0
)
)
[5] => stdClass Object
(
[metadata] => stdClass Object
(
[style] =>
)
[runs] => Array
(
[0] => stdClass Object
(
[style] => stdClass Object
(
[color] =>
[font_family] =>
[font_size] =>
[font_styles] =>
[text_shift] =>
)
[text] => List item
)
)
[style] => stdClass Object
(
[align] =>
[list_depth] => 2
[list_style] => decimal
[list_index] => 0
)
)
[6] => stdClass Object
(
[metadata] => stdClass Object
(
[style] =>
)
[runs] => Array
(
[0] => stdClass Object
(
[style] => stdClass Object
(
[color] =>
[font_family] =>
[font_size] =>
[font_styles] =>
[text_shift] =>
)
[text] => List item
)
)
[style] => stdClass Object
(
[align] =>
[list_depth] => 2
[list_style] => decimal
[list_index] => 0
)
)
[7] => stdClass Object
(
[metadata] => stdClass Object
(
[style] =>
)
[runs] => Array
(
[0] => stdClass Object
(
[style] => stdClass Object
(
[color] =>
[font_family] =>
[font_size] =>
[font_styles] =>
[text_shift] =>
)
[text] => List item
)
)
[style] => stdClass Object
(
[align] =>
[list_depth] => 1
[list_style] => decimal
[list_index] => 0
)
)
[8] => stdClass Object
(
[metadata] => stdClass Object
(
[style] =>
)
[runs] => Array
(
[0] => stdClass Object
(
[style] => stdClass Object
(
[color] =>
[font_family] =>
[font_size] =>
[font_styles] =>
[text_shift] =>
)
[text] => Some more text.
)
)
[style] => stdClass Object
(
[align] =>
[list_depth] => 0
[list_style] =>
[list_index] => 0
)
)
[9] => stdClass Object
(
[metadata] => stdClass Object
(
[style] =>
)
[runs] => Array
(
[0] => stdClass Object
(
[style] => stdClass Object
(
[color] =>
[font_family] =>
[font_size] =>
[font_styles] =>
[text_shift] =>
)
[text] => List item with hard coded start number.
)
)
[style] => stdClass Object
(
[align] =>
[list_depth] => 1
[list_style] => decimal
[list_index] => 0
)
)
[10] => stdClass Object
(
[metadata] => stdClass Object
(
[style] => code
)
[runs] => Array
(
[0] => stdClass Object
(
[style] => stdClass Object
(
[color] =>
[font_family] => Courier
[font_size] =>
[font_styles] =>
[text_shift] =>
)
[text] => This is some code.
)
)
[style] => stdClass Object
(
[align] =>
[list_depth] => 0
[list_style] =>
[list_index] => 0
)
)
)
0 Comments
Add your comment