Skip to content

Commit fe0dbc8

Browse files
committed
Add support for ezglossary
1 parent e7f26c7 commit fe0dbc8

File tree

7 files changed

+102
-1
lines changed

7 files changed

+102
-1
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,8 @@ $(MODULES): $(TMODULES)
252252
sed -i 's/^\*\\\[\([[:print:]]*\)\\\]\*/`[\1]`/g' $(TMODULES)
253253
sed -i 's/\([^\*]\)\*\([[:alnum:]][[:alnum:][:blank:]:|\|\.-]*\)\*$$/\1`\2`/g' $(TMODULES)
254254
sed -i 's/OPTIONNAME\([\\_[:alnum:]]*\)OPTIONNAME: /**\1**: /g' $(TMODULES)
255+
# Fix links to glossary defitions:
256+
sed -i 's|\((def:[[:print:]]*)\)|[]\1|g' $(TMODULES)
255257
# Remove unneeded escape characters \ in verbatim text:
256258
sed -i 's/`\([[:print:]]*\)\\\([[:print:]]*\)`/`\1\2`/g' $(TMODULES)
257259
sed -i 's/`\([[:print:]]*\)\\\([[:print:]]*\)`/`\1\2`/g' $(TMODULES)

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ _`bookmarks_to_pep`_ API
103103
_`default_db`_
104104
_`basic.md#captcha|CAPTCHA`_
105105
https://xmpp.org/extensions/xep-0045.html[XEP-0045]
106+
(def:c2s)
106107
```
107108

108109
gets converted into this markdown:
@@ -113,6 +114,45 @@ gets converted into this markdown:
113114
[default_db](toplevel.md#default_db)
114115
[CAPTCHA](basic.md#captcha)
115116
[XEP-0045](https://xmpp.org/extensions/xep-0045.html)
117+
[](def:c2s)
116118
```
117119

118120
There are example usage of those shorthands in ejabberd, for example in `mod_muc.erl`.
121+
122+
## Glossary
123+
124+
### Directly in markdown file
125+
126+
To define a new term, write in markdown:
127+
128+
``` markdown
129+
def:c2s
130+
: Client to Server connection in XMPP.
131+
```
132+
133+
To link to that term, write in markdown:
134+
135+
``` markdown
136+
Most connections in XMPP are [](def:c2s).
137+
```
138+
139+
Glossary terms can be defined as singular nouns (`connection`, `port`), and later you can link to that term in plural noun (`connections`, `ports`).
140+
141+
### In ejabberd source code
142+
143+
Term definition is done as expected; example usage:
144+
``` erlang
145+
mod_doc() ->
146+
#{desc =>
147+
[?T("def:ad-hoc command"), "",
148+
?T(": Command that can be executed by an XMPP client using XEP-0050."), "",
149+
?T("This module implements XEP-0050.")]
150+
```
151+
152+
In order to link to a term definition, please write simply `(def:c2s)` because `[]` becomes escaped and wouldn't work. Later `make extract` will add the `[]` automatically. Example usage:
153+
```erl
154+
mod_doc() ->
155+
#{desc =>
156+
?T("This module implements some (def:ad-hoc commands) for adminitration.")
157+
```
158+

content/assets/css/ezglossary.css

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
:root {
2+
--md-admonition-icon--glossary-definition: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M18 2a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2zm0 2h-5v8l-2.5-2.25L8 12V4H6v16h12z"/></svg>');
3+
--md-admonition-glossary-fg-color: rgb(0, 184, 212);
4+
}
5+
6+
.md-typeset .admonition.glossary-definition,
7+
.md-typeset details.glossary-definition {
8+
border-color: var(--md-admonition-glossary-fg-color);
9+
}
10+
.md-typeset .glossary-definition > .admonition-title,
11+
.md-typeset .glossary-definition > summary {
12+
background-color: rgba(0, 184, 212, 0.1);
13+
}
14+
.md-typeset .glossary-definition > .admonition-title::before,
15+
.md-typeset .glossary-definition > summary::before {
16+
background-color: var(--md-admonition-glossary-fg-color);
17+
-webkit-mask-image: var(--md-admonition-icon--glossary-definition);
18+
mask-image: var(--md-admonition-icon--glossary-definition);
19+
}
20+
21+
a.mkdocs-ezglossary-link {
22+
text-decoration-color: var(--md-admonition-glossary-fg-color);
23+
text-decoration-line: underline;
24+
text-decoration-style: wavy;
25+
text-decoration-thickness: 5%;
26+
text-underline-offset: 15%;
27+
}
28+

mkdocs.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ extra_css:
6464
- "assets/css/notes.css"
6565
- "assets/css/status.css"
6666
- "assets/css/headers-underline.css"
67+
- "assets/css/ezglossary.css"
6768

6869
#.
6970
#' markdown and hooks
@@ -93,16 +94,28 @@ markdown_extensions:
9394
- pymdownx.emoji:
9495
emoji_generator: !!python/name:material.extensions.emoji.to_svg
9596
emoji_index: !!python/name:material.extensions.emoji.twemoji
97+
- def_list
98+
- pymdownx.tasklist:
99+
custom_checkbox: true
96100

97101
hooks:
98-
- add_old_ids.py
102+
# - add_old_ids.py
99103
- shortcodes.py
100104

101105
#.
102106
#' plugins
103107
#
104108

105109
plugins:
110+
- ezglossary:
111+
ignore_case: true
112+
inline_refs: list
113+
#list_definitions: false
114+
#list_references: false
115+
markdown_links: true
116+
plurals: en
117+
templates: templates
118+
tooltip: short
106119
#- git-committers:
107120
# repository: processone/mkdocs
108121
# branch: main
@@ -203,6 +216,7 @@ nav:
203216
- Use Cases: use-cases/index.md
204217
- License: COPYING.md
205218
- Security: SECURITY.md
219+
- Glossary: glossary.md
206220
- Quickstart: README-GIT.md
207221
- Install:
208222
- admin/install/index.md

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mkdocs
2+
mkdocs-ezglossary-plugin
23
mkdocs-htmlproofer-plugin
34
mkdocs-material
45
mkdocs-redirects

templates/definition.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div class="admonition glossary-definition" id="{{ target }}">
2+
<p class="admonition-title">{{ term }}</p>
3+
<p>{{ definition|safe }}</p>
4+
</div>

templates/summary.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<ul>
2+
{% for term in terms %}
3+
{% for type in types %}
4+
{% for entry in glossary.get(section, term, type) %}
5+
{% if type[:-1] == "def" %}
6+
<li><a href="{{ root }}{{ entry.page.url }}#{{ entry.target }}">{{term}}</a></li>
7+
{% endif %}
8+
{% endfor %}
9+
{% endfor %}
10+
{% endfor %}
11+
</ul>
12+

0 commit comments

Comments
 (0)