[idea]Compatible code for Markdown literary programming

2 points by lincpa ↗ HN
Compatible code for Markdown literary programming. Just add a custom line comment character before each line of Markdown.

When previewing or converting a format, you only need to simply preprocess: replace the `\r\n\;` with `\r\n` (note: line comment character of Clojure is `;`)

For example:

```

;# Markdown literary programming

;## example01:

;```clojure

(defn f [[evens odds total amax amin] x]

  (let [[evens odds] (cond 

                       (even? x) [(inc evens ) odds]

                       (odd? x)  [evens (inc odds)]

                       :else     [evens odds])

        total (+ total x)

        amax  (max amax x)

        amin  (min amin x)]   

     [evens odds total amax amin]))
(reduce f [0 0 0 ##-Inf ##Inf] [5 6 8 -3 -9 11 156 6 7])

;```

;`=>[4 5 187 156 -9]`

```

7 comments

[ 2.8 ms ] story [ 23.4 ms ] thread
Curious if you are familiar with Emacs, org-mode, and Babel.

https://orgmode.org/

https://orgmode.org/worg/org-contrib/babel/

There are many editors that support markdown, and markdown is simpler, so you can simply draw flowcharts, tables, task list, and display data visualizations image in comments of code.
I don't disagree. I'm biased toward Emacs because it supports so many languages, from the mainstream like Clojure, Ruby, and Python to the niche languages like Dot, PlantUML, and Standard ML.

What Babel+org-mode do for me is all the tangling and weaving of my literate programs. It will handle the creation of multiple files from a single document. For example I can create a literate document that includes leiningen configuration, clojure source, a readme.md, and an HTML version of the literate program document for Github pages all at once with a single command (M-x org-babel-tangle). Within the document I have Emacs full suite of source code tools: syntax highlighting, indentation, paredit, REPL's etc. for all the different languages in my literate document.

Now all that comes with the caveat that I'm not really interested in writing my own tangling and weaving tools for literate programming. Glue code to make my workflow easier is enough. Of course, there was a point five or six years ago when I mostly committed to the Emacs learning curve and a point two years ago where I committed to Babel (as part of a commitment to more literate programming).

What I find useful is that Emacs supports literate programming at a deeper level than markdown.

Good luck.

My github profile has several public repositories that show literate programming. One using Racket's literate programming tools (a pain in the ass) and several using org-mode + Babel (amazingly powerful)
I mean, when we edit the code, we can preview the effect in real time. Editing literary code has a live preview like most markdown editors.

The editor has a Live Preview panel to do the following work:

1. Get the current text

2. replace the `\r\n\;` with `\r\n` (note: line breaks and line comment characters of the current file can be obtained from the editor’s API. line comment characters of clojure(lisp) is `;`)

3. live Preview markdown string

4. Easily export directly to PDF or HTML.

Its advantages:

1. Don't break the syntax of any programming language, you can compile directly.

2. you only need a single line of regular replacement preprocessing, then you can use any Markdown parse or converter.

3. Support any code editor that supports Markdwon Live preview, allowing the source code of any programming language to become rich text in real time. In the code's comment area, You can use the markdown to draw flowcharts, tables, task lists, and display images on the live preview panel, enhance the readability of your code.

4. If you extend the Markdwon tag, you can implement the eval code, print result, display data visualization and other instruction tags, to achieve live programming, live test.

Ah, I see. Thanks.
comment area markup method can be applied to any programming language and any markup (including Org,rst, asciidoc, etc.), which is the greatest advantage. :-)