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)

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!194.109.133.84.MISMATCH!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'completeness': 0.05; 'python': 0.08; 'command.': 0.09; 'skip:\\ 10': 0.09; 'tags,': 0.09; 'am,': 0.13; 'wrote:': 0.15; 'assertion': 0.16; 'editors,': 0.16; 'files"': 0.16; 'string:': 0.16; 'stripped': 0.16; 'subject:example': 0.16; 'cc:addr:python-list': 0.16; 'mon,': 0.16; 'cheers,': 0.19; 'cc:2**0': 0.21; 'cc:no real name:2**0': 0.22; 'header:In-Reply-To:1': 0.22; 'assume': 0.23; 'breaks': 0.23; 'appear': 0.23; 'invalid': 0.25; 'lee': 0.28; 'message- id:@mail.gmail.com': 0.28; 'anyway.': 0.29; 'cc:addr:python.org': 0.30; 'nested': 0.30; 'least': 0.31; 'break': 0.33; 'closing': 0.33; 'none': 0.35; 'replacement': 0.35; 'uses': 0.35; 'subject:text': 0.35; 'skip:" 10': 0.36; 'subject:/': 0.36; 'listed': 0.37; 'but': 0.37; 'using': 0.37; 'received:google.com': 0.38; 'not,': 0.38; 'received:209.85.161': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.38; 'should': 0.39; 'except': 0.39; 'received:209': 0.40; 'possibility': 0.40; 'tag': 0.64; 'here': 0.66; 'kept': 0.67; 'exclude': 0.77; 'dialect': 0.84; 'xah': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=IaCBHMwQqAXsll1kcskWDnh3lLZpKLQ0AEDpxniVons=; b=ftQJ7ywRN9b5ZgIR5E/7Bq/RfYifhP+81MJo0Sz1kkTRt5PtcoIIGM1lc6nDoi4RaP X98e7hWQh6kOvfALIjC4etGiy9HkdTc7ScLjBRfqL6FP6rZK33y4W8AXnEID56zd6fO9 h5FDhIKUQU5al8r9gmeb9oIxEd37dTdBHKcts=
MIME-Version 1.0
In-Reply-To <bf6bcb4b-3f87-4dbe-84e4-1fa157871161@k23g2000pri.googlegroups.com>
References <bf6bcb4b-3f87-4dbe-84e4-1fa157871161@k23g2000pri.googlegroups.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Tue, 5 Jul 2011 13:17:25 -0600
Subject Re: emacs lisp text processing example (html5 figure/figcaption)
To Xah Lee <xahlee@gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.641.1309893476.1164.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1309893476 news.xs4all.nl 21842 [2001:888:2000:d::a6]:38880
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:8851

Show key headers only | 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