murkdown 0.1.1

An experimental semantic markup language and static site generator for composing and decomposing hypertext documents
Documentation
RULES FOR html PRODUCE text/html

/* ------------------------------------------------ */
PREPROCESS RULES:
/* list */
[LIST...] [SEC...]$
  NOOP

/* image */
[...IMAGE...]$
  IS REF-BY-COPY

/* code */
[...CODE...] [SEC...]$
  NOOP

/* other */
[SEC...]$
  IS PARAGRAPHABLE

/* ------------------------------------------------ */
COMPILE RULES:

[...TIP...]$
  IS COMPOSABLE
  PUSH class "tip"

[...NOTE...]$
  IS COMPOSABLE
  PUSH class "note"

[...QUOTE...]$
  IS COMPOSABLE
  PUSH class "quote"

/* tabs */
[...TABS...] [SEC...] [...TABS...]$
  WRITEALL indent
  WRITE "<input type=\"radio\" name=\"$tabid-r\" id=\"$tabid-\i\" value=\"dummy\" $checked />\n"
  DRAIN checked
  WRITEALL indent
  WRITE "<label for=\"$tabid-\i\">$id</label>\n"
  /* start a new tab */
  SET checked "checked"
  SET tabid "\r"
  WRITE "<div class=\"tabs tabs-content $class:j\" name=\"$tabid-f\">\n"
  DRAIN class
  PUSH indent "  "
  YIELD
  WRITE "\n"
  POP indent
  WRITEALL indent
  WRITE "</div>\n"

[...TABS...]$
  WRITEALL indent
  SET checked "checked"
  SET tabid "\r"
  WRITE "<div class=\"tabs $class:j\" name=\"$tabid-f\">\n"
  DRAIN class
  PUSH indent "  "
  YIELD
  WRITE "\n"
  POP indent
  WRITEALL indent
  WRITE "</div>"

[...TABS...] [SEC...] [...]$
  IS COMPOSABLE
  WRITEALL indent
  WRITE "<input type=\"radio\" name=\"$tabid-r\" id=\"$tabid-\i\" value=\"dummy\" $checked />\n"
  DRAIN checked
  WRITEALL indent
  WRITE "<label for=\"$tabid-\i\">$id</label>\n"
  PUSH class "tabs-content"

/* list */
[...LIST...]$
  WRITEALL indent
  WRITE "<ul class=\"$class:j\">\n"
  DRAIN class
  PUSH indent "  "
  YIELD
  WRITE "\n"
  POP indent
  WRITEALL indent
  WRITE "</ul>"

[...LIST...] [SEC...]$
  IS COMPOSABLE
  YIELD

[...LIST...] [SEC...] [...]$
  IS COMPOSABLE
  WRITEALL indent
  WRITE "<li>\n"
  PUSH indent "  "
  YIELD
  POP indent
  WRITE "\n"
  WRITEALL indent
  WRITE "</li>"

[...LIST...] [SEC...] LINE$
  IS COMPOSABLE
  PUSH prefix "<li>"
  PUSH suffix "</li>"
  YIELD
  POP prefix
  POP suffix

/* link */
[...LINK...]$
  WRITEALL indent
  WRITE "<a href=\"$href\" class=\"$class:j\">\n"
  DRAIN class
  PUSH indent "  "
  YIELD
  POP indent
  WRITE "\n"
  WRITEALL indent
  WRITE "</a>"

/* image & figure */
[...FIGURE...]$
  WRITEALL indent
  WRITE "<figure>\n"
  PUSH indent "  "
  YIELD
  WRITE "\n"
  POP indent
  WRITEALL indent
  WRITE "</figure>"

[...FIGURE...] [SEC...] [...IMAGE...]$
  WRITEALL indent
  WRITE "<img src=\"$ref\" />\n"
  WRITEALL indent
  WRITE "\n"
  WRITEALL indent
  WRITE "<figcaption>\n"
  PUSH indent "  "
  YIELD
  WRITE "\n"
  POP indent
  WRITEALL indent
  WRITE "</figcaption>"

[...IMAGE...]$
  WRITEALL indent
  WRITE "<img src=\"$ref\" class=\"$class:j\" alt=\""
  DRAIN class
  YIELD
  WRITE "\" />"

[...IMAGE...] LINE$
  WRITE "\v"

[...IMAGE...] [...]$
  NOOP

/* code */
[CODE]$
  SET language "$language"
  YIELD
  SET language ""

[...CODE...]$
  SET language "$language"
  YIELD
  SET language ""

[...CODE...] [SEC...]$
  WRITEALL indent
  WRITE "<pre class=\"code $class:j\"><code class=\"language-$language\">"
  DRAIN class
  YIELD
  WRITE "\n"
  WRITE "</code></pre>"

[...CODE...] [SEC...] LINE$
  WRITEALL prefix
  WRITE "\v"
  WRITEALL suffix

/* heading */
[...]( [SEC...] [...HEADING...]){3}$
  SET prefix "<h2>"
  SET suffix "</h2>"
  YIELD
  POP prefix
  POP suffix

[...]( [SEC...] [...HEADING...]){2}$
  SET prefix "<h2>"
  SET suffix "</h2>"
  YIELD
  POP prefix
  POP suffix

[...]( [SEC...] [...HEADING...]){1}$
  PUSH prefix "<h1>"
  PUSH suffix "</h1>"
  YIELD
  POP prefix
  POP suffix

/* paragraph */
[PAR...]$
  WRITEALL indent
  WRITE "<p>\n"
  PUSH indent "  "
  YIELD
  POP indent
  WRITE "\n"
  WRITEALL indent
  WRITE "</p>"

/* website */
^[...WEBSITE...]$
  IS COMPOSABLE
  WRITE "<!DOCTYPE html>\n"
  WRITE "<html lang=\"$lang\">\n"
  WRITE "<head>\n"
  PUSH indent "  "
  WRITE "  <title>$title</title>\n"
  WRITE "  <meta charset=\"utf-8\">\n"
  WRITE "  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n"
  WRITEALL indent
  WRITE "<style>"
  WRITE "ul { padding-left: 1.5rem; } "
  WRITE ".quote { background: #f9f9f9; border-left: .25em solid #ccc; margin: 1.5em 0; padding: 0.5em; quotes: \"\201C\" \"\201D\" \"\2018\" \"\2019\"; } "
  WRITE ".quote:before { color: #ccc; content: open-quote; font-size: 4em; line-height: 1rem; height: 0; display: block; } "
  WRITE ".tip { margin-bottom: 16px; color: inherit; border-left: .25em solid rgb(26, 127, 55); } "
  WRITE ".tip::before { margin-left: 0.5rem; content: \"⚲ Tip\"; color: rgb(26, 127, 55); margin-right: 0.5rem; font-size: 1rem; } "
  WRITE ".note { margin-bottom: 16px; color: inherit; border-left: .25em solid rgb(9, 105, 218); } "
  WRITE ".note::before { margin-left: 0.5rem; content: \"ⓘ Note\"; color: rgb(9, 105, 218); margin-right: 0.5rem; font-size: 1rem; } "
  WRITE ".tabs { display: grid; grid-auto-columns: 1fr; margin: 0; } "
  WRITE ".tabs > label { grid-row: 1; display: block; padding: 2px 10px 0px 10px; text-align: center; border: solid var(--border); border-width: 1px 1px 0 1px; border-radius: 10px 10px 0px 0px; color: #514f4f; } "
  WRITE ".tabs label > p { line-height: 0; font-size: 12px; } "
  WRITE ".tabs label:hover { cursor: pointer; background-color: #bbb; } "
  WRITE ".tabs input:checked + label { background-color: var(--accent-bg); color: var(--accent); box-shadow: 5px 0px 7px #aaa; z-index: 0; } "
  WRITE ".tabs input { display: none; } "
  WRITE ".tabs input:checked + label + .tabs-content { display: block; grid-column-start: span 10; } "
  WRITE ".tabs input:checked + label + .tabs.tabs-content { display: grid; } "
  WRITE ".tabs > .tabs-content { grid-row: 2; display: none; margin-top: 0 !important; z-index: 1; } "
  WRITE ".code.tabs-content { border-top-left-radius: 0; } "
  WRITE "pre { background-color: #f3f3f3; padding-left: 0.5rem; } "
  WRITE "</style>\n"
  YIELD

^[SIMPLE WEBSITE...]$
  IS COMPOSABLE
  WRITEALL indent
  WRITE "<link rel=\"stylesheet\" href=\"https://cdn.simplecss.org/simple.min.css\">\n"
  WRITEALL indent
  WRITE "<link rel=\"stylesheet\" href=\"https://unpkg.com/@highlightjs/cdn-assets@11.10.0/styles/default.min.css\">\n"
  WRITEALL indent
  WRITE "<script src=\"https://unpkg.com/@highlightjs/cdn-assets@11.10.0/highlight.min.js\"></script>\n"
  WRITEALL indent
  WRITE "<style>"
  WRITE ".hljs { background: unset; } "
  WRITE "</style>\n"

^[SLIDESHOW WEBSITE...]$
  IS COMPOSABLE
  WRITEALL indent
  WRITE "<link rel=\"stylesheet\" href=\"https://unpkg.com/reveal.js@^5//dist/reset.css\">\n"
  WRITEALL indent
  WRITE "<link rel=\"stylesheet\" href=\"https://unpkg.com/reveal.js@^5//dist/reveal.css\">\n"
  WRITEALL indent
  WRITE "<link rel=\"stylesheet\" href=\"https://unpkg.com/reveal.js@^5//dist/theme/white.css\" id=\"theme\">\n"
  WRITEALL indent
  WRITE "<link rel=\"stylesheet\" href=\"https://unpkg.com/@highlightjs/cdn-assets@11.4.0/styles/default.min.css\">\n"
  PUSH class "reveal"

^[...WEBSITE...]$
  IS COMPOSABLE
  WRITE "</head>\n"
  WRITE "<body class=\"$class:j\">\n"
  DRAIN class
  YIELD
  WRITE "</html>\n"

^[...WEBSITE...]$
  IS COMPOSABLE
  YIELD
  POP indent
  WRITE "</body>\n"

^[SLIDESHOW WEBSITE...]$
  IS COMPOSABLE
  WRITEALL indent
  WRITE "<div class=\"slides\">\n"
  PUSH indent "  "
  YIELD
  POP indent
  WRITE "\n"
  WRITEALL indent
  WRITE "</div>\n"
  WRITE "  <script type=\"module\">\n    import Reveal from 'https://unpkg.com/reveal.js@^5//dist/reveal.esm.js';\n    import Highlight from 'https://unpkg.com/reveal.js@^5//plugin/highlight/highlight.esm.js';\n    Reveal.initialize({ plugins: [Highlight] });\n  </script>\n"

^[SIMPLE WEBSITE...]$
  IS COMPOSABLE
  YIELD
  POP indent
  WRITE "\n"
  WRITE "  <script>hljs.highlightAll();</script>\n"

^[...WEBSITE...] [SEC...HEADER]$
  WRITEALL indent
  WRITE "<header>\n"
  PUSH indent "  "
  YIELD
  WRITE "\n"
  POP indent
  WRITEALL indent
  WRITE "</header>\n"

^[...SLIDESHOW...] [SEC...]$
  WRITEALL indent
  WRITE "<section class=\"$class:j\">"
  DRAIN class
  PUSH indent "  "
  YIELD
  WRITE "\n"
  POP indent
  WRITEALL indent
  WRITE "</section>\n"

^[...WEBSITE...] [SEC...]$
  WRITEALL indent
  WRITE "<main class=\"$class:j\">"
  DRAIN class
  PUSH indent "  "
  YIELD
  WRITE "\n"
  POP indent
  WRITEALL indent
  WRITE "</main>\n"

^[...WEBSITE...] .*[...NAV...]$
  WRITEALL indent
  WRITE "<nav class=\"$class:j\">\n"
  DRAIN class
  PUSH indent "  "
  YIELD
  WRITE "\n"
  POP indent
  WRITEALL indent
  WRITE "</nav>\n"

^[...WEBSITE...] .*[...ASIDE...]$
  WRITEALL indent
  WRITE "<aside class=\"$class:j\">\n"
  DRAIN class
  PUSH indent "  "
  YIELD
  WRITE "\n"
  POP indent
  WRITEALL indent
  WRITE "</aside>\n"

/* other */
[SEC...]$
  NOOP

/* root */
^[...]$
  SET join "\n"

[...]$
  WRITEALL indent
  WRITE "<div class=\"$class:j\">\n"
  DRAIN class
  PUSH indent "  "
  YIELD
  WRITE "\n"
  POP indent
  WRITEALL indent
  WRITE "</div>"

LINE$
  WRITEALL indent
  WRITEALL prefix
  WRITE "\v"
  WRITEALL suffix