Skip to content

Commit 173ff0d

Browse files
authored
Merge pull request #25 from takanory/t24-searchable-nekochan-list
#24 searchable nekochan list
2 parents 50b91e7 + 1ac3930 commit 173ff0d

File tree

5 files changed

+43
-16
lines changed

5 files changed

+43
-16
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## v0.3.3 - 2025-03-22
4+
5+
* 📝 Add search function to nekochan emoji list(by [List.js](https://listjs.com/))
6+
37
## v0.3.2 - 2025-03-19
48

59
* ✨ Add nekochan directive

docs/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"class": "fa-brands fa-solid fa-github fa-2x",
5757
},
5858
],
59+
5960
}
6061

6162
html_css_files = [

docs/images/nekochan-search.gif

415 KB
Loading

docs/nekochan_emojis.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,11 @@ Each emoji can be specified by name or alias.
3131
If you want to add or edit aliases to any Nekochan emoji, please send a Pull Request to [aliases.json](https://github.com/takanory/sphinx-nekochan/blob/main/sphinx_nekochan/data/aliases.json).
3232
```
3333

34+
```{tip}
35+
You can search nekochan emojis.
36+
37+
![](images/nekochan-search.gif)
38+
```
39+
3440
```{_all_nekochan}
3541
```

sphinx_nekochan/__init__.py

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""sphinx-nekochan emoji extension"""
22

3-
__version__ = "0.3.2"
3+
__version__ = "0.3.3"
44

55
from functools import cache
66
from importlib import resources
@@ -155,26 +155,40 @@ def run(self) -> list[nodes.Node]:
155155
nekochan_emoji, _ = get_nekochan_emoji_data()
156156

157157
text = f"Number of Nekochan emojis: {len(nekochan_emoji)}"
158-
node_list.append(nodes.Text(text))
158+
paragraph = nodes.paragraph()
159+
paragraph.append(nodes.Text(text))
160+
node_list.append(paragraph)
161+
162+
# add div
163+
container = nodes.container()
164+
container.attributes["ids"] = ["nekochan"]
165+
search_text = '<input class="search" placeholder="Search" />'
166+
search = nodes.raw("", nodes.Text(search_text), format="html")
167+
container.append(search)
168+
169+
# create table and header
170+
table, tgroup = self.create_table_header()
171+
tbody = nodes.tbody()
172+
tbody.set_class("list")
173+
tgroup += tbody
174+
175+
container.append(table)
176+
node_list.append(container)
159177

160-
first_char = ""
161178
for name, data in nekochan_emoji.items():
162-
if name[0] != first_char:
163-
first_char = name[0]
164-
# create section and title(H2)
165-
section = nodes.section(ids=[first_char])
166-
title = nodes.title(first_char.upper(), first_char.upper())
167-
section.append(title)
168-
node_list.append(section)
169-
170-
# create table and header
171-
table, tgroup = self.create_table_header()
172-
tbody = nodes.tbody()
173-
tgroup += tbody
174-
node_list.append(table)
175179
# add row to table
176180
tbody += self.create_row(name, nekochan_emoji[name]["aliases"])
177181

182+
# add javascript for list.js
183+
js = """<script src="https://cdnjs.cloudflare.com/ajax/libs/list.js/2.3.1/list.min.js"></script>
184+
<script>
185+
var options = {valueNames: ['name', 'aliases']};
186+
var userList = new List('nekochan', options);
187+
</script>"""
188+
search_text = '<input class="search" placeholder="Search" />'
189+
js_node = nodes.raw("", nodes.Text(js), format="html")
190+
container.append(js_node)
191+
178192
return node_list
179193

180194
def create_table_header(self) -> nodes.Node:
@@ -218,12 +232,14 @@ def create_row(self, name: str, aliases) -> nodes.Node:
218232
cell = nodes.entry()
219233
row += cell
220234
cell += nodes.literal(name, name)
235+
cell.set_class("name")
221236
cell = nodes.entry()
222237
row += cell
223238
for idx, alias in enumerate(aliases):
224239
if idx > 0:
225240
cell += nodes.Text(", ")
226241
cell += nodes.literal(alias, alias)
242+
cell.set_class("aliases")
227243

228244
return row
229245

0 commit comments

Comments
 (0)