~sforman/Pagemage

f631f757ce37b83cfa6ade24e8e489752e9d9a80 — sforman 5 months ago 68771bc trunk
Pass through syntax tag for PRE blocks.

It's just Prolog and Python.
1 files changed, 13 insertions(+), 5 deletions(-)

M src/gemtext.pl
M src/gemtext.pl => src/gemtext.pl +13 -5
@@ 19,6 19,10 @@
*/


% Print debug messages.
% p(Message) :- print(user_error, Message), nl(user_error).


gem_blank(32). % Space
gem_blank(9).  % Tab



@@ 72,8 76,9 @@ gem_text([line(Line)|Gs]) -->
gem_text([]) --> [].


gem_pre_syntax(prolog) --> "prolog",
    gem_blanks, "\n".
gem_pre_syntax(prolog) --> "prolog", gem_blanks, "\n".
gem_pre_syntax(python) --> "python", gem_blanks, "\n".
gem_pre_syntax(python) --> "Python", gem_blanks, "\n".


gem_pre([]) --> "```\n", !.


@@ 114,8 119,8 @@ gem_html([ heading2(Heading)  |Gs]) --> "<h2>", Heading, "</h2>\n", gem_html(Gs)
gem_html([ heading3(Heading)  |Gs]) --> "<h3>", Heading, "</h3>\n", gem_html(Gs).
gem_html([ block_quote(BQ)    |Gs]) --> "<blockquote>", BQ, "</blockquote>\n", gem_html(Gs).
gem_html([ pre(Codes)         |Gs]) --> "<pre>", Codes, "</pre>\n", gem_html(Gs).
gem_html([ pre(_Syntax, Codes)|Gs]) --> % TODO: use _Syntax to pick syntax. In gem_text//1.
    { highlight_prolog(Codes, HTML) },  HTML, gem_html(Gs).
gem_html([ pre(Syntax, Codes)|Gs]) -->
    { highlight(Syntax, Codes, HTML) },  HTML, gem_html(Gs).
gem_html([ line(Line)         |Gs]) --> "<p>", Line, "</p>\n", gem_html(Gs).
gem_html([ ull(ULs)           |Gs]) --> "<ul>\n", uls(ULs), "</ul>\n", gem_html(Gs).
gem_html([ ul(LI)             |Gs]) --> gem_html([ull([LI])|Gs]).


@@ 162,9 167,12 @@ do :-
:- initialization(do).


highlight_prolog(PrologCodes, HTMLCodes) :-
highlight(prolog, PrologCodes, HTMLCodes) :-
    pipe('pygmentize -l prolog -f html', PrologCodes, HTMLCodes).

highlight(python, PrologCodes, HTMLCodes) :-
    pipe('pygmentize -l python -f html', PrologCodes, HTMLCodes).


rest_of_line(_Line, [], _) :- !, fail.
rest_of_line(Line, Codes, Rest) :- append(Line, [10|Rest], Codes), !.