diff --git a/test/test_tuitse_tsinghap.py b/test/test_tuitse_tsinghap.py new file mode 100644 index 0000000..c9f19cd --- /dev/null +++ b/test/test_tuitse_tsinghap.py @@ -0,0 +1,14 @@ +from django.test.testcases import TestCase + +from tuitse import kiamtsa +from tuitse.html import tuitse_html + + +class TuaLiongTuiTse(TestCase): + + def test_tuitse(self): + tsusin = kiamtsa( + '做代誌愛像走{<華><馬拉松>,沓沓仔來。', + 'tsò tāi-tsì ài tshiūnn tsáu <華><馬拉松> kāng-khuán, ta̍uh-ta̍uh-á lâi.', + ) + tuitse_html(tsusin) diff --git a/tuitse/html.py b/tuitse/html.py index 49bd6ff..8d08ac6 100644 --- a/tuitse/html.py +++ b/tuitse/html.py @@ -5,7 +5,9 @@ def tuitse_html(kiamtsa_tinliat): html = '' - htmlsu = '' + tshamsoo = [] + su_html = '' + su_tshamsoo = [] kam_ting_tsit_hing_si_lomaji = False kam_ting_tsit_im_si_lomaji = False for ji in kiamtsa_tinliat: @@ -31,10 +33,11 @@ def tuitse_html(kiamtsa_tinliat): if ji[2] == THAU_JI: # Thòo sû ê html - if htmlsu: - html += "{}".format(htmlsu) + if su_html: + html += "{}".format(su_html) + tshamsoo += su_tshamsoo # Html tîng-lâi - htmlsu = _sng_ji_html(ji) + su_html, su_tshamsoo = _sng_ji_html(ji) continue if ji[2] == LIAN_JI: @@ -45,26 +48,33 @@ def tuitse_html(kiamtsa_tinliat): raise RuntimeError('一定愛設定頭字、連字、a̍h-sī輕聲') if kam_im_ai_lian: - htmlsu += "{}".format(tiauhu) + su_html += "{}" + su_tshamsoo.append(tiauhu) else: - htmlsu += " " + su_html += " " if kam_hing_ai_lian: - htmlsu += "{}".format(tiauhu) + su_html += "{}" + su_tshamsoo.append(tiauhu) else: - htmlsu += "" + su_html += "" - htmlsu += _sng_ji_html(ji) + sng_html, sng_tshamsoo = _sng_ji_html(ji) + su_html += sng_html + su_tshamsoo += sng_tshamsoo # Thòo bué sû ê html - html += "{}".format(htmlsu) - return format_html(html) + html += "{}".format(su_html) + tshamsoo += su_tshamsoo + return format_html(html, *tshamsoo) def _sng_ji_html(ji): if ji[3]: - return "{}{}".format(ji[1], ji[0]) + return "{}{}", [ji[1], ji[0]] if ji[1]: - return "{}{}".format( - ji[1], ji[0]) - return "  {}".format( - ji[0]) + return "{}{}", [ + ji[1], ji[0] + ] + return "  {}", [ + ji[0] + ]