1
votes

I have hundreds of list items to code. each list item contains title and description in 2 lines. so what i need to do is wrap 2 lines with a tag. is there any way to do so using sublime text 2? i am using windows OS.

this is the output needed:

<ul>
    <li>
        this is the title
        this is the descrpition
    </li>
    <li>
        this is the title
        this is the descrpition
    </li>
</ul>

raw text looks like this:

this is title
this is description
this is title
this is description

=====

i have tried using ctrl+shift+G and using ul>li* but unfortunately it wraps each line with <li>

if it is possible with sublime text, i actually need this type of structure:

<ul>
    <li>
        <span class="title">this is the title</span>
        <span class="description">this is the descrpition</span>
    </li>
    <li>
        <span class="title">this is the title</span>
        <span class="description">this is the descrpition</span>
    </li>
</ul>
1
Please edit your question to show example input, expected output, and what you have tried so far to solve the problem. - MattDMo
you could use notepad ++ and replace return chars with <li> - Frank_Vr
@Frank_Vr Try the idea you posted and see what you get. Is that result what the OP is asking for? I think you'll find you have missed the point pretty much completely. - jwpfox

1 Answers

0
votes

How about a two step process using find and replace?

I am assuming that:

  • your original text is not indented at all;
  • your indentation is two spaces; and
  • you will handle the wrap with <ul> and resultant indentation yourself after this is done.

Original state:

    this is title
    this is description
    this is title
    this is description

Step one

Ensuring you have enabled regular expression matching do a find and replace using these values.

FIND WHAT :: ((.*\n){1,2})

REPLACE WITH :: <li>\n\1</li>\n

Result:

    <li>
    this is title
    this is description
    </li>
    <li>
    this is title
    this is description
    </li>

Step two

Ensuring you have enabled regular expression matching do a find and replace using these values.

FIND WHAT :: (<li>\n)(.*)\n(.*)

REPLACE WITH :: \1 <span class="title">\2</span>\n <span class="description">\3</span>

Result:

    <li>
      <span class="title">this is title</span>
      <span class="description">this is description</span>
    </li>
    <li>
      <span class="title">this is title</span>
      <span class="description">this is description</span>
    </li>

What do you think?

Close enough to be useful?