To provide for weaving in plain text format, which is not very interesting, but ought to be available.


§1. Creation.

void PlainText::create(void) {
    weave_format *wf = Formats::create_weave_format(I"plain", I".txt");
    METHOD_ADD(wf, RENDER_FOR_MTID, PlainText::render);
}

§2. Methods. For documentation, see "Weave Fornats".

typedef struct PlainText_render_state {
    struct text_stream *OUT;
    struct weave_order *wv;
} PlainText_render_state;

void PlainText::render(weave_format *self, text_stream *OUT, heterogeneous_tree *tree) {
    PlainText_render_state prs;
    prs.OUT = OUT;
    weave_document_node *C = RETRIEVE_POINTER_weave_document_node(tree->root->content);
    prs.wv = C->wv;
    Trees::traverse_from(tree->root, &PlainText::render_visit, (void *) &prs, 0);
}

int PlainText::render_visit(tree_node *N, void *state, int L) {
    PlainText_render_state *prs = (PlainText_render_state *) state;
    text_stream *OUT = prs->OUT;
    if ((N->type == weave_document_node_type) ||
        (N->type == weave_head_node_type) ||
        (N->type == weave_body_node_type) ||
        (N->type == weave_tail_node_type) ||
        (N->type == weave_chapter_title_page_node_type) ||
        (N->type == weave_chapter_footer_node_type) ||
        (N->type == weave_figure_node_type) ||
        (N->type == weave_audio_node_type) ||
        (N->type == weave_video_node_type) ||
        (N->type == weave_download_node_type) ||
        (N->type == weave_material_node_type) ||
        (N->type == weave_chapter_node_type) ||
        (N->type == weave_carousel_slide_node_type) ||
        (N->type == weave_toc_node_type) ||
        (N->type == weave_toc_line_node_type) ||
        (N->type == weave_grammar_index_node_type) ||
        (N->type == weave_inline_node_type)) Render nothing2.12

    else if (N->type == weave_verbatim_node_type) Render verbatim2.11
    else if (N->type == weave_chapter_header_node_type) Render chapter header2.1
    else if (N->type == weave_section_header_node_type) Render header2.2
    else if (N->type == weave_section_footer_node_type) Render footer2.3
    else if (N->type == weave_section_purpose_node_type) Render purpose2.4
    else if (N->type == weave_subheading_node_type) Render subheading2.5
    else if (N->type == weave_bar_node_type) Render bar2.6
    else if (N->type == weave_pagebreak_node_type) Render pagebreak2.7
    else if (N->type == weave_linebreak_node_type) Render linebreak2.8
    else if (N->type == weave_paragraph_heading_node_type) Render paragraph heading2.9
    else if (N->type == weave_endnote_node_type) Render endnote2.10
    else if (N->type == weave_embed_node_type) Render embed2.13
    else if (N->type == weave_pmac_node_type) Render pmac2.14
    else if (N->type == weave_vskip_node_type) Render vskip2.15
    else if (N->type == weave_section_node_type) Render section2.16
    else if (N->type == weave_code_line_node_type) Render code line2.17
    else if (N->type == weave_function_usage_node_type) Render function usage2.18
    else if (N->type == weave_commentary_node_type) Render commentary2.19
    else if (N->type == weave_defn_node_type) Render defn2.20
    else if (N->type == weave_source_code_node_type) Render source code2.21
    else if (N->type == weave_url_node_type) Render URL2.22
    else if (N->type == weave_footnote_cue_node_type) Render footnote cue2.23
    else if (N->type == weave_begin_footnote_text_node_type) Render footnote text2.24
    else if (N->type == weave_display_line_node_type) Render display line2.25
    else if (N->type == weave_function_defn_node_type) Render function defn2.26
    else if (N->type == weave_item_node_type) Render item2.27
    else if (N->type == weave_locale_node_type) Render locale2.28
    else if (N->type == weave_maths_node_type) Render maths2.29

    else internal_error("unable to render unknown node");
    return TRUE;
}

§2.1. Render chapter header2.1 =

    weave_chapter_header_node *C = RETRIEVE_POINTER_weave_chapter_header_node(N->content);
    WRITE("%S\n\n", C->chap->md->ch_title);
    section *S;
    LOOP_OVER_LINKED_LIST(S, section, C->chap->sections)
        WRITE("  %S\n    %S\n",
            S->md->sect_title, S->sect_purpose);
    WRITE("\n");

§2.2. Render header2.2 =

    weave_section_header_node *C = RETRIEVE_POINTER_weave_section_header_node(N->content);
    WRITE("%S\n\n", C->sect->md->sect_title);

§2.3. Render footer2.3 =

    WRITE("\n\n");

§2.4. Render purpose2.4 =

    weave_section_purpose_node *C = RETRIEVE_POINTER_weave_section_purpose_node(N->content);
    WRITE("%S\n\n", C->purpose);

§2.5. Render subheading2.5 =

    weave_subheading_node *C = RETRIEVE_POINTER_weave_subheading_node(N->content);
    WRITE("%S\n\n", C->text);

§2.6. Render bar2.6 =

    WRITE("\n----------------------------------------------------------------------\n\n");

§2.7. Render pagebreak2.7 =

    ;

§2.8. Render linebreak2.8 =

    WRITE("\n");

§2.9. Render paragraph heading2.9 =

    weave_paragraph_heading_node *C = RETRIEVE_POINTER_weave_paragraph_heading_node(N->content);
    WRITE("\n");
    WRITE("%S%S", C->para->ornament, C->para->paragraph_number);
    if (Str::len(C->para->heading_text) > 0) WRITE(" %S", C->para->heading_text);
    WRITE(".  ");

§2.10. Render endnote2.10 =

    Recurse tne renderer through children nodes2.10.1;
    WRITE("\n");
    return FALSE;

§2.11. Render verbatim2.11 =

    weave_verbatim_node *C = RETRIEVE_POINTER_weave_verbatim_node(N->content);
    WRITE("%S", C->content);

§2.12. Render nothing2.12 =

    ;

§2.13. Render embed2.13 =

    weave_embed_node *C = RETRIEVE_POINTER_weave_embed_node(N->content);
    WRITE("[See %S video with ID %S.]\n", C->service, C->ID);

§2.14. Render pmac2.14 =

    weave_pmac_node *C = RETRIEVE_POINTER_weave_pmac_node(N->content);
    WRITE("<%S (%S)>%s",
        C->pmac->macro_name, C->pmac->defining_paragraph->paragraph_number,
        (C->defn)?" =":"");

§2.15. Render vskip2.15 =

    WRITE("\n");

§2.16. Render section2.16 =

    weave_section_node *C = RETRIEVE_POINTER_weave_section_node(N->content);
    LOG("It was %d\n", C->allocation_id);

§2.17. Render code line2.17 =

    for (tree_node *M = N->child; M; M = M->next)
        Trees::traverse_from(M, &PlainText::render_visit, (void *) prs, L+1);
    WRITE("\n");
    return FALSE;

§2.18. Render function usage2.18 =

    weave_function_usage_node *C = RETRIEVE_POINTER_weave_function_usage_node(N->content);
    WRITE("%S", C->fn->function_name);
    return FALSE;

§2.19. Render commentary2.19 =

    weave_commentary_node *C = RETRIEVE_POINTER_weave_commentary_node(N->content);
    if (C->in_code) WRITE("  ");
    WRITE("%S", C->text);
    if (C->in_code) WRITE(" */ ");

§2.20. Render defn2.20 =

    weave_defn_node *C = RETRIEVE_POINTER_weave_defn_node(N->content);
    WRITE("%S ", C->keyword);

§2.21. Render source code2.21 =

    weave_source_code_node *C = RETRIEVE_POINTER_weave_source_code_node(N->content);
    WRITE("%S", C->matter);

§2.22. Render URL2.22 =

    weave_url_node *C = RETRIEVE_POINTER_weave_url_node(N->content);
    WRITE("%S", C->url);

§2.23. Render footnote cue2.23 =

    weave_footnote_cue_node *C = RETRIEVE_POINTER_weave_footnote_cue_node(N->content);
    WRITE("[%S]", C->cue_text);

§2.24. Render footnote text2.24 =

    WRITE("\n");

§2.25. Render display line2.25 =

    weave_display_line_node *C = RETRIEVE_POINTER_weave_display_line_node(N->content);
    WRITE("    %S\n", C->text);

§2.26. Render function defn2.26 =

    weave_function_defn_node *C = RETRIEVE_POINTER_weave_function_defn_node(N->content);
    WRITE("%S", C->fn->function_name);
    return TRUE;

§2.27. Render item2.27 =

    weave_item_node *C = RETRIEVE_POINTER_weave_item_node(N->content);
    for (int i=1; i<C->depth; i++) WRITE("  ");
    WRITE("(%S) ", C->label);

§2.28. Render locale2.28 =

    weave_locale_node *C = RETRIEVE_POINTER_weave_locale_node(N->content);
    WRITE("%S%S", C->par1->ornament, C->par1->paragraph_number);
    if (C->par2) WRITE("-%S", C->par2->paragraph_number);

§2.29. Render maths2.29 =

    weave_maths_node *C = RETRIEVE_POINTER_weave_maths_node(N->content);
    if (C->displayed) WRITE("\n");
    WRITE("%S", C->content);
    if (C->displayed) WRITE("\n\n");

§2.10.1. Recurse tne renderer through children nodes2.10.1 =

    for (tree_node *M = N->child; M; M = M->next)
        Trees::traverse_from(M, &PlainText::render_visit, (void *) prs, L+1);