On Wednesday 10 December 2003 15:40, Angus Leeming wrote:
>
> \begin_inset Note -> \begin_inset Note Note
> \begin_inset Comment -> \begin_inset Note Comment
> \begin_inset Greyedout -> \begin_inset Note Greyedout
>
> I'll up the file format to 226 and have been thinking about
> lyxconvert_225.py
>
> Currently it's rather ugly (and unfinished). Question what should I
> put in the ...

> def convert_note(lines):
>     i = 0
>     while 1:
>         j = find_token(lines, "\\begin_inset Note", i)
>         if j == -1:
>             j = find_token(lines, "\\begin_inset Comment", i)
>         if j == -1:
>             j = find_token(lines, "\\begin_inset Greyedout", i)
>         if j == -1:
>             break
>
>         # Line j contains a note inset in one of its three forms.
>         # Insert 'Note' immediately after '\begin_inset'.
>         ...
>
>         # update the line count and continue the loop
>         i = j + 1;

  How about

def convert_note(lines):
  i = 0
  while 1:
    i = find_tokens(lines, ["\\begin_inset Note",
                               "\\begin_inset Comment",
                               "\\begin_inset Greyedout"], i)
    if i == -1:
        break

    lines[i] = lines[i][8:] + 'Note ' + lines[i][:8]

  Not tested, but you get the idea.

> More elegant would be to use a regex like
>         note_re = re.compile(r'\(\\begin_inset
> \)\(Note|Comment|Greyedout\)') and to insert 'Note ' between the two
> groups. However, I don't know if the above is a valid python RE. I don't
> know how to do the inserting either...

  It can be done like that, but it it doesn't need to be that way. :-)

-- 
José Abílio

LyX and docbook, a perfect match. :-)

Reply via email to