Why does loop.index not work with replace? Good day!

In Craft CMS 3, I'm tring to configure the replacement of tags for markdown via replace, everything works except for the tag {{ loop.index }} 

Please tell me how to properly configure to work correctly {{ loop.index }}?

{{ block.markdownContent|markdown

 |replace('&lt;p&gt;', '&lt;p class="section__paragraph text"&gt;')
 |replace('&lt;h2&gt;', '&lt;h2 class="section__title title"&gt;')
 |replace('&lt;a ', '&lt;a class="link link-color"')
 |replace('&lt;ul&gt;', '&lt;ul class="attention"&gt;')
 |replace('&lt;li&gt;', '&lt;li class="attention__item"&gt;&lt;p class="attention__text"&gt;')
 |replace('&lt;/li&gt; ', '&lt;/p&gt;&lt;/li&gt;')
 |replace('&lt;ol&gt;', '&lt;ol class="remark list"&gt;')
 |replace('&lt;li&gt;', '&lt;li class="remark__item item"&gt;&lt;p class="remark__text"&gt;&lt;span class="remark__label"&gt;{{ loop.index }}&lt;/span&gt;')
 |replace('&lt;/li&gt; ', '&lt;/p&gt;&lt;/li&gt;')|raw }}


Can you advise other ways of realizing this task.
Twig output tags won't work inside of Twig output tags.

You should be using '&lt;li class="remark__item item"&gt;&lt;p class="remark__text"&gt;&lt;span class="remark__label"&gt;'~loop.index~'&lt;/span&gt;'

The overall approach seems a bit heavy-handed though.