#!/usr/bin/env bash
function markdown_h1() {
  local doc="$1" header="$2"

  jq_push "$doc" "# $header"
}

function markdown_h2() {
  local doc="$1" header="$2"
  jq_push "$doc" "## $header"
}

function markdown_h3() {
  local doc="$1" header="$2"
  jq_push "$doc" "### $header"
}

function markdown_h4() {
  local doc="$1" header="$2"
  jq_push "$doc" "#### $header"
}

function markdown_tab() {
  local doc="$1"
  local peek=".[length-1]"
  jq_set "$doc" "$peek" "\"  $(jq_get "$doc" "$peek")\""
}

function markdown_bullet() {
  local doc="$1" point="$2"
  jq_push "$doc" "- $point"
}

function markdown_line() {
  local doc="$1" content="$2"
  jq_push "$doc" "$content"
}

function markdown_nl() {
  jq_push "$1" ""
}

function markdown_code_start() {
  local doc="$1" lang="$2"
  jq_push "$doc" "\`\`\`$lang"
}

function markdown_code_end() {
  jq_push "$1" "\`\`\`"
}

function markdown_render() {
  jq -r 'join("\n")' <<< "$1"
}

function markdown_link() {
  local link="$1" text="${2:-$1}"
  echo "[$text]($link)"
}
