Skip to content

Commit 34f5a77

Browse files
committed
fix: improve ruby plugin
1 parent acee737 commit 34f5a77

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/mistune/plugins/ruby.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from ..markdown import Markdown
1111

1212

13-
RUBY_PATTERN = r'\[(?:\w+\(\w+\))+\]'
13+
RUBY_PATTERN = r'\[(?:\w+\([\w ]+\))+\]'
1414
_ruby_re = re.compile(RUBY_PATTERN)
1515

1616

@@ -86,7 +86,7 @@ def _parse_ruby_link(
8686

8787

8888
def render_ruby(renderer: "BaseRenderer", text: str, rt: str) -> str:
89-
return "<ruby><rb>" + text + "</rb><rt>" + rt + "</rt></ruby>"
89+
return "<ruby>" + text + "<rt>" + rt + "</rt></ruby>"
9090

9191

9292
def ruby(md: "Markdown") -> None:

tests/fixtures/ruby.txt

+15-9
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@
66
```````````````````````````````` example
77
[漢字(ㄏㄢˋㄗˋ)]
88
.
9-
<p><ruby><rb>漢字</rb><rt>ㄏㄢˋㄗˋ</rt></ruby></p>
9+
<p><ruby>漢字<rt>ㄏㄢˋㄗˋ</rt></ruby></p>
1010
````````````````````````````````
1111

1212
```````````````````````````````` example
1313
[漢(ㄏㄢˋ)字(ㄗˋ)]
1414
.
15-
<p><ruby><rb>漢</rb><rt>ㄏㄢˋ</rt></ruby><ruby><rb>字</rb><rt>ㄗˋ</rt></ruby></p>
15+
<p><ruby>漢<rt>ㄏㄢˋ</rt></ruby><ruby><rt>ㄗˋ</rt></ruby></p>
1616
````````````````````````````````
1717

1818
```````````````````````````````` example
1919
[漢字(ㄏㄢˋㄗˋ)][]
2020
.
21-
<p><ruby><rb>漢字</rb><rt>ㄏㄢˋㄗˋ</rt></ruby>[]</p>
21+
<p><ruby>漢字<rt>ㄏㄢˋㄗˋ</rt></ruby>[]</p>
2222
````````````````````````````````
2323

2424
```````````````````````````````` example
2525
[漢字(ㄏㄢˋㄗˋ)][link]
2626
.
27-
<p><ruby><rb>漢字</rb><rt>ㄏㄢˋㄗˋ</rt></ruby>[link]</p>
27+
<p><ruby>漢字<rt>ㄏㄢˋㄗˋ</rt></ruby>[link]</p>
2828
````````````````````````````````
2929

3030
## ruby with link
@@ -34,31 +34,37 @@
3434

3535
[漢字(ㄏㄢˋㄗˋ)][link]
3636
.
37-
<p><a href="/url"><ruby><rb>漢字</rb><rt>ㄏㄢˋㄗˋ</rt></ruby></a></p>
37+
<p><a href="/url"><ruby>漢字<rt>ㄏㄢˋㄗˋ</rt></ruby></a></p>
3838
````````````````````````````````
3939

4040
```````````````````````````````` example
4141
[漢字(ㄏㄢˋㄗˋ)]()
4242
.
43-
<p><a href=""><ruby><rb>漢字</rb><rt>ㄏㄢˋㄗˋ</rt></ruby></a></p>
43+
<p><a href=""><ruby>漢字<rt>ㄏㄢˋㄗˋ</rt></ruby></a></p>
4444
````````````````````````````````
4545

4646
```````````````````````````````` example
4747
[漢字(ㄏㄢˋㄗˋ)](/url)
4848
.
49-
<p><a href="/url"><ruby><rb>漢字</rb><rt>ㄏㄢˋㄗˋ</rt></ruby></a></p>
49+
<p><a href="/url"><ruby>漢字<rt>ㄏㄢˋㄗˋ</rt></ruby></a></p>
5050
````````````````````````````````
5151

5252
## ruby splits
5353

5454
```````````````````````````````` example
5555
[漢(かん)][字(じ)]
5656
.
57-
<p><ruby><rb>漢</rb><rt>かん</rt></ruby><ruby><rb>字</rb><rt>じ</rt></ruby></p>
57+
<p><ruby>漢<rt>かん</rt></ruby><ruby><rt>じ</rt></ruby></p>
5858
````````````````````````````````
5959

6060
```````````````````````````````` example
6161
[[漢(かん)][字(じ)]](https://jisho.org/search/漢字)
6262
.
63-
<p><a href="https://jisho.org/search/%E6%BC%A2%E5%AD%97"><ruby><rb>漢</rb><rt>かん</rt></ruby><ruby><rb>字</rb><rt>じ</rt></ruby></a></p>
63+
<p><a href="https://jisho.org/search/%E6%BC%A2%E5%AD%97"><ruby>漢<rt>かん</rt></ruby><ruby>字<rt>じ</rt></ruby></a></p>
64+
````````````````````````````````
65+
66+
```````````````````````````````` example
67+
[汉字(hàn zì)]
68+
.
69+
<p><ruby>汉字<rt>hàn zì</rt></ruby></p>
6470
````````````````````````````````

0 commit comments

Comments
 (0)