-
Notifications
You must be signed in to change notification settings - Fork 2
155 lines (148 loc) · 6.19 KB
/
build-ss3-manual-html.yml
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
name: build html version of the ss3 user manual
on:
push:
paths:
- '**.tex'
- 'html_usermanual_snippets.html'
- '**.yml'
pull_request:
paths:
- '**.tex'
- 'html_usermanual_snippets.html'
- '**.yml'
workflow_call:
inputs:
ref:
default: ${{ github.ref }}
required: false
type: string
jobs:
build-html:
runs-on: ubuntu-20.04
env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"
steps:
- name: Set up Git repository
uses: actions/checkout@v3
with:
ref: ${{ inputs.ref }}
- name: Update Ubuntu packages
run: sudo apt-get update
- name: Set up R
uses: r-lib/actions/setup-r@v2
with:
r-version: 'release'
- name: setup pandoc
uses: r-lib/actions/setup-pandoc@v2
with:
pandoc-version: '2.14.0.3'
- name: Convert tex to html
run: pandoc SS330_User_Manual.tex -s -o SS330_User_Manual.html --toc --self-contained --mathjax --default-image-extension=png --number-sections --citeproc --variable linkcolor=#0033CC
# Note: for the following R code, may be a single command to deal with the double header issue before rendering.
- name: Edit html to improve formatting
run: |
html_txt <- readLines("SS330_User_Manual.html")
#read html snippits to add
html_snips <- readLines("html_usermanual_snippets.html")
# remove inline style
style_sec <- grep("style>", html_txt)
html_txt <- html_txt[-(style_sec[1]:style_sec[2])]
# add in the navbar
navbar_snip <- grep("div", html_snips)
navbar_snip <- html_snips[navbar_snip[1]:navbar_snip[2]]
html_txt <- append(html_txt, navbar_snip, after = grep("<html", html_txt))
html_txt <- gsub(
"<p>_add:nnn<span>Catalog</span><span>Lang</span><span>(enUS)</span></p>",
"", html_txt, fixed = TRUE)
# add link to css
css_snip <- grep("<link", html_snips, value = TRUE)
html_txt <- append(html_txt, css_snip, after = grep("<title>", html_txt))
# Add styling to tables add 1 because first col is on next row
first_lines <- grep("^<tr class=[[:punct:]]{1}[oe]", html_txt) + 1
tmp_lines <- html_txt[first_lines]
tmp_lines <- gsub("<td style=\"text-align: left;\">",
"<td style=\"text-align: left;white-space: nowrap;\">",
tmp_lines)
html_txt[first_lines] <- tmp_lines
# remove Typical Value double header
label <- grep(">Typical Value<", html_txt, fixed = TRUE)
diff_label <- diff(label)
to_rm <- which(diff_label <10)
# one to get rid of is test
to_rm_lines <- label[to_rm+1]
for (i in to_rm_lines) {
start <- grep("<tr", html_txt, fixed = TRUE)
end <- grep("/tr", html_txt, fixed = TRUE)
start <- max(start[start %in% (i-5):(i-1)])
end <- min(end[end %in% (i+1):(i+5)])
if(length(start) == 1 & length(end) == 1) {
html_txt[start:end] <- ""
}
}
# remove Value double header
label <- grep(">Value<", html_txt, fixed = TRUE)
diff_label <- diff(label)
to_rm <- which(diff_label <10)
to_rm_lines <- label[to_rm+1]
for (i in to_rm_lines) {
start <- grep("<tr", html_txt, fixed = TRUE)
end <- grep("/tr", html_txt, fixed = TRUE)
start <- max(start[start %in% (i-5):(i-1)])
end <- min(end[end %in% (i+1):(i+5)])
if(length(start) == 1 & length(end) == 1) {
html_txt[start:end] <- ""
}
}
# remove LO HI INIT etc double header
label <- grep(">LO<", html_txt, fixed = TRUE)
diff_label <- diff(label)
to_rm <- which(diff_label < 20)
to_rm_lines <- label[to_rm+1]
for (i in to_rm_lines) {
start <- grep("<tr", html_txt, fixed = TRUE)
end <- grep("/tr", html_txt, fixed = TRUE)
start <- max(start[start %in% (i-10):(i-1)])
end <- min(end[end %in% (i+1):(i+10)])
if(length(start) == 1 & length(end) == 1) {
html_txt[start:end] <- ""
}
}
# remove Pattern N Parameters etc double header
label <- grep(">N Parameters<", html_txt, fixed = T)
diff_label <- diff(label)
to_rm <- which(diff_label == 5)
to_rm_lines <- label[to_rm+1]
for (i in to_rm_lines) {
start <- grep("<tr", html_txt, fixed = TRUE)
end <- grep("/tr", html_txt, fixed = TRUE)
start <- max(start[start %in% (i-2):(i-1)])
end <- min(end[end %in% (i+1):(i+2)])
if(length(start) == 1 & length(end) == 1) {
html_txt[start:end] <- ""
}
}
# Add title to table of contents
where_add <- grep('<nav id="TOC" role="doc-toc">',
html_txt, fixed = TRUE)
html_txt <- append(html_txt,
"<h1>Table of Contents</h1>",
after = where_add[1])
# Add title to references
where_add <- (grep("references csl-bib-body hanging-indent",
html_txt, fixed = TRUE) - 1)
html_txt <- append(html_txt,
'<h1 data-number="17" id="sec:references"><span class="header-section-number">17</span> References</h1>',
after = where_add)
# Add references to table of contents
where_add <- grep("</nav>", html_txt, fixed = TRUE)-2
html_txt <- append(html_txt,
'<li><a href="#sec:references"><span class="toc-section-number">17</span> References</a></li>',
after = where_add)
writeLines(html_txt, "SS330_User_Manual.html")
shell: Rscript {0}
- name: upload html file as artifact
uses: actions/upload-artifact@v3
with:
name: SS330_User_Manual.html
path: SS330_User_Manual.html