Skip to content

Commit

Permalink
Keep Block Attributes on sections
Browse files Browse the repository at this point in the history
  • Loading branch information
aarroyoc committed Jan 29, 2023
1 parent 60ea30d commit 45551fd
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions djota.pl
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@

% Block attribute
djot_ast_([Line|Lines], Attrs) -->
{ phrase(inline_attr_ast_(Attrs1), Line), append(Attrs, Attrs1, Attrs2) },
{ phrase(inline_attr_ast_single_(Attrs1), Line), append(Attrs, Attrs1, Attrs2) },
djot_ast_(Lines, Attrs2).


% Paragraph
djot_ast_([Line|Lines], Attrs) -->
Expand Down Expand Up @@ -159,10 +158,12 @@
append(SectionLines, [HeadingLine|Rest], Lines),
phrase(heading_line(NextN, _), HeadingLine),
NextN =< N,
phrase(djot_ast_(SectionLines, []), SectionAst)
section_lines_block(SectionLines, SectionLines1, BlockAttrs),
phrase(djot_ast_(SectionLines1, []), SectionAst),
append(BlockAttrs, [HeadingLine|Rest], NextLines)
},
[section(N, Header, SectionAst, Attrs)],
djot_ast_([HeadingLine|Rest], []).
djot_ast_(NextLines, []).

djot_heading_ast_([[]|Lines], N, Header, Attrs) -->
{
Expand All @@ -173,6 +174,15 @@
djot_heading_ast_([], N, Header, Attrs) -->
djot_heading_ast_([""], N, Header, Attrs).

section_lines_block([], [], []).
section_lines_block(Lines, LinesOut, Block) :-
append(Lines1, [BlockLine], Lines),
(
phrase(inline_attr_ast_single_(_), BlockLine) ->
(section_lines_block(Lines1, LinesOut, Block0), Block = [BlockLine|Block0])
; ( Lines = LinesOut, Block = [] )
).

heading_line(1, Header) --> "# ", seq(Header).
heading_line(2, Header) --> "## ", seq(Header).
heading_line(3, Header) --> "### ", seq(Header).
Expand Down

0 comments on commit 45551fd

Please sign in to comment.