Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

solvaholic/md2html.sed

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

md2html.sed

Learn sed(1) by rendering Markdown to HTML

(And also by reading the O'Reilly sed & awk book)

Use md2html.sed

sed -f md2html.sed test.md

Test md2html.sed

diff -B <(sed -f md2html.sed test.md) test.html
diff <(sed -f md2html.sed test.md) <(gsed -f md2html.sed test.md)
sed -f md2html.sed README.md

Modify md2html.sed

  1. Make sure the script tests successfully, before changing it
  2. Add or modify Markdown in test.md
  3. Add or modify corresponding HTML in test.html
  4. Add or modify commands to render Markdown to HTML in md2html.sed
  5. Update README.md, if it's no longer correct
  6. Make sure the script tests successfully, after changing it

Which Markdown features are supported?

md2html.sed supports a small subset of Markdown features. See test.md for the current list.

md2html.sed should support ____

Kindly share your feedback in a pull request or an issue 🙇

How does md2html.sed work?

Expectations/Assumptions

In Markdown, use blank lines between different formats and layouts.

When script begins or ends, hold space contains all pending output.

Steps

  1. If pattern space is blank then swap hold to pattern and jump to :close
  2. If pattern begins with ``` then start or end a pre
  3. If hold space contains a pre tag then jump to :save
  4. Render links
  5. Render headings
  6. Render trailing spaces line breaks
  7. Render ordered lists
  8. Render unordered lists
  9. [:save] If pattern is not blank, append to hold and swap
  10. If not last line, swap pattern to hold and end
  11. [:close] If pattern is blank, delete and continue
  12. If pattern does not begin with <, render as p
  13. Close some opening tags: ol, ul, pre
  14. Render inline formatting: ` _ *
  15. Clear hold space

About

Learn sed(1) by rendering Markdown to HTML

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks