]> git.lyx.org Git - features.git/commitdiff
Update chunk handling to use new inset
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 31 May 2013 09:29:11 +0000 (11:29 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 3 Jun 2013 10:36:35 +0000 (12:36 +0200)
At the same time, rename parse_noweb to parse_chunk.

src/tex2lyx/text.cpp
src/version.h

index 5d90fed629107a823f9eda56a4fdd16baa3514a6..e5b720997d776cf9f384935350e4fdbb647175fd 100644 (file)
@@ -1993,43 +1993,55 @@ void copy_file(FileName const & src, string dstname)
 }
 
 
-/// Parse a NoWeb Chunk section. The initial "<<" is already parsed.
-bool parse_noweb(Parser & p, ostream & os, Context & context)
+/// Parse a literate Chunk section. The initial "<<" is already parsed.
+bool parse_chunk(Parser & p, ostream & os, Context & context)
 {
        // check whether a chunk is possible here.
-       if (!context.new_layout_allowed ||
-           !context.textclass.hasLayout(from_ascii("Chunk"))) {
+       if (!context.textclass.hasInsetLayout(from_ascii("Flex:Chunk"))) {
                return false;
        }
 
        p.pushPosition();
 
        // read the parameters
-       Parser::Arg stuff = p.verbatimStuff(">>=", false);
-       if (!stuff.first) {
+       Parser::Arg const params = p.verbatimStuff(">>=\n", false);
+       if (!params.first) {
                p.popPosition();
                return false;
        }
-       string chunk = "<<" + stuff.second + ">>="
-               + p.verbatimStuff("\n").second + '\n';
 
-       stuff = p.verbatimStuff("\n@");
-       if (!stuff.first) {
+       Parser::Arg const code = p.verbatimStuff("\n@");
+       if (!code.first) {
                p.popPosition();
                return false;
        }
-       chunk += stuff.second + "\n@";
-       string post_chunk = p.verbatimStuff("\n").second + '\n';
+       string const post_chunk = p.verbatimStuff("\n").second + '\n';
        if (post_chunk[0] != ' ' && post_chunk[0] != '\n') {
                p.popPosition();
                return false;
        }
-       chunk += post_chunk;
+       // The last newline read is important for paragraph handling
+       p.putback();
+       p.deparse();
 
-       context.new_paragraph(os);
-       Context newcontext(true, context.textclass,
-               &context.textclass[from_ascii("Chunk")]);
-       output_ert(os, chunk, newcontext);
+       //cerr << "params=[" << params.second << "], code=[" << code.second << "]" <<endl;
+       // We must have a valid layout before outputting the Chunk inset.
+       context.check_layout(os);
+       Context chunkcontext(true, context.textclass);
+       chunkcontext.layout = &context.textclass.plainLayout();
+       begin_inset(os, "Flex Chunk");
+       os << "\nstatus open\n";
+       if (!params.second.empty()) {
+               chunkcontext.check_layout(os);
+               Context paramscontext(true, context.textclass);
+               paramscontext.layout = &context.textclass.plainLayout();
+               begin_inset(os, "Argument 1");
+               os << "\nstatus open\n";
+               output_ert(os, params.second, paramscontext);
+               end_inset(os);
+       }
+       output_ert(os, code.second, chunkcontext);
+       end_inset(os);
 
        p.dropPosition();
        return true;
@@ -2305,16 +2317,16 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
 
                else if (t.asInput() == "<"
                         && p.next_token().asInput() == "<") {
-                       bool has_noweb = false;
+                       bool has_chunk = false;
                        if (noweb_mode) {
                                p.pushPosition();
                                p.get_token();
-                               has_noweb = parse_noweb(p, os, context);
-                               if (!has_noweb)
+                               has_chunk = parse_chunk(p, os, context);
+                               if (!has_chunk)
                                        p.popPosition();
                        }
 
-                       if (!has_noweb) {
+                       if (!has_chunk) {
                                context.check_layout(os);
                                begin_inset(os, "Quotes ");
                                //FIXME: this is a right danish quote;
index 99c446760e5bb22536043640b013ca0e71cb748e..ab712d5875f0c5f9c2b85ec63193b78e434f2adf 100644 (file)
@@ -31,7 +31,7 @@ extern char const * const lyx_version_info;
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
 #define LYX_FORMAT_LYX 474 // rgh: dummy format change for Chunk switch
-#define LYX_FORMAT_TEX2LYX 473
+#define LYX_FORMAT_TEX2LYX 474
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER