|
1 | 1 | """sphinx-nekochan emoji extension""" |
2 | 2 |
|
3 | | -__version__ = "0.3.2" |
| 3 | +__version__ = "0.3.3" |
4 | 4 |
|
5 | 5 | from functools import cache |
6 | 6 | from importlib import resources |
@@ -155,26 +155,40 @@ def run(self) -> list[nodes.Node]: |
155 | 155 | nekochan_emoji, _ = get_nekochan_emoji_data() |
156 | 156 |
|
157 | 157 | 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) |
159 | 177 |
|
160 | | - first_char = "" |
161 | 178 | 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) |
175 | 179 | # add row to table |
176 | 180 | tbody += self.create_row(name, nekochan_emoji[name]["aliases"]) |
177 | 181 |
|
| 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 | + |
178 | 192 | return node_list |
179 | 193 |
|
180 | 194 | def create_table_header(self) -> nodes.Node: |
@@ -218,12 +232,14 @@ def create_row(self, name: str, aliases) -> nodes.Node: |
218 | 232 | cell = nodes.entry() |
219 | 233 | row += cell |
220 | 234 | cell += nodes.literal(name, name) |
| 235 | + cell.set_class("name") |
221 | 236 | cell = nodes.entry() |
222 | 237 | row += cell |
223 | 238 | for idx, alias in enumerate(aliases): |
224 | 239 | if idx > 0: |
225 | 240 | cell += nodes.Text(", ") |
226 | 241 | cell += nodes.literal(alias, alias) |
| 242 | + cell.set_class("aliases") |
227 | 243 |
|
228 | 244 | return row |
229 | 245 |
|
|
0 commit comments