") has to appear as
* itself rather than as markup. The two outputs need different escaping,
* and the Markdown copy used to be derived from the HTML one -- so
* "R&D" was written into Readme.md as "R&D". That renders correctly
* on a site that parses entities, but Readme.md is a file people also read
* raw, in an editor or a terminal, where it is just wrong.
*
* HTML: &, <, and > all become entities.
* Markdown: only what Markdown itself would misread -- | would open an
* extra table column, and < would open a raw HTML tag. A bare & is
* ordinary text in Markdown and is left alone.
foreach m in project date author desc url topic public timeline ///
othernotes stamp {
* Put back the ~ (and any $) the caller parked, before escaping.
local `m' = subinstr(`"`macval(`m')'"', char(5), char(126), .)
local `m' = subinstr(`"`macval(`m')'"', char(1), char(36), .)
* Markdown first, from the unescaped value.
local md_`m' = subinstr(`"`macval(`m')'"', "|", "\|", .)
local md_`m' = subinstr(`"`macval(md_`m')'"', "<", "<", .)
* then HTML.
local `m' = subinstr(`"`macval(`m')'"', "&", "&", .)
local `m' = subinstr(`"`macval(`m')'"', "<", "<", .)
local `m' = subinstr(`"`macval(`m')'"', ">", ">", .)
}
tempname fh
* ---- website/index.html ---------------------------------------------
quietly file open `fh' using `"`html'"', write text replace
file write `fh' "" _n
file write `fh' `""' _n
file write `fh' `""' _n
file write `fh' `"`macval(project)' -- project documentation"' _n
file write `fh' "" _n
file write `fh' `"`macval(project)'
"' _n
file write `fh' `"`macval(desc)'
"' _n
file write `fh' "" _n
file write `fh' `"| Created | `macval(date)' |
"' _n
file write `fh' `"| Author | `macval(author)' |
"' _n
file write `fh' `"| Source URL | `macval(url)' |
"' _n
file write `fh' `"| Topic | `macval(topic)' |
"' _n
file write `fh' `"| Public-facing | `macval(public)' |
"' _n
file write `fh' `"| Refresh timeline | `macval(timeline)' |
"' _n
file write `fh' `"| Other notes | `macval(othernotes)' |
"' _n
file write `fh' "
" _n
pb_htmllist `fh' `"`rawd'"' "*" "Raw files (01_raw/)"
pb_htmllist `fh' `"`convd'"' "*.dta" "Converted files (01_raw/_converted/)"
pb_htmllist `fh' `"`cleand'"' "*.dta" "Analytic files (02_cleaned/)"
file write `fh' `"Built `macval(stamp)' by projectbuilder v2.0.1."' _n
file write `fh' " Install webdoc2 for a richer rendering.
" _n
file write `fh' "" _n
file close `fh'
* ---- _documentation/Readme.md ---------------------------------------
quietly file open `fh' using `"`readme'"', write text replace
file write `fh' `"# `macval(md_project)'"' _n _n
file write `fh' `"`macval(md_desc)'"' _n _n
file write `fh' "| Field | Value |" _n
file write `fh' "|-------|-------|" _n
file write `fh' `"| Created | `macval(md_date)' |"' _n
file write `fh' `"| Author | `macval(md_author)' |"' _n
file write `fh' `"| Source URL | `macval(md_url)' |"' _n
file write `fh' `"| Topic | `macval(md_topic)' |"' _n
file write `fh' `"| Public-facing | `macval(md_public)' |"' _n
file write `fh' `"| Refresh timeline | `macval(md_timeline)' |"' _n
file write `fh' `"| Other notes | `macval(md_othernotes)' |"' _n
file write `fh' _n
pb_mdlist `fh' `"`rawd'"' "*" "Raw files (01_raw/)"
pb_mdlist `fh' `"`convd'"' "*.dta" "Converted files (01_raw/_converted/)"
pb_mdlist `fh' `"`cleand'"' "*.dta" "Analytic files (02_cleaned/)"
file write `fh' _n `"_Built `macval(md_stamp)' by projectbuilder v2.0.1._"' _n
file close `fh'
end
program define pb_htmllist
gettoken fh 0 : 0
gettoken dir 0 : 0
gettoken pat 0 : 0
gettoken hdr 0 : 0
file write `fh' `"`hdr'
"' _n
* As in pb_count: a folder we cannot list simply shows no files, rather
* than stopping the run with r(601) from inside the documentation writer.
capture local list : dir `"`dir'"' files `"`pat'"'
if _rc local list ""
local any = 0
file write `fh' "" _n
foreach f of local list {
if substr(`"`f'"', 1, 1) == "." continue
local fe = subinstr(`"`f'"', "&", "&", .)
local fe = subinstr(`"`fe'"', "<", "<", .)
local fe = subinstr(`"`fe'"', ">", ">", .)
file write `fh' `"`fe' "' _n
local any = 1
}
if !`any' file write `fh' `"- (none yet)
"' _n
file write `fh' "
" _n
end
program define pb_mdlist
gettoken fh 0 : 0
gettoken dir 0 : 0
gettoken pat 0 : 0
gettoken hdr 0 : 0
file write `fh' `"## `hdr'"' _n _n
capture local list : dir `"`dir'"' files `"`pat'"'
if _rc local list ""
local any = 0
foreach f of local list {
if substr(`"`macval(f)'"', 1, 1) == "." continue
* Markdown escaping only -- see the note in pb_docs. A file called
* "R&D notes.csv" is listed as itself, not as "R&D notes.csv".
local fe = subinstr(`"`macval(f)'"', "|", "\|", .)
local fe = subinstr(`"`macval(fe)'"', "<", "<", .)
file write `fh' `"- `macval(fe)'"' _n
local any = 1
}
if !`any' file write `fh' "- (none yet)" _n
file write `fh' _n
end