Skip to content

Commit 7f7f63a

Browse files
author
james-ball-qualcomm
authored
Merge pull request #117 from riscv/116-improve-display-of-norm-rules-sidebar-in-html
Made norm rule HTML sidebar more compact and display truncated tables
2 parents 3e01674 + 7c7e45e commit 7f7f63a

File tree

9 files changed

+127
-82
lines changed

9 files changed

+127
-82
lines changed

test-norm-rules-ref.adoc

Lines changed: 0 additions & 64 deletions
This file was deleted.

tests/norm-rule/expected/test-norm-rules.adoc

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,40 @@ a| link:test.html#norm:paragraph:tag_with_newlines[norm:paragraph:tag_with_newli
3131
a| link:test.html#norm:def[norm:def] | This paragraph has two tags but we only ever get a tag for norm:def.
3232

3333
.1+| table1
34-
a| link:test.html#norm:table:anchors-in-cells:entire-table[norm:table:anchors-in-cells:entire-table] | ENTIRE TABLE
34+
a| link:test.html#norm:table:anchors-in-cells:entire-table[norm:table:anchors-in-cells:entire-table] | ===
35+
WITH anchor
36+
WITHOUT anchor
37+
===
3538

3639
.1+| table2
37-
a| link:test.html#norm:table:no-anchors-in-cells:entire-table[norm:table:no-anchors-in-cells:entire-table] | ENTIRE TABLE
40+
a| link:test.html#norm:table:no-anchors-in-cells:entire-table[norm:table:no-anchors-in-cells:entire-table] | Header 1|Header 2
41+
===
42+
Cell in column 1, row 1|Cell in column 2, row 1
43+
Cell in column 1, row 2|Cell in column 2, row 2
44+
===
3845

3946
.1+| table3
4047
a| link:test.html#norm:table:anchors-in-cells:entire-table-tagged:cell[norm:table:anchors-in-cells:entire-table-tagged:cell] | WITH anchor
4148

4249
.1+| table4
4350
a| link:test.html#norm:table:anchors-in-cells:entire-table-not-tagged:cell[norm:table:anchors-in-cells:entire-table-not-tagged:cell] | ABC DEF
4451

52+
.1+| table5
53+
a| link:test.html#norm:table:many-rows[norm:table:many-rows] | Name|Color
54+
===
55+
Roses|Red
56+
Violets|Blue
57+
Name1|Color1
58+
Name2|Color2
59+
Name3|Color3
60+
Name4|Color4
61+
Name5|Color5
62+
Name6|Color6
63+
Name7|Color8
64+
Name9|Color9
65+
Name10|Color10
66+
...
67+
4568
.1+| unordered1
4669
a| link:test.html#norm:unordered-list:no-anchors-in-items:entire-list[norm:unordered-list:no-anchors-in-items:entire-list] | Item A
4770
Item B

tests/norm-rule/expected/test-norm-rules.html

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="utf-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1" />
6-
<title>Page with Tables & Sidebar Navigation</title>
6+
<title>Normative Rules per Chapter</title>
77
<style>
88
:root{
99
--sidebar-width: 200px;
@@ -30,7 +30,7 @@
3030
overflow-y:auto;
3131
scrollbar-width:auto; /* show only when needed in Firefox */
3232
}
33-
sidebar::-webkit-scrollbar{
33+
.sidebar::-webkit-scrollbar{
3434
width:8px;
3535
}
3636
.sidebar::-webkit-scrollbar-thumb{
@@ -40,13 +40,27 @@
4040
.sidebar::-webkit-scrollbar-thumb:hover{
4141
background:rgba(0,0,0,0.3);
4242
}
43+
.sidebar ul {
44+
list-style: none;
45+
padding: 0;
46+
margin: 0;
47+
}
48+
.sidebar li {
49+
margin: 2px 0; /* reduce vertical gap between items */
50+
}
4351
.sidebar::-webkit-scrollbar-track{
4452
background:transparent;
4553
}
4654
.sidebar h2{margin:0 0 12px;font-size:18px}
47-
.nav{display:flex;flex-direction:column;gap:8px}
55+
.nav{display:flex;flex-direction:column;gap:2px}
4856
.nav a{
49-
display:block;padding:10px 12px;border-radius:8px;text-decoration:none;color:var(--accent);font-weight:600;
57+
display:block;
58+
font-size: 14px;
59+
padding:6px 10px;
60+
border-radius:6px;
61+
text-decoration:none;
62+
color:var(--accent);
63+
font-weight:600;
5064
}
5165
.nav a .subtitle{display:block;font-weight:400;color:var(--muted);font-size:12px}
5266
.nav a.active{background:rgba(3,102,214,0.12);color:var(--accent)}
@@ -141,12 +155,12 @@ <h3>my-chapter_name</h3>
141155
<tr>
142156
<td rowspan=1>table1</td>
143157
<td><a href="test.html#norm:table:anchors-in-cells:entire-table">norm:table:anchors-in-cells:entire-table</a></td>
144-
<td>ENTIRE TABLE</td></tr>
158+
<td>===<br>WITH anchor<br>WITHOUT anchor<br>===</td></tr>
145159
</tr>
146160
<tr>
147161
<td rowspan=1>table2</td>
148162
<td><a href="test.html#norm:table:no-anchors-in-cells:entire-table">norm:table:no-anchors-in-cells:entire-table</a></td>
149-
<td>ENTIRE TABLE</td></tr>
163+
<td>Header 1|Header 2<br>===<br>Cell in column 1, row 1|Cell in column 2, row 1<br>Cell in column 1, row 2|Cell in column 2, row 2<br>===</td></tr>
150164
</tr>
151165
<tr>
152166
<td rowspan=1>table3</td>
@@ -158,6 +172,11 @@ <h3>my-chapter_name</h3>
158172
<td><a href="test.html#norm:table:anchors-in-cells:entire-table-not-tagged:cell">norm:table:anchors-in-cells:entire-table-not-tagged:cell</a></td>
159173
<td>ABC DEF</td></tr>
160174
</tr>
175+
<tr>
176+
<td rowspan=1>table5</td>
177+
<td><a href="test.html#norm:table:many-rows">norm:table:many-rows</a></td>
178+
<td>Name|Color<br>===<br>Roses|Red<br>Violets|Blue<br>Name1|Color1<br>Name2|Color2<br>Name3|Color3<br>Name4|Color4<br>Name5|Color5<br>Name6|Color6<br>Name7|Color8<br>Name9|Color9<br>Name10|Color10<br>...</td></tr>
179+
</tr>
161180
<tr>
162181
<td rowspan=1>unordered1</td>
163182
<td><a href="test.html#norm:unordered-list:no-anchors-in-items:entire-list">norm:unordered-list:no-anchors-in-items:entire-list</a></td>

tests/norm-rule/expected/test-norm-rules.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,18 @@
139139
}
140140
]
141141
},
142+
{
143+
"name": "table5",
144+
"def_filename": "tests/norm-rule/test.yaml",
145+
"chapter_name": "my-chapter_name",
146+
"tags": [
147+
{
148+
"name": "norm:table:many-rows",
149+
"text": "Name|Color\n===\nRoses|Red\nViolets|Blue\nName1|Color1\nName2|Color2\nName3|Color3\nName4|Color4\nName5|Color5\nName6|Color6\nName7|Color8\nName9|Color9\nName10|Color10\nName11|Color11\nName12|Color12\nName13|Color13\nName14|Color14\n===",
150+
"tag_filename": "/build/test-norm-tags.json"
151+
}
152+
]
153+
},
142154
{
143155
"name": "unordered1",
144156
"def_filename": "tests/norm-rule/test.yaml",
153 Bytes
Binary file not shown.

tests/norm-rule/expected/test-norm-tags.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"norm:table:anchors-in-cells:entire-table-tagged:cell": "WITH anchor",
1212
"norm:table:anchors-in-cells:entire-table": "===\nWITH anchor\nWITHOUT anchor\n===",
1313
"norm:table:anchors-in-cells:entire-table-not-tagged:cell": "ABC DEF",
14+
"norm:table:many-rows": "Name|Color\n===\nRoses|Red\nViolets|Blue\nName1|Color1\nName2|Color2\nName3|Color3\nName4|Color4\nName5|Color5\nName6|Color6\nName7|Color8\nName9|Color9\nName10|Color10\nName11|Color11\nName12|Color12\nName13|Color13\nName14|Color14\n===",
1415
"norm:unordered-list:no-anchors-in-items:entire-list": "Item A\nItem B\nItem C",
1516
"norm:unordered-list:anchors-in-items:item1": "Item 1",
1617
"norm:unordered-list:anchors-in-items:item2": "Item 2",
@@ -69,7 +70,8 @@
6970
"norm:table:no-anchors-in-cells:entire-table",
7071
"norm:table:anchors-in-cells:entire-table-tagged:cell",
7172
"norm:table:anchors-in-cells:entire-table",
72-
"norm:table:anchors-in-cells:entire-table-not-tagged:cell"
73+
"norm:table:anchors-in-cells:entire-table-not-tagged:cell",
74+
"norm:table:many-rows"
7375
]
7476
}
7577
],

tests/norm-rule/test.adoc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,29 @@ a| Cell is adoc
8585
| [#norm:table:anchors-in-cells:entire-table-not-tagged:cell]#ABC DEF#
8686
|===
8787

88+
// PASSES - Want tagged text to be "ENTIRE TABLE"
89+
[[norm:table:many-rows]]
90+
[cols="1,1"]
91+
|===
92+
|Name|Color
93+
94+
|Roses|Red
95+
|Violets|Blue
96+
|Name1|Color1
97+
|Name2|Color2
98+
|Name3|Color3
99+
|Name4|Color4
100+
|Name5|Color5
101+
|Name6|Color6
102+
|Name7|Color8
103+
|Name9|Color9
104+
|Name10|Color10
105+
|Name11|Color11
106+
|Name12|Color12
107+
|Name13|Color13
108+
|Name14|Color14
109+
|===
110+
88111
== Chapter 3 - Tagging Unordered Lists
89112

90113
// PASSES - Tag includes all list items

tests/norm-rule/test.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ normative_rule_definitions:
4040
tags: ["norm:table:anchors-in-cells:entire-table-tagged:cell"]
4141
- name: table4
4242
tags: ["norm:table:anchors-in-cells:entire-table-not-tagged:cell"]
43+
- name: table5
44+
tags: ["norm:table:many-rows"]
4345

4446
# Unordered lists
4547
- name: unordered1

tools/create_normative_rules.rb

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ def html_head(f)
801801
<head>
802802
<meta charset="utf-8" />
803803
<meta name="viewport" content="width=device-width, initial-scale=1" />
804-
<title>Page with Tables & Sidebar Navigation</title>
804+
<title>Normative Rules per Chapter</title>
805805
<style>
806806
:root{
807807
--sidebar-width: 200px;
@@ -828,7 +828,7 @@ def html_head(f)
828828
overflow-y:auto;
829829
scrollbar-width:auto; /* show only when needed in Firefox */
830830
}
831-
sidebar::-webkit-scrollbar{
831+
.sidebar::-webkit-scrollbar{
832832
width:8px;
833833
}
834834
.sidebar::-webkit-scrollbar-thumb{
@@ -838,13 +838,27 @@ def html_head(f)
838838
.sidebar::-webkit-scrollbar-thumb:hover{
839839
background:rgba(0,0,0,0.3);
840840
}
841+
.sidebar ul {
842+
list-style: none;
843+
padding: 0;
844+
margin: 0;
845+
}
846+
.sidebar li {
847+
margin: 2px 0; /* reduce vertical gap between items */
848+
}
841849
.sidebar::-webkit-scrollbar-track{
842850
background:transparent;
843851
}
844852
.sidebar h2{margin:0 0 12px;font-size:18px}
845-
.nav{display:flex;flex-direction:column;gap:8px}
853+
.nav{display:flex;flex-direction:column;gap:2px}
846854
.nav a{
847-
display:block;padding:10px 12px;border-radius:8px;text-decoration:none;color:var(--accent);font-weight:600;
855+
display:block;
856+
font-size: 14px;
857+
padding:6px 10px;
858+
border-radius:6px;
859+
text-decoration:none;
860+
color:var(--accent);
861+
font-weight:600;
848862
}
849863
.nav a .subtitle{display:block;font-weight:400;color:var(--muted);font-size:12px}
850864
.nav a.active{background:rgba(3,102,214,0.12);color:var(--accent)}
@@ -997,19 +1011,34 @@ def html_script(f)
9971011
end
9981012

9991013
# Cleanup the tag text to be suitably displayed.
1000-
# TODO: When https://github.com/riscv/docs-resources/issues/112 improves table format,
1001-
# update this to allow small tables to be displayed.
10021014
def handle_tables(text)
10031015
raise ArgumentError, "Expected String for text but was passed a #{text}.class" unless text.is_a?(String)
10041016

1017+
# This is the detection pattern for an entire table being tagged from the "tags.rb" AsciiDoctor backend.
10051018
if text.end_with?("\n===")
1006-
# This is the currentl weak detection pattern for an entire table being tagged.
1007-
"ENTIRE TABLE"
1019+
# Limit table size displayed.
1020+
truncate_after_newlines(text, 12)
10081021
else
10091022
text
10101023
end
10111024
end
10121025

1026+
def truncate_after_newlines(text, max_newlines)
1027+
# Split the string into lines
1028+
lines = text.split("\n")
1029+
1030+
# Take only up to the allowed number of lines
1031+
truncated_lines = lines.first(max_newlines + 1)
1032+
1033+
# Join them back together with newline characters
1034+
truncated_text = truncated_lines.join("\n")
1035+
1036+
# If there were more lines than allowed, indicate truncation.
1037+
truncated_text += "\n..." if lines.size > max_newlines + 1
1038+
1039+
truncated_text
1040+
end
1041+
10131042
# Convert newlines to <br>.
10141043
def html_handle_newlines(text)
10151044
raise ArgumentError, "Expected String for text but was passed a #{text}.class" unless text.is_a?(String)
@@ -1049,5 +1078,4 @@ def html_handle_newlines(text)
10491078
raise "Unknown output_format of #{output_format}"
10501079
end
10511080

1052-
10531081
exit 0

0 commit comments

Comments
 (0)