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


§1. Creation.

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

§2. Methods.

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

void PlainTextWeaving::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, &PlainTextWeaving::render_visit, (void *) &prs, 0);
}

int PlainTextWeaving::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.13

    else if (N->type == weave_verbatim_node_type) Render verbatim2.12
    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_subsubheading_node_type) Render subsubheading2.6
    else if (N->type == weave_bar_node_type) Render bar2.7
    else if (N->type == weave_pagebreak_node_type) Render pagebreak2.8
    else if (N->type == weave_linebreak_node_type) Render linebreak2.9
    else if (N->type == weave_paragraph_heading_node_type) Render paragraph heading2.10
    else if (N->type == weave_endnote_node_type) Render endnote2.11
    else if (N->type == weave_embed_node_type) Render embed2.14
    else if (N->type == weave_holon_declaration_node_type) Render holon declaration2.15
    else if (N->type == weave_holon_usage_node_type) Render holon usage2.16
    else if (N->type == weave_vskip_node_type) Render vskip2.17
    else if (N->type == weave_section_node_type) Render section2.18
    else if (N->type == weave_code_line_node_type) Render code line2.19
    else if (N->type == weave_function_usage_node_type) Render function usage2.20
    else if (N->type == weave_commentary_node_type) Render commentary2.21
    else if (N->type == weave_defn_node_type) Render defn2.22
    else if (N->type == weave_source_code_node_type) Render source code2.23
    else if (N->type == weave_url_node_type) Render URL2.24
    else if (N->type == weave_footnote_cue_node_type) Render footnote cue2.25
    else if (N->type == weave_begin_footnote_text_node_type) Render footnote text2.26
    else if (N->type == weave_display_line_node_type) Render display line2.27
    else if (N->type == weave_function_defn_node_type) Render function defn2.28
    else if (N->type == weave_item_node_type) Render item2.29
    else if (N->type == weave_locale_node_type) Render locale2.30
    else if (N->type == weave_maths_node_type) Render maths2.31
    else if (N->type == weave_markdown_node_type) Render Markdown2.32
    else if (N->type == weave_index_marker_node_type) Render index2.33

    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->ch_title);
    ls_section *S;
    LOOP_OVER_LINKED_LIST(S, ls_section, C->chap->sections) {
        WRITE("  %S\n    %S\n", S->sect_title, LiterateSource::unit_purpose(S->literate_source));
        WRITE("\n");
    }
    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->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 subsubheading2.6 =

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

§2.7. Render bar2.7 =

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

§2.8. Render pagebreak2.8 =

    ;

§2.9. Render linebreak2.9 =

    WRITE("\n");

§2.10. Render paragraph heading2.10 =

    weave_paragraph_heading_node *C = RETRIEVE_POINTER_weave_paragraph_heading_node(N->content);
    WRITE("\n");
    WRITE("%S%S", LiterateSource::par_ornament(C->para), C->para->paragraph_number);
    text_stream *title = LiterateSource::par_title(C->para);
    if (Str::len(title) > 0) WRITE(" %S", title);
    WRITE(".  ");

§2.11. Render endnote2.11 =

    Recurse the renderer through children nodes2.11.1;
    WRITE("\n");
    return FALSE;

§2.12. Render verbatim2.12 =

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

§2.13. Render nothing2.13 =

    ;

§2.14. Render embed2.14 =

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

§2.15. Render holon declaration2.15 =

    weave_holon_declaration_node *C = RETRIEVE_POINTER_weave_holon_declaration_node(N->content);
    WRITE("<%S (%S)> =",
        C->holon->holon_name, C->holon->corresponding_chunk->owner->paragraph_number);

§2.16. Render holon usage2.16 =

    weave_holon_usage_node *C = RETRIEVE_POINTER_weave_holon_usage_node(N->content);
    WRITE("<%S (%S)>",
        (C->holon)?(C->holon->holon_name):NULL, C->holon->corresponding_chunk->owner->paragraph_number);

§2.17. Render vskip2.17 =

    WRITE("\n");

§2.18. Render section2.18 =

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

§2.19. Render code line2.19 =

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

§2.20. Render function usage2.20 =

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

§2.21. Render commentary2.21 =

    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.22. Render defn2.22 =

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

§2.23. Render source code2.23 =

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

§2.24. Render URL2.24 =

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

§2.25. Render footnote cue2.25 =

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

§2.26. Render footnote text2.26 =

    WRITE("\n");

§2.27. Render display line2.27 =

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

§2.28. Render function defn2.28 =

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

§2.29. Render item2.29 =

    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.30. Render locale2.30 =

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

§2.31. Render maths2.31 =

    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.32. Render Markdown2.32 =

    weave_markdown_node *C = RETRIEVE_POINTER_weave_markdown_node(N->content);
    MDRenderer::render_extended(OUT, (void *) prs->wv, C->content, C->variation, 0);

§2.33. Render index2.33 =

    if ((prs->wv) && (prs->wv->weave_web)) {
        WebIndexing::inspect_index(OUT, prs->wv->weave_web, I"0");
    }

§2.11.1. Recurse the renderer through children nodes2.11.1 =

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