On 02/28/2014 05:35 AM, Rainer M Krug wrote:
Rob Oakes <lyx-de...@oak-tree.us> writes:
Dear Developers,
I've been following this conversation from the shadows, but I had one
thought that they be relevant.
I think everyone agrees that we want to avoid reimplementing the
internal logic of a LyX document. While thinking about what might be
the best way to implement a converter, it occurred to me that it might
be worthwhile to implement the converters as clients that are able to
use a LyX server session.
This comes close to my thought about an API, but it would be even better
in the sense of more versatile and easier usable by external tools.
The server - client approach would be the optimal and most flexible approach.
For export, the server could load a document, provide data about inset
and paragraph contents, and the client could then convert the logical
representation to docx or odf. For import, the process might work in
reverse. The importer reads in the data from the document, translates
it to a logical format that could be consumed by the server, and the
server creates a new document. Document internals remain internal to
LyX, while the server-client communicate over a well-defined protocol
to interactively build the document.
This would be the best approach, as the internals are hidden in LyX, and
the external clients only ask the same questions to retrieve the content
they need to do what they want to do.
It would also open many more options, e.g. web based editing.
The "building the document" part is already do-able. Every editing
action is an LFUN. Try it in the minibuffer:
layout-section Section 1
break-paragraph
self-insert This is the contents.
footnote-insert
self-insert This is a footnote.
char-forward
self-insert That's all folks.
There's a bit of a problem here: There's no easy way to insert a space
after the footnote, from what I can see.
I'm not sure I understand, conceptually, what the API would look like
going the other direction. The obvious way to "provide data about inset
and paragraph contents" would be to send the client a copy of the LyX
file. I mean, we have to serialize the data somehow, which is something
LyX even does internally. And the serialization looks just like the LyX
file. That allows us to reuse the code that reads the LyX file to read
serialized data produced internally.
Richard