Advertisement
GeneralGuy4872

markdowntohtml2.awk

Dec 22nd, 2018
3,901
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Awk 0.53 KB | None | 0 0
  1. BEGIN {FS = "\n"; RS = "\n\n";
  2. printf("<!DOCTYPE html PUBLIC \"-//IETF//DTD HTML 2.0//EN\"><HTML>\n<HEAD>\n<TITLE>MARKDOWN DOCUMENT (TRANSLATED TO HTML2.0)</TITLE>\n</HEAD>\n<BODY>\n");
  3. }
  4. {
  5. if ($2 ~ /[===]+/)
  6.     myheader()
  7. else if ($2 ~ /[---]+/)
  8.     mysubheader()
  9. else
  10.     myparagraph()
  11. }
  12. function myheader(){
  13. printf("<H1>\n");print $1;printf("</H1>\n");
  14. }
  15. function mysubheader(){
  16. printf("<H3>\n");print $1;printf("</H3>\n");
  17. }
  18. function myparagraph(){
  19. printf("<P>\n");print $0;printf("\n</P>\n")
  20. }
  21. END {
  22. printf("</BODY></HTML>")
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement