[idea] Markdown Literary Programming that don't break the syntax of any programming language


#1

Markdown Literary programming for compatible codes. Just add a custom line comment character before each line of Markdown.

In the comments of code, you can draw flowcharts, tasklist, display data visualizations image, etc.

When previewing or converting a format, you only need to simply preprocess: replace the \r\n\; with \r\n

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]))
;;The comment of the code requires at least two line comment characters
(reduce f [0 0 0 ##-Inf ##Inf] [5 6 8 -3 -9 11 156 6 7])
;```
;return`[4 5 187 156 -9]`

Screenshot

mv3


#2

Interesting. I was thinking about something similar. I thought we can extract doc-strings and function source from any namespace and put them together in a string in MD format. Export in to a markdown file to read at leisure. :slight_smile:


#3

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.)

  3. live Preview markdown string


#4

Interesting!

By the way, this is similar to Gorilla Repl’s format.


#5

Its advantages:

  1. Do not 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.

  5. Easily export directly to PDF or HTML.


#6

Have you looked into Literate CoffeeScript https://coffeescript.org/#literate

also the doc it generated https://coffeescript.org/annotated-source/scope.html


#7

I have not looked into Literate CoffeeScript.

The most important thing is that my comment area markup method can be applied to any programming language and any markup (including Org,rst, asciidoc, etc.), which is the greatest advantage.

if you break the programming language syntax, like org, this is the biggest drawback.


#8

Take a look at marginalia https://github.com/gdeer81/marginalia


#9

Your project is good, but the main purpose of the Code comment area markup method is to live Preview directly in the Code Editor Preview panel without exporting or any preprocessing.

I think:

  1. Literary Programming, Programming was the first, Literary was the second.

  2. The entire file is compliant with the programming language syntax and can be compiled directly.

  3. When writing (reading or refactoring) code files, I can modify and live preview directly in the editor without exporting or any preprocessing.

  4. Do not interfere with people who do not understand the markup language to read the code.

  5. Reliable. Maximum code accuracy is guaranteed, and markup language errors do not affect the code.


#10

Interesting!

It is worth looking into the current discussion at Clojurians Zulip, with some nice (similar) ideas by @didibus:

link


#11

There’s already something similar for Clojure: https://github.com/eccentric-j/book-report


#12

You could probably set this up with inotify and marginalia - so that each time you save your file it would regenerate the HTML and then it’d autorefresh in your browser window?

I’ve found running marginalia slow, so you’d need to find a way to speed things up by maybe having it run as some daemon

I do really like it’s side-by-side layout though and I use it in shorter programs where orgmode is overkill. And I do feel the layout is better than the traditional literate/org-mode vertical layout.

That all being said - I’ve never used live-preview while writing literate programs. I find that with the right highlighting it’s basically just as nice to stick to the raw text-form. Some emacs themes seem to extend org-mode’s highlighting so that it’s all visually easier to parse

So I feel the most pragmatic solution would just be a syntax highlighting layer on top of the existing Clojure one that would highlight the comment areas appropriately (which would be still written in a markdown/marginalia style). Something so it’s not all just light grey, but similar to the way text is highlighted in org, and then visually separate the code section with like a separate background or something to that effect. I think that’d get you 80% to where you want.

But the way things are right now, it’s a bit of an eyesore writing big grey code comment blocks :slight_smile:


#13

code comment area markup method can be in the editor preview panel live Preview, it’s fast.

Markdown is simple, so if it doesn’t have syntax highlighting, it doesn’t have much effect on writing and reading.

And having a gray comment area doesn’t affect reading code, especially for people who don’t understand the markup language.

Strict distinction between markdown and code, and markdown Gray, can reduce the amount of information in the source code file, conducive to reading code.

@geokon-gn Your method is document first, used to generate the document.

code comment area markup method is code first. used as a rich text code comments and Live Programming.

two methods apply different scenarios


#14

Marp uses the comment area to extend the Markdown directive to achieve “Markdown presentation Writer”, which is a good reference mechanism.

https://github.com/yhatt/marp/

https://yhatt.github.io/marp/

Marp markdown Comment Area extended directive:

  • slide directive

Clojure Comment Area extended directive:

  • markdown
  • manual eval code, live eval code, print result, display data visualization and other directives

#15

I love it! I adore literate programming, and ideas on this space are more of what we need. I really dig Marginalia, too. In my research, my favourite tool for readable documentation.

I had a go at my own LP tool a while back http://blaze.oat.sh/
Similar to Linpeng’s method, this just requires some frontmatter, for Blaze, its a shebang.

There are two schools of thought here: document-first (blaze), or code-first (Linpeng’s).

A small video I made talking about blaze, literate programming, and testing: https://youtu.be/eTQmlSL4L6c

What I’d love to see is first-class literate support in Clojure, like the aforementioned coffeescript, and like haskell.
Perhaps a lein preprocessor plugin?

Humans first, computers second!


#16

This is very similar to the source code format we use under the covers for http://maria.cloud.


#17

Because the article is long and inconvenient for typesetting, the complete presentation, notepad++ solution and patch see the links below:

Markdown Literary programming that don’t break the syntax of any programming language


#18

There is a markdown extension tag project that can execute tagged r (python, Julia, Rust) code.

Live code in Pandoc Markdown

https://github.com/gpoore/codebraid


#19

Just a quick PoC based on Marginalia parser.


#20

PythonScipt Solutions for Notepad++ Markdown Literary Programming

This PythonScript code is also a Markdown Literary Programming example.