1111
1212_BLOCK_TAGS = {tag .lower () for tag in block_parser .BLOCK_TAGS }
1313_HEADING_LINE_RE = re .compile (r'^(\s*)(#{1,6})(?!#)(?=\S)' )
14- _REF_LINK_OR_IMAGE_RE = re .compile (r'!?\[[^\]]+\]\[[^\]]+ \]' )
14+ _REF_LINK_OR_IMAGE_RE = re .compile (r'!?\[[^\]]+\]\s*\ [[^\]]* \]' )
1515_REF_DEF_LINE_RE = re .compile (r'^\s{0,3}\[[^\]]+\]:\s+\S+' )
1616_FENCE_RE = re .compile (r'^\s*(```|~~~)' )
17+ _INLINE_MARKERS = {
18+ 'strong' : '**' ,
19+ 'emphasis' : '*' ,
20+ 'strikethrough' : '~~' ,
21+ }
1722
1823
1924class MdParser :
@@ -134,6 +139,14 @@ def flush_buffer():
134139 url = attrs .get ('url' , '' )
135140 title = attrs .get ('title' )
136141 nodes .append (Image (_format_image_markup (alt , url , title )))
142+ elif token_type in _INLINE_MARKERS :
143+ flush_buffer ()
144+ marker = _INLINE_MARKERS [token_type ]
145+ _append_text (nodes , marker )
146+ children = token .get ('children' , [])
147+ if children :
148+ nodes .extend (self ._convert_inline_tokens (children ))
149+ _append_text (nodes , marker )
137150 else :
138151 flush_buffer ()
139152 children = token .get ('children' , [])
@@ -155,6 +168,10 @@ def _flatten_inline_text(self, tokens: Iterable[dict]):
155168 parts .append (token .get ('raw' ) or token .get ('text' ) or '' )
156169 elif token_type == 'codespan' :
157170 parts .append (f"`{ token .get ('raw' ) or token .get ('text' ) or '' } `" )
171+ elif token_type in _INLINE_MARKERS :
172+ marker = _INLINE_MARKERS [token_type ]
173+ inner = self ._flatten_inline_text (token .get ('children' , []))
174+ parts .append (f'{ marker } { inner } { marker } ' )
158175 elif token_type in {'linebreak' , 'softbreak' }:
159176 parts .append (' ' )
160177 else :
0 commit comments