forked from nix-community/nixvim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
0002-nixos-render-docs-Support-gfm-style-admonitions.patch
112 lines (108 loc) · 3.23 KB
/
0002-nixos-render-docs-Support-gfm-style-admonitions.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
From cf462a681089ead8ac747b24116c78db0cc1df40 Mon Sep 17 00:00:00 2001
From: Quentin Boyer <quentin+dev@familleboyer.net>
Date: Wed, 11 Sep 2024 19:21:12 +0200
Subject: [PATCH 2/2] nixos-render-docs: Support gfm-style admonitions
---
nixos_render_docs/md.py | 2 ++
tests/sample_md.py | 3 +++
tests/test_asciidoc.py | 6 ++++++
tests/test_commonmark.py | 3 +++
tests/test_html.py | 4 ++++
tests/test_manpage.py | 6 ++++++
6 files changed, 24 insertions(+)
diff --git a/nixos_render_docs/md.py b/nixos_render_docs/md.py
index 894daf9ca9c7..e0aca42ebd14 100644
--- a/nixos_render_docs/md.py
+++ b/nixos_render_docs/md.py
@@ -14,6 +14,7 @@ from mdit_py_plugins.container import container_plugin # type: ignore[attr-defin
from mdit_py_plugins.deflist import deflist_plugin # type: ignore[attr-defined]
from mdit_py_plugins.footnote import footnote_plugin # type: ignore[attr-defined]
from mdit_py_plugins.myst_role import myst_role_plugin # type: ignore[attr-defined]
+from gfm_alerts_to_admonitions import gfm_alert_to_admonition
_md_escape_table = {
ord('*'): '\\*',
@@ -588,6 +589,7 @@ class Converter(ABC, Generic[TR]):
renderer_cls=self.ForbiddenRenderer
)
self._md.enable('table')
+ self._md.use(gfm_alert_to_admonition)
self._md.use(
container_plugin,
name="blockattr",
diff --git a/tests/sample_md.py b/tests/sample_md.py
index 73a64fde8364..1648c4d9453e 100644
--- a/tests/sample_md.py
+++ b/tests/sample_md.py
@@ -1,4 +1,7 @@
sample1 = """\
+> [!NOTE]
+> This is a *note*
+
:::: {.warning}
foo
::: {.note}
diff --git a/tests/test_asciidoc.py b/tests/test_asciidoc.py
index 3cf5b208f392..c9b39f4e47f9 100644
--- a/tests/test_asciidoc.py
+++ b/tests/test_asciidoc.py
@@ -45,6 +45,12 @@ f
def test_full() -> None:
c = Converter({ 'man(1)': 'http://example.org' })
assert c._render(sample1) == """\
+[NOTE]
+====
+This is a __note__
+====
+
+
[WARNING]
====
foo
diff --git a/tests/test_commonmark.py b/tests/test_commonmark.py
index e151325338ca..ca137ce8cc48 100644
--- a/tests/test_commonmark.py
+++ b/tests/test_commonmark.py
@@ -27,6 +27,9 @@ def test_indented_fence() -> None:
def test_full() -> None:
c = Converter({ 'man(1)': 'http://example.org' })
assert c._render(sample1) == """\
+> [!Note]
+> This is a *note*
+
> [!Warning]
> foo
>
diff --git a/tests/test_html.py b/tests/test_html.py
index 9a3e07cb24c7..b51bc47ec557 100644
--- a/tests/test_html.py
+++ b/tests/test_html.py
@@ -149,6 +149,10 @@ def test_footnotes() -> None:
def test_full() -> None:
c = Converter({ 'man(1)': 'http://example.org' }, {})
assert c._render(sample1) == unpretty("""
+ <div class="note">
+ <h3 class="title">Note</h3>
+ <p>This is a <span class="emphasis"><em>note</em></span></p>
+ </div>
<div class="warning">
<h3 class="title">Warning</h3>
<p>foo</p>
diff --git a/tests/test_manpage.py b/tests/test_manpage.py
index b6e4a94ef1c6..1943bb17f339 100644
--- a/tests/test_manpage.py
+++ b/tests/test_manpage.py
@@ -41,6 +41,12 @@ def test_full() -> None:
assert c._render(sample1) == """\
.sp
.RS 4
+\\fBNote\\fP
+.br
+This is a \\fInote\\fR
+.RE
+.sp
+.RS 4
\\fBWarning\\fP
.br
foo
--
2.46.0