Skip to content

Commit 9bbcac7

Browse files
committed
Styles for desc and multi-field languages
1 parent f6a8162 commit 9bbcac7

File tree

2 files changed

+58
-21
lines changed

2 files changed

+58
-21
lines changed

src/routes/+page.svelte

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818

1919
<style>
2020
.page {
21+
font-size: 16px;
2122
text-align: center;
2223
}
2324
2425
input {
2526
background-color: inherit;
2627
color: inherit;
27-
28+
font-size: 1em;
2829
}
2930
3031
input[type="text"] {
@@ -46,10 +47,6 @@ form {
4647
form > * {
4748
vertical-align: middle;
4849
}
49-
50-
footer {
51-
font-size: 90%;
52-
}
5350
</style>
5451

5552
<div class="page">
@@ -63,6 +60,6 @@ footer {
6360
<DataTable results={results}/>
6461

6562
<footer>
66-
<p>網站作者:<a href="https://github.com/nk2028/hdqt">nk2028</a> - 資料來源:漢字音典(眾專家)</p>
63+
<p>網站作者:<a href="https://github.com/nk2028/hdqt">nk2028</a> - 資料來源:<a href="https://github.com/osfans/MCPDict">漢字音典(眾專家)</a></p>
6764
</footer>
6865
</div>

src/routes/DataTable.svelte

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,54 @@
11
<script lang="ts">
22
export let results: string[][];
3+
const headers: { [key: string]: string[] } = {
4+
'廣韻': [
5+
'切拼i', '白一平i', '古韻i', '有女i',
6+
'髙本漢', '王力{1957}', '王力{1985}', '李榮', '邵榮芬', '蒲立本', '鄭張尙芳', '潘悟雲{2000}', '潘悟雲{2013}', '潘悟雲{2023}', 'unt{2020}', 'unt{2022}', 'unt{通俗}', 'msoeg',
7+
'切韻音系描述', 'null', '方音字彙描述',
8+
'廣韻韻目原貌', '折合平水韻目',
9+
'反切',
10+
],
11+
'中原音韻': ['楊耐思', '寧繼福', '薛鳳生{音位形式}', 'unt{音位形式}', 'unt'],
12+
'普通話': ['i'],
13+
'東干語': ['西里爾字母i', '音標'],
14+
'香港': ['i'],
15+
'臺灣': ['i'],
16+
'越南': ['i'],
17+
'朝鮮': ['i'],
18+
'日語吳音': ['i'],
19+
'日語漢音': ['i'],
20+
};
321
</script>
422

523
<style>
624
table {
725
border-collapse: collapse;
826
margin: 0 auto;
927
overflow-x: auto;
28+
line-height: 1.5;
1029
}
1130
1231
th, td {
13-
border: 1px solid;
14-
padding: 4px 6px;
32+
padding: 0.25em;
33+
width: 12em;
34+
text-align: start;
35+
vertical-align: top;
1536
}
1637
17-
td:first-child {
18-
white-space: nowrap;
19-
}
20-
21-
td:not(:first-child) {
22-
width: 6em;
23-
word-break: break-all;
38+
th:first-child, td:first-child {
39+
width: auto;
40+
text-align: end;
2441
}
2542
2643
.name-tag {
27-
border-radius: 10px;
44+
border-radius: 0.5em;
2845
color: white;
29-
font-size: 0.8em;
30-
padding: 3px 5px;
46+
padding: 0.15em 0.2em;
47+
white-space: nowrap;
3148
}
3249
33-
.text {
34-
font-size: 90%;
50+
.desc {
51+
font-size: 0.75em;
3552
}
3653
</style>
3754

@@ -49,7 +66,30 @@ td:not(:first-child) {
4966
<tr>
5067
<td><span class="name-tag" style="background-color: {顏色};" title="{分區}">{簡稱}</span></td>
5168
{#each 字音們 as 字音}
52-
<td lang="zh-x-fonipa" class="text">{字音}</td>
69+
{(字音 = 字音.replace(/\{.*?\}/g, s => s.replace(/ /g, '')))}
70+
{#if headers[簡稱]}
71+
{(字音 = 字音
72+
.split(' ')
73+
.map(s => s
74+
.split('/')
75+
.map((s, i) => {
76+
let header = headers[簡稱][i];
77+
if (header === 'null') return '';
78+
if (header && header.endsWith('i')) {
79+
header = header.slice(0, -1);
80+
s = `<em>${s}</em>`;
81+
}
82+
return header ? header + '' + s : s;
83+
})
84+
.join('<br>')
85+
.replace(/(<br>)+/g, '<br>'))
86+
.join(headers[簡稱].length > 1 ? '<br><br>' : ' '))}
87+
{/if}
88+
{(字音 = 字音
89+
.replace(/\*(.*?)\*/g, '<strong>$1</strong>')
90+
.replace(/\|(.*?)\|/g, '<span style="opacity: 0.5;">$1</span>')
91+
.replace(/\{(.*?)\}/g, '<span class="desc">$1</span>'))}
92+
<td lang="zh-x-fonipa" class="text">{@html 字音}</td>
5393
{/each}
5494
</tr>
5595
{/each}

0 commit comments

Comments
 (0)