Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #8851

Re: emacs lisp text processing example (html5 figure/figcaption)

References <bf6bcb4b-3f87-4dbe-84e4-1fa157871161@k23g2000pri.googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2011-07-05 13:17 -0600
Subject Re: emacs lisp text processing example (html5 figure/figcaption)
Newsgroups comp.lang.python
Message-ID <mailman.641.1309893476.1164.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, Jul 4, 2011 at 12:36 AM, Xah Lee <xahlee@gmail.com> wrote:
> So, a solution by regex is out.

Actually, none of the complications you listed appear to exclude
regexes.  Here's a possible (untested) solution:

<div class="img">
((?:\s*<img src="[^.]+\.(?:jpg|png|gif)" alt="[^"]+" width="[0-9]+"
height="[0-9]+">)+)
\s*<p class="cpt">((?:[^<]|<(?!/p>))+)</p>
\s*</div>

and corresponding replacement string:

<figure>
\1
<figcaption>\2</figcaption>
</figure>

I don't know what dialect Emacs uses for regexes; the above is the
Python re dialect.  I assume it is translatable.  If not, then the
above should at least work with other editors, such as Komodo's
"Find/Replace in Files" command.  I kept the line breaks here for
readability, but for completeness they should be stripped out of the
final regex.

The possibility of nested HTML in the caption is allowed for by using
a negative look-ahead assertion to accept any tag except a closing
</p>.  It would break if you had nested <p> tags, but then that would
be invalid html anyway.

Cheers,
Ian

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

emacs lisp text processing example (html5 figure/figcaption) Xah Lee <xahlee@gmail.com> - 2011-07-03 23:36 -0700
  Re: emacs lisp text processing example (html5 figure/figcaption) "S.Mandl" <StefanMandl@web.de> - 2011-07-04 12:13 -0700
    Re: emacs lisp text processing example (html5 figure/figcaption) Xah Lee <xahlee@gmail.com> - 2011-07-05 12:47 -0700
      Re: emacs lisp text processing example (html5 figure/figcaption) "S.Mandl" <StefanMandl@web.de> - 2011-07-05 14:30 -0700
  Re: emacs lisp text processing example (html5 figure/figcaption) Ian Kelly <ian.g.kelly@gmail.com> - 2011-07-05 13:17 -0600
    Re: emacs lisp text processing example (html5 figure/figcaption) Xah Lee <xahlee@gmail.com> - 2011-07-05 12:46 -0700
    Re: emacs lisp text processing example (html5 figure/figcaption) Xah Lee <xahlee@gmail.com> - 2011-07-05 13:37 -0700
      Re: emacs lisp text processing example (html5 figure/figcaption) Ian Kelly <ian.g.kelly@gmail.com> - 2011-07-05 16:09 -0600

csiph-web