Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 70 additions & 29 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,6 @@
border-radius: 4px;
}

.etymology-label {
font-size: 14px;
font-weight: 600;
color: #8b7355;
text-transform: uppercase;
letter-spacing: 0.5px;
margin-bottom: 8px;
}

.etymology-text {
font-size: 16px;
color: #555;
Expand Down Expand Up @@ -188,12 +179,24 @@

.definition-text {
font-size: 18px;
line-height:

1.8;
line-height: 1.8;
color: #2d2d2d;
}

/* Second level: lowercase latin letters (a, b, cq...) */
.definitions-list ol {
margin-top: 8px;
margin-bottom: 8px;
padding-left: 28px;
list-style-type: lower-alpha;
}

/* Third level: lowercase Roman numerals (i, ii, iii...) */
.definitions-list ol ol {
list-style-type: lower-roman;
padding-left: 24px;
}

.no-results {
text-align: center;
color: #999;
Expand Down Expand Up @@ -679,12 +682,58 @@

this.currentWord = result.headword;


const renderDefinition = (arr, level = 0) => {
let html = '';
if (level === 0) {
html += '<ol class="definitions-list">'
}else {
html += '<ol>';
}

for (let i = 0; i < arr.length; i++) {
const item = arr[i];
const next = arr[i + 1];

if (typeof item === "string") {
if (level === 0) {
html += `<li class="definition-item">
<div class="definition-text">${item}`

} else {
html += `<li>${item}`;
}

// If next is an array, it belongs to this item
if (Array.isArray(next)) {
html += renderDefinition(next, level + 1);
i++; // skip the array
}

if (level === 0) {
html += `</div>`
}
html += `</li>`;

} else if (Array.isArray(item)) {
// Array without preceding string — attach to empty string
html += `<li>`;
html += renderDefinition(item, level + 1);
html += `</li>`;
}
}

html += `</ol>`;
return html;
};


// Build HTML for the word entry
let html = `<div class="definition-card">
<div class="word-header">
<h1 class="word-title">${result.headword}</h1>
${result.isRedirect ? `<div class="word-redirect">${result.redirectChain ? result.redirectChain.join(' → ') : result.searchWord + ' → ' + result.headword}</div>` : ''}
<div class="word-meta">`;
<div class="word-header">
<h1 class="word-title">${result.headword}</h1>
${result.isRedirect ? `<div class="word-redirect">${result.redirectChain ? result.redirectChain.join(' → ') : result.searchWord + ' → ' + result.headword}</div>` : ''}
<div class="word-meta">`;

// Add pronunciation if available
if (data.p) {
Expand All @@ -700,8 +749,7 @@ <h1 class="word-title">${result.headword}</h1>

// Add etymology if available
if (data.e) {
html += `<div class="word-etymology">
<div class="etymology-label">Etymology</div>`;
html += `<div class="word-etymology">`;

const etymArray = Array.isArray(data.e) ? data.e : [data.e];
etymArray.forEach(item => {
Expand All @@ -715,18 +763,11 @@ <h1 class="word-title">${result.headword}</h1>
if (data.d && typeof data.d === 'object') {
for (const [partOfSpeech, definitions] of Object.entries(data.d)) {
html += `<div class="part-of-speech-section">
<h2 class="part-of-speech">${partOfSpeech}</h2>
<ol class="definitions-list">`;

const defArray = Array.isArray(definitions) ? definitions : [definitions];
defArray.forEach(def => {
html += `<li class="definition-item">
<div class="definition-text">${def}</div>
</li>`;
});
<h2 class="part-of-speech">${partOfSpeech}</h2>`;

html += `</ol></div>`;
}
html += renderDefinition(definitions)
html += `</div>`;
}
}

html += `</div>`;
Expand Down
2 changes: 1 addition & 1 deletion wikidict/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def main() -> int:
args["LOCALE"],
args["--gen-dict"],
args["--output"],
format=args.get["--format", "kobo"],
format=args.get("--format", "kobo"),
)

if args["--show-pos"]:
Expand Down