ATL_DEV
ATL_DEV

Reputation: 9591

Can Resharper 9 perform pattern search and replace on HTML markup?

I am in the process of restructuring large amounts of MVC code to use Bootstrap. The process is very tedious and error prone because it's easy to clobber the markup. The majority of the code, however, is structurally identical and it could be at least partially automated. If I could somehow search the HTML structure,

  <div class="header">
        <div class="content">
        <h1 class="big">@Model.Foo </h1>
    </div>
    </div>

with

 <div class="panel panel-default">
  <div class="panel-body">
    @Model.Foo;
  </div>
</div>

I understand Resharper 9 has structural search and replace, but I couldn't find any documentation for it. I would guess that this feature would work for HTML, since Resharper can detect errors in the markup based on nesting.

EDIT: I found some documentation on "Search with Pattern", but upon trying it, I couldn't get it to work at all following the examples. In particular, putting any value "CSS Selector" field ignored it.

Upvotes: 0

Views: 128

Answers (1)

citizenmatt
citizenmatt

Reputation: 18583

It should work. In the search pattern dialog, make sure HTML is selected as the target language, and then just type the first HTML block in as the search pattern. You don't mention if the first block is an example, or exactly the code you want to search for. If it's an example, you'll need to add placeholders for other attributes and elements.

Then put the second block in the replace field. Again, if it's verbatim HTML, just copy it in. Otherwise, you can use the placeholders from the search pattern to fill the captured values in.

Upvotes: 1

Related Questions