How to use anchor link in escapeHtml text in magento 2?

Magento escapeHtml() method used to define translate specific text messages in the template files.

You can use the escapeHtml() function to define normal as well as HTML text to translate out of the box in the template.

In the method, the first argument takes data as a text message and the second argument is the array value of specific HTML tags to escape from the string.

You can check the resultant message for the add-to-compare using the escape HTML method,

<?= $block->escapeHtml(
    __(
        'You added product %1 to the <a href="%2">comparison list</a>.',
        $block->getData('product_name'),
        $block->getData('compare_list_url')
    ),
    ['a']
); ?>

In the above method, If we don’t pass the [‘a’] array then it will display the entire anchor tag also in the result.

You can prevent anchor tag HTML from the result by passing the array values of specific HTML tags.