Changeset 481

Show
Ignore:
Timestamp:
03/04/08 12:58:42 (4 years ago)
Author:
mgalloy
Message:

Added image directives to rst markup parser.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/idldoc/src/parser/docparrstmarkupparser__define.pro

    r444 r481  
    1010;   #. (not implemented) code can be marked as `a = findgen(10)` 
    1111;   #. (not implemented) links: single word and phrase links 
     12;   #. images 
    1213;   #. code callouts like:: 
    1314 
     
    2021;- 
    2122 
     23 
     24;+ 
     25; Process directives. 
     26;- 
     27pro docparrstmarkupparser::_processDirective, line, pos, len, tree=tree 
     28  compile_opt strictarr 
     29   
     30  fullDirective = strmid(line, pos + 3L, len) 
     31  tokens = strsplit(fullDirective, '::[[:space:]]+', /regex, /extract) 
     32   
     33  case strlowcase(tokens[0]) of 
     34    'image': begin 
     35        tag = obj_new('MGtmTag', type='image') 
     36        tag->addAttribute, 'source', tokens[1] 
     37      end 
     38    else: self.system->warning, 'unknown rst directive ' + tokens[0] 
     39  endcase 
     40 
     41  beforeDirective = strmid(line, 0, pos) 
     42  afterDirective = strmid(line, pos + len) 
     43  tree->addChild, obj_new('MGtmText', text=beforeDirective) 
     44  tree->addChild, tag 
     45  tree->addChild, obj_new('MGtmText', text=afterDirective) 
     46  tree->addChild, obj_new('MGtmTag', type='newline') 
     47end 
    2248 
    2349;+ 
     
    4470   
    4571  for l = 0L, n_elements(lines) - 1L do begin 
    46     cleanLine = strtrim(lines[l], 0) 
     72    cleanline = strtrim(lines[l], 0) 
    4773    dummy = stregex(lines[l], ' *[^[:space:]]', length=currentIndent) 
    4874     
     
    5278    endif 
    5379     
    54     nextIsCode = strmid(cleanLine, 1, /reverse_offset) eq '::' 
     80    nextIsCode = strmid(cleanline, 1, /reverse_offset) eq '::' 
    5581     
    5682    if (nextIsCode) then cleanline = strmid(cleanline, 0, strlen(cleanline) - 1) 
    5783     
    58     if (code && (currentIndent eq -1 || currentIndent gt indent)) then begin 
    59       listing->addChild, obj_new('MGtmText', text=strmid(cleanline, indent)) 
    60       listing->addChild, obj_new('MGtmTag', type='newline') 
    61     endif else begin      
    62       para->addChild, obj_new('MGtmText', text=cleanline) 
    63       para->addChild, obj_new('MGtmTag', type='newline') 
     84    directivePos = stregex(cleanline, '\.\. [[:alpha:]]+:: [[:alnum:]_/.\-]+', $ 
     85                           length=directiveLen) 
     86     
     87    if ((~code || (currentIndent gt -1 && currentIndent le indent)) && directivePos ne -1L) then begin 
     88      self->_processDirective, cleanline, directivePos, directiveLen, tree=para 
    6489      code = 0B 
     90    endif else begin 
     91      if (code && (currentIndent eq -1 || currentIndent gt indent)) then begin 
     92        listing->addChild, obj_new('MGtmText', text=strmid(cleanline, indent)) 
     93        listing->addChild, obj_new('MGtmTag', type='newline') 
     94      endif else begin      
     95        para->addChild, obj_new('MGtmText', text=cleanline) 
     96        para->addChild, obj_new('MGtmTag', type='newline') 
     97        code = 0B 
     98      endelse 
    6599    endelse 
    66100