I have a long text, and some list of dict objects which has indexes of this long text. I want to add some strings to these indexes. If I set a loop, indexes change and I must calculate the indexes again. I think this way very confusing. Is there any way add different strings to different indexes in single time?
My sample data:
main_str = 'Lorem Ipsum is simply dummy text of the printing and typesetting industry.'
My indexes list:
indexes_list = [
{
"type": "first_type",
"endOffset": 5,
"startOffset": 0,
},
{
"type": "second_type",
"endOffset": 22,
"startOffset": 16,
}
]
My main purpose: I want to add <span> attributes to given indexes with some color styles based on types. After that I render it on template, directly. Have you another suggestion?
For example I want to create this data according to above variables main_str and indexes_list(Please ignore color part of styles. I provide it dynamically from value of type from indexes_list):
new_str = '<span style="color:#FFFFFF">Lorem</span> Ipsum is <span style="color:#FFFFFF">simply</span> dummy text of the printing and typesetting industry.'