summaryrefslogtreecommitdiffstats
path: root/notes/processing-scripts.txt
blob: 35e8edb402e5ea59c875b751ea865b04ee2f7d55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
MD -> TXT:
	scripts/preprocmdheaders.pl -n $docdir
MD -> HTML:
	scripts/preprocmdheaders.pl -nl $docdir
	scripts/linkpages.pl $docdir
	markdown $docdir/index.txt > $docdir/index.html
	while read file; do \
			markdown $docdir/$file.txt > $docdir/$file.html
		done < $docdir/series
	scripts/postprochtmlheaders.pl -anL $docdir


scripts/preprocmdheaders.pl [-ntl] docdir
	options
		-n  prepend section numbers to headers
		-l  handle hyperlinks to sections in text and table of contents
	pseudocode
		chapter = 0
		for each file in $docdir/series:
			++chapter
			...
			for each header:
				if opt n:
					...
				...
scripts/linkpages.pl docdir
scripts/postprochtmlheaders.pl [-anL] docdir
	options
		-a  add "id" attributes to headers
		-n  remove section numbers from "id" attributes (use with -a)

scripts/preproc.pl
	options
		-f format
			"txt" or "html"
	pseudopseudocode
		scan each source file for sections
		build a ToC
			print('  ' x $seclev, "* [$secnum $sectitle][$secid]\n");
		if txt
			add section numbers to headers
			add $title . "\n" . '*' x strlen($title)
		if html
			add link defs "[$secid]: $chapter.html#$section_id"
scripts/postproc.pl
	options
		-f format
			"txt" or "html"
	pseudopseudocode
		if txt
			blame the schools and bail out
		add section numbers and "id" attributes to headers


$docdir/
 +- appendices
 |    A list of appendix documents in the book.
 +- chapters
 |    A list of chapter documents in the book.
 +- first-chapter.md
 |    The source file for a chapter.
 +- first-chapter.html
 |    The rendered HTML file for a chapter.
 +- first-chapter.txt
 |    The rendered text file for a chapter.
 +- reference-stuff.md
 |    The source file for an appendix.
 +- second-chapter.md
 |    The source file for a chapter.
 \- title.md
      The source file for the title page.


ToC substitution:
$[toc]

section link substitution:
$[sectlink][foo]
[ยง 1.10.11][foo]

# create book and documents             - DONE
# book->parse()                         - DONE
#   foreach document:                   - DONE
#     doc->parse()                      - DONE
#       foreach heading:                - DONE
#         section = new Section         - DONE
#         push(self->sections, section) - DONE
#         book->add_section()           - DONE
#         prefix section title with num - DONE
# book->output()                        - DONE
#   book->subst_macros                  - DONE
#     build ToC string                  - DONE
#   foreach document:                   - DONE
#     doc(Txt)->output()                - DONE
#       book->subst_macros()            - DONE
#       write title                     - DONE
#       dump Markdown text              - DONE
#     doc(HTML)->output()               - DONE
#       book->subst_macros()            - DONE
#       append link defs string         - DONE
#       generate HTML (markdown)        - DONE
#       parse HTML                      - DONE
#       foreach heading:                - DONE
#         set id attribute              - DONE
#       write templated documents       - DONE
#
# Book
#   new
#   add_section
#     indexes section by id
#     appends to link defs string
#   parse
#   output
#   add_section
#   add_macro
#   subst_macros
#   _do_subst_macro
# Document
#   new
#   parse
# Document::Txt
#   output
# Document::HTML
#   output
# Section
#   new
#   number
#   id
#   title