Code Markdown to Structured Pseudo-code
Convert very simple markdown syntax to very simple pseudo-code.
Code markdown is line-oriented whereas pseudo-code is structure-oriented (braces indicate inclusion).
Basic Premise
Use markdown-mode
of emacs to write code and elide details.
Elision in Emacs Org-Mode
Position mouse over a line containing an octothorpe #
.
Press TAB
key.
This will open/close a layer.
Pressing TAB
key again and again will toggle between elided and non-elided forms of the text.
Italicized Identifiers
Possible convention, italicized identifiers can include spaces (but not underscores - this can be changed later to be some other character or sequence) and are considered to be comments.
Example
Input
# _containment_
## _fb pipeline_
allContains1
printAllDeepContains
printAllDirectContains
## _details_
### allContains1
load fb
load onSameDiagram
load contain1
### printAllDeepContains
load fb
load onSameDiagram
load contains2
### printAllDirectContains
load fb
load onSameDiagram
load contains3
Output
{_containment_
{_fb pipeline_
allContains1
printAllDeepContains
printAllDirectContains
}
{_details_
{allContains1
load fb
load onSameDiagram
load contain1
}
{printAllDeepContains
load fb
load onSameDiagram
load contains2
}
{printAllDirectContains
load fb
load onSameDiagram
load contains3
}}}
Algorithm
A section beginning with an octothorpe #
is composed of 3 parts:
- The octothorpe
#
- The first text up to \n
- The rest of the text up to the next octothorpe (incl. \nās).
# a b
## c d
## e f
is converted to
{ a b { c d } { e f }}
using a simple algorithm, see md2brace.html and support.js.
- Set two counters to 0. (depth and openbrackets).
- When a
#
is encountered, determine new depth as the number of#
s. If newdepth > depth, emit an open brace{
, if newdepth === depth emit close and open}\n{
, otherwise panic. Set depth to newdepth, increment openbrackets by number of{
that were added. - At the end, emit one ā}ā for each openbracket.
No judgement is made about the contents of a,b,c,d,e,f. (That is left up to other tools).