diff -ur v12/ezmd.py v13/ezmd.py --- v12/ezmd.py 2019-09-30 01:52:00.000000000 +0900 +++ v13/ezmd.py 2019-09-30 21:30:25.000000000 +0900 @@ -5,7 +5,7 @@ import nkf heads = [ 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'h7', 'h8', 'h9' ] -modes = heads + [ 'p', 'pre', 'ul', 'index' ] +modes = heads + [ 'p', 'pre', 'ul', 'dl', 'index' ] is_all_ge_n = lambda s, c, n: all( map( lambda c_: c_ == c, s ) ) and len(s) >= n @@ -31,6 +31,7 @@ flat_map = lambda f, lst: sum( map( lambda o: to_lst( f(o) ), lst ), [] ) lst_strip = lambda lst: list( map( lambda s: s.strip(), lst ) ) +lst_to_empty = lambda lst: list( map( lambda s: '' if s.strip() == '' else s, lst ) ) strip_head = lambda s: strip_head(s[1:]) if s and s[0] in (' ', '\t') else s strip_tail = lambda s: strip_tail(s[:-1]) if s and s[-1] in (' ', '\t') else s @@ -142,6 +143,24 @@ res.extend( list( map(lst_to, lsts) ) ) +def do_mode_dl(buf, res): + buf = lst_to_empty(buf) + buf = cut_ht_empty(buf) + if buf: + buf = cut_verb_idt(buf) + (lst, mode, mbuf) = ( [], '', [] ) + for s in buf: + mode_ = '' if s == '' else ( 'dd' if s[0] in (' ', '\t') else 'dt' ) + if mode_ != mode: + if mode and mbuf: + lst.append( { mode: do_str(mbuf) } ) + (mode, mbuf) = ( mode_, [ s.strip() ] ) + elif s: + mbuf.append( s.strip() ) + if mode and mbuf: + lst.append( { mode: do_str(mbuf) } ) + res.append( { 'dl': lst } ) + def do_mode(mode, buf, res, hd_names): if mode in heads: buf = lst_strip(buf) @@ -174,6 +193,8 @@ res.append( { 'pre': s } ) elif mode == 'ul': do_mode_ul(buf, res) + elif mode == 'dl': + do_mode_dl(buf, res) elif mode == 'hr': res.extend( [ { 'p': { 'hr': '/' } } ] * len(buf) ) elif mode == 'index':