src/Pure/Thy/markdown.ML
changeset 67322 734a4e44b159
parent 64357 e10fa8afc96c
child 67323 d02208cefbdb
equal deleted inserted replaced
67313:a2d7c0987f19 67322:734a4e44b159
    58   Line of
    58   Line of
    59    {source: Antiquote.text_antiquote list,
    59    {source: Antiquote.text_antiquote list,
    60     is_empty: bool,
    60     is_empty: bool,
    61     indent: int,
    61     indent: int,
    62     item: kind option,
    62     item: kind option,
    63     item_pos: Position.T,
    63     bullet_pos: Position.T,
    64     content: Antiquote.text_antiquote list};
    64     content: Antiquote.text_antiquote list};
    65 
    65 
    66 val eof_line =
    66 val eof_line =
    67   Line {source = [Antiquote.Text [(Symbol.eof, Position.none)]],
    67   Line {source = [Antiquote.Text [(Symbol.eof, Position.none)]],
    68     is_empty = false, indent = 0, item = NONE, item_pos = Position.none, content = []};
    68     is_empty = false, indent = 0, item = NONE, bullet_pos = Position.none, content = []};
    69 
    69 
    70 fun line_source (Line {source, ...}) = source;
    70 fun line_source (Line {source, ...}) = source;
    71 fun line_is_empty (Line {is_empty, ...}) = is_empty;
    71 fun line_is_empty (Line {is_empty, ...}) = is_empty;
    72 fun line_is_item (Line {item, ...}) = is_some item;
    72 fun line_is_item (Line {item, ...}) = is_some item;
    73 fun line_content (Line {content, ...}) = content;
    73 fun line_content (Line {content, ...}) = content;
    98   let val (indent, source') = strip_spaces source in
    98   let val (indent, source') = strip_spaces source in
    99     (case source' of
    99     (case source' of
   100       (control as Antiquote.Control {name = (name, pos), body = [], ...}) :: rest =>
   100       (control as Antiquote.Control {name = (name, pos), body = [], ...}) :: rest =>
   101         let
   101         let
   102           val item = AList.lookup (op =) kinds name;
   102           val item = AList.lookup (op =) kinds name;
   103           val item_pos = if is_some item then pos else Position.none;
   103           val bullet_pos = if is_some item then pos else Position.none;
   104           val (_, rest') = strip_spaces (if is_some item then rest else control :: rest);
   104           val (_, rest') = strip_spaces (if is_some item then rest else control :: rest);
   105         in ((indent, item, item_pos), rest') end
   105         in ((indent, item, bullet_pos), rest') end
   106     | _ => ((indent, NONE, Position.none), source'))
   106     | _ => ((indent, NONE, Position.none), source'))
   107   end;
   107   end;
   108 
   108 
   109 in
   109 in
   110 
   110 
   111 fun make_line source =
   111 fun make_line source =
   112   let
   112   let
   113     val _ = check_blanks source;
   113     val _ = check_blanks source;
   114     val ((indent, item, item_pos), content) = read_marker source;
   114     val ((indent, item, bullet_pos), content) = read_marker source;
   115   in
   115   in
   116     Line {source = source, is_empty = is_empty source, indent = indent,
   116     Line {source = source, is_empty = is_empty source, indent = indent,
   117       item = item, item_pos = item_pos, content = content}
   117       item = item, bullet_pos = bullet_pos, content = content}
   118   end;
   118   end;
   119 
   119 
   120 val empty_line = make_line [];
   120 val empty_line = make_line [];
   121 
   121 
   122 end;
   122 end;
   191 val text_reports =
   191 val text_reports =
   192   maps (fn Antiquote.Text ss => [(#1 (Symbol_Pos.range ss), Markup.words)] | _ => []);
   192   maps (fn Antiquote.Text ss => [(#1 (Symbol_Pos.range ss), Markup.words)] | _ => []);
   193 
   193 
   194 local
   194 local
   195 
   195 
   196 fun line_reports depth (Line {item_pos, content, ...}) =
   196 fun line_reports depth (Line {bullet_pos, content, ...}) =
   197   cons (item_pos, Markup.markdown_item depth) #> append (text_reports content);
   197   cons (bullet_pos, Markup.markdown_bullet depth) #> append (text_reports content);
   198 
   198 
   199 fun block_reports depth block =
   199 fun block_reports depth block =
   200   (case block of
   200   (case block of
   201     Par lines =>
   201     Par lines =>
   202       cons (#1 (block_range block), Markup.markdown_paragraph) #>
   202       cons (#1 (block_range block), Markup.markdown_paragraph) #>