squeeze

A static site generator that can put the toothpaste back in the tube.
git clone https://git.stjo.hn/squeeze
Log | Files | Refs | README | LICENSE

parse_entry.pl (1711B)


      1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      2 % File: parse_entry.pl
      3 % Description: Predicates to generate and parse a static site's Markdown/HTML.
      4 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      5 
      6 :- include('helpers.pl').
      7 :- include('markdown.pl').
      8 
      9 % parse_entry.
     10 %	Read in an HTML file from stdin.
     11 parse_entry:-
     12 	read_file(user_input, HTML),
     13 	parse_html(HTML).
     14 
     15 % parse_entry(+Filename).
     16 %	Read in an HTML file from Filename.
     17 parse_entry(Filename):-
     18 	open(Filename, read, Stream),
     19 	read_file(Stream, HTML),
     20 	close(Stream),
     21 	parse_html(HTML).
     22 
     23 
     24 % parse_html(+HTML).
     25 %	Parse HTML into a Markdown file and write to stdout.
     26 parse_html(HTML):-
     27 	page(EntryCodes, Title, Subtitle, Date, _, HTML, []),
     28 	markdown(EntryCodes, Title, Subtitle, Date, MarkdownCodes, []),
     29 	write_codes(user_output, MarkdownCodes),
     30 	halt.
     31 
     32 
     33 % generate_entry.
     34 %	Read in a Markdown file from stdin.
     35 generate_entry:-
     36 	read_file(user_input, Entry),
     37 	generate_html(Entry).
     38 
     39 % generate_entry(Filename).
     40 %	Read in a Markdown file from Filename.
     41 generate_entry(Filename):-
     42 	open(Filename, read, Stream),
     43 	read_file(Stream, Entry),
     44 	close(Stream),
     45 	generate_html(Entry).
     46 
     47 
     48 % generate_html(Markdown).
     49 %	Parse Markdown into an HTML file and write to stdout.
     50 generate_html(Markdown):-
     51 	markdown(EntryCodes, Title, Subtitle, Date, Markdown, []),
     52 	clean_title(Title, CleanTitle),
     53 	page(EntryCodes, Title, Subtitle, Date, CleanTitle, HTMLCodes, []),
     54 	write_codes(user_output, HTMLCodes),
     55 	halt.
     56 
     57 
     58 % clean_title(+Title, -CleanTitle).
     59 % 	Replace select HTML tags in an entry title to make it suitable
     60 % 	for an HTML title.
     61 clean_title(null, null).
     62 
     63 clean_title(Title, CleanTitle):-
     64 	replace("<cite>", "\"", Title, Title1),
     65 	replace("</cite>", "\"", Title1, CleanTitle).