Skip to content

Commit

Permalink
Rework emphasis & strong
Browse files Browse the repository at this point in the history
  • Loading branch information
aarroyoc committed Jan 18, 2023
1 parent 5e89729 commit f919cd9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
32 changes: 14 additions & 18 deletions djota.pl
Original file line number Diff line number Diff line change
Expand Up @@ -435,42 +435,38 @@

emphasis_ast_([emphasis(InlineAst)|Ast0]) -->
( ("_", look_ahead(T), { T \= ' ' }) | "{_" ),
inline_text_ast_(InlineAst),
seq(Inline),
"_",
{
append(_, [End], InlineAst),
(
End = str(StrEnd) ->
( append(_, [EndChar], StrEnd), EndChar \= ' ' )
; true
)
append(_, [G], Inline),
G \= ' ',
inline_text_ast(Inline, InlineAst)
},
"_",
inline_text_ast_(Ast0).

emphasis_ast_([emphasis(InlineAst)|Ast0]) -->
( ("_", look_ahead(T), { T \= ' ' }) | "{_" ),
inline_text_ast_(InlineAst),
seq(Inline),
"_}",
{ inline_text_ast(Inline, InlineAst) },
inline_text_ast_(Ast0).

strong_ast_([strong(InlineAst)|Ast0]) -->
( ("*", look_ahead(T), { T \= ' ' }) | "{*" ),
inline_text_ast_(InlineAst),
seq(Inline),
"*",
{
append(_, [End], InlineAst),
(
End = str(StrEnd) ->
( append(_, [EndChar], StrEnd), EndChar \= ' ' )
; true
)
append(_, [G], Inline),
G \= ' ',
inline_text_ast(Inline, InlineAst)
},
"*",
inline_text_ast_(Ast0).

strong_ast_([strong(InlineAst)|Ast0]) -->
( ("*", look_ahead(T), { T \= ' ' }) | "{*" ),
inline_text_ast_(InlineAst),
seq(Inline),
"*}",
{ inline_text_ast(Inline, InlineAst) },
inline_text_ast_(Ast0).

verbatim_ast_([verbatim(Str)|Ast0]) -->
Expand Down
2 changes: 1 addition & 1 deletion test.lgt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ test(strong_ast) :-
djota:inline_text_ast("*HelloHello*Prolog*_!", [strong([str("HelloHello*Prolog")]),str("_!")]).

test(emphasis_strong) :-
djota:djot("Hello _Prolog_! You said: _I *need* to_wake up__", "<p>Hello <em>Prolog<em>! You said: <em>I <strong>need</strong> to</em>wake up</em></em></p>").
djota:djot("Hello _Prolog_! You said: _I *need* to_wake up__", "<p>Hello <em>Prolog</em>! You said: <em>I <strong>need</strong> to</em>wake up__</p>").

test(highlight_ast) :-
djota:inline_text_ast("Hello {=Prolog=}!", [str("Hello "), highlight("Prolog"), str("!")]).
Expand Down

0 comments on commit f919cd9

Please sign in to comment.