Skip to content

Instantly share code, notes, and snippets.

@alganet
Created May 27, 2015 04:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alganet/bbf6dc73c949ca9b0316 to your computer and use it in GitHub Desktop.
Save alganet/bbf6dc73c949ca9b0316 to your computer and use it in GitHub Desktop.
:on_stream
/^0 \(.*\)$/ { b on_document }
n
b on_stream
:on_document
s/^.*$/DOC1 &/;p
n
:on_document_back
/^[0-9][0-9]* \(.*\)$/ { b on_body }
b on_stream
:on_body
s/^.*$/TXT1 &/;p
n
:on_body_back
/^0 \(.*\)$/ { b on_document }
/^[0-9][0-9]* \(.*\)$/ { b on_code_indented }
/^[0-9][0-9]* \(~~~\|```\)$/ { h ; b on_code_fenced }
/^[0-9][0-9]* \(\[\]\:\)\([a-zA-Z0-9]*\)\s*(*\([^)]*\)\s*)*\s*$/ { b on_reference }
/^[0-9][0-9]* \(.*\)$/ { b on_body }
b on_stream
:on_reference
s/^.*$/REF1 &/;p
n
b on_body_back
:on_code_indented
s/^.*$/PRE1 &/;p
n
:on_code_indented_back
/^[0-9][0-9]* \(.*\)$/ { b on_code_indented }
/^[0-9][0-9]* $/ { b on_code_indented }
/^[0-9][0-9]* \(.*\)$/ { b on_body }
b on_stream
:on_code_fenced
s/^.*$/PRE2 &/;p
n
:on_code_fenced_back
/^[0-9][0-9]* \(~~~\|```\)$/ {
G
/^[0-9][0-9]* ~~~\
[0-9][0-9]* ~~~$/ { b on_code_fenced_close }
/^[0-9][0-9]* ```\
[0-9][0-9]* ```$/ { b on_code_fenced_close }
s/^\([0-9][0-9]* \)\(~~~\|```\).*$/\1\2/
b on_code_fenced
}
b on_code_fenced
:on_code_fenced_close
s/^\([0-9][0-9]* \)\(~~~\|```\).*$/\1\2/
s/^.*$/PRE3 &/;p
n
b on_body_back
$(fnc stream)
${find_document} { $(jmp document) }
n
$(jmp stream)
$(def document DOC1)
${find_anything} { $(jmp body) }
$(jmp stream)
$(def body TXT1)
${find_document} { $(jmp document) }
${find_codeblock} { $(jmp code_indented) }
${find_fence} { h ; $(jmp code_fenced) }
${find_context} { $(jmp reference) }
${find_anything} { $(jmp body) }
$(jmp stream)
$(fnc reference)
$(dmp REF1)
n
$(jmp body back)
$(def code_indented PRE1)
${find_codeblock} { $(jmp code_indented) }
/^${line}$/ { $(jmp code_indented) }
${find_anything} { $(jmp body) }
$(jmp stream)
$(def code_fenced PRE2)
${find_fence} {
G
/^${line}~~~\\
${line}~~~$/ { $(jmp code_fenced_close) }
/^${line}\`\`\`\\
${line}\`\`\`$/ { $(jmp code_fenced_close) }
${coalesce_fence}
$(jmp code_fenced)
}
$(jmp code_fenced)
$(fnc code_fenced_close)
${coalesce_fence}
$(dmp PRE3)
n
$(jmp body back)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment