; docformat = 'rst' ;+ ; Get the first line of text given a markup tree and return it as another ; markup tree (copying nodes in the original tree where necessary). ; ; :Returns: another markup tree ; ; :Params: ; tree : in, required, type=object ; markup tree ;- function mg_tm_firstline, tree compile_opt strictarr firstline = obj_new('MGtmTag') ; depth first search to find the first paragraph firstpara = tree firstpara->getProperty, type=type nchildren = 1 while (obj_class(firstpara) eq 'MGTMTAG' $ && type ne 'paragraph' $ && nChildren gt 0) do begin firstpara->getProperty, n_children=nChildren if (nChildren gt 0) then begin firstpara = firstpara->getChild(0) firstpara->getProperty, type=type endif endwhile ; add children of the first paragraph to firstline if (type eq 'paragraph') then begin para = obj_new('MGtmTag', type='paragraph') firstline->addChild, para firstpara->getProperty, n_children=nChildren for c = 0L, nChildren - 1L do begin child = firstpara->getChild(c) if (obj_class(child) eq 'MGTMTEXT') then begin ; if it's MGtmText node, then add it (until the .) child->getProperty, text=text dotpos = stregex(text, '\.([[:space:]]|$)') newText = dotpos eq -1L ? text : strmid(text, 0, dotpos + 1L) textNode = obj_new('MGtmText', text=newText) para->addChild, textNode if (dotpos ne -1L) then break endif endfor endif ; return our contructed firstline return, firstline end