- // We use new_paragraph instead of check_end_layout because the stuff
- // following the noweb chunk needs to start with a \begin_layout.
- // This may create a new paragraph even if there was none in the
- // noweb file, but the alternative is an invalid LyX file. Since
- // noweb code chunks are implemented with a layout style in LyX they
- // always must be in an own paragraph.
- context.new_paragraph(os);
- Context newcontext(true, context.textclass,
- &context.textclass[from_ascii("Chunk")]);
- newcontext.check_layout(os);
- os << name;
- while (p.good()) {
- Token const & t = p.get_token();
- // We abuse the parser a bit, because this is no TeX syntax
- // at all.
- if (t.cat() == catEscape)
- os << subst(t.asInput(), "\\", "\n\\backslash\n");
- else {
- ostringstream oss;
- Context tmp(false, context.textclass,
- &context.textclass[from_ascii("Chunk")]);
- tmp.need_end_layout = true;
- tmp.check_layout(oss);
- os << subst(t.asInput(), "\n", oss.str());
- }
- // The chunk is ended by an @ at the beginning of a line.
- // After the @ the line may contain a comment and/or
- // whitespace, but nothing else.
- if (t.asInput() == "@" && p.prev_token().cat() == catNewline &&
- (p.next_token().cat() == catSpace ||
- p.next_token().cat() == catNewline ||
- p.next_token().cat() == catComment)) {
- while (p.good() && p.next_token().cat() == catSpace)
- os << p.get_token().asInput();
- if (p.next_token().cat() == catComment)
- // The comment includes a final '\n'
- os << p.get_token().asInput();
- else {
- if (p.next_token().cat() == catNewline)
- p.get_token();
- os << '\n';
- }
- break;
- }