:- begin_tests(md_html). % Integration tests with SWI-Prolog's html_write % module. :- use_module(library(http/html_write)). :- use_module(library(apply)). :- use_module(prolog/md/md_span). :- use_module(prolog/md/md_parse). % Helper to turn Markdown span elements % into HTML code (atom). span_html(String, Html):- string_codes(String, Codes), md_span_codes(Codes, Spans), phrase(html(Spans), Tokens), strip_layout(Tokens, Clean), with_output_to(atom(Html), print_html(Clean)). % Helper to turn Markdown into HTML code (atom). html(String, Html):- md_parse_string(String, Blocks), phrase(html(Blocks), Tokens, []), strip_layout(Tokens, Clean), with_output_to(atom(Html), print_html(Clean)). strip_layout(In, Out):- exclude(layout, In, Out). layout(nl(_)). layout(mailbox(_, _)). test(special_amp):- span_html("AT&T", 'AT&T'). test(special_amp_noescape):- span_html("AT&T", 'AT&T'). test(special_lt):- span_html("1<2", '1<2'). test(strong):- span_html("**abc**", 'abc'). test(emphasis):- span_html("*abc*", 'abc'). test(link):- span_html("[label](http://google.com)", 'label'). test(link_entities):- span_html("[label](http://google.com?q=abc&s=def)", 'label'). test(code_2):- span_html("``abc``", 'abc'). test(code_2_escape):- span_html("````", '<blink>'). test(strong_emb_html):- span_html("**abcanchor**", 'abcanchor'). test(emphasis_escape):- span_html("\\*abc\\*", '*abc*'). test(paragraph):- html("abc", '

abc

'). test(two_paragraphs):- html("abc\n\ndef", '

abc

def

'). test(html_block):- html("
*abc*
", '
*abc*
'). test(span_paragraph):- html("abc **def** ghi", '

abc def ghi

'). test(heading1):- html("Hello\n=====", '

Hello

'). test(code_block):- html("\ta = 1;\n\tb = 2;\n\tc = a + b;", '
a = 1;\nb = 2;\nc = a + b;
'). test(code_block_escape):- html("\ta = 1;\n\tb = 2;\n\tc = a < b;", '
a = 1;\nb = 2;\nc = a < b;
'). test(script_span):- html("abc def", '

abc def

'). :- end_tests(md_html).