Skip to content

Instantly share code, notes, and snippets.

@tonyfast
Last active August 29, 2015 14:22
Show Gist options
  • Save tonyfast/c8fa98cd19a0edf55181 to your computer and use it in GitHub Desktop.
Save tonyfast/c8fa98cd19a0edf55181 to your computer and use it in GitHub Desktop.
Literate Presentation Streams with Markdown
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Literate Presentation Streams

{{title}} combine semantic text and code as structured text to communicate information. Presentation streams provide a minimal abstraction that can display information on many popular services like Github, nbviewer, speakerdeck, Disqus, Jekyll, bl.ocks, blogs, RSS...

The static presentation of information should promote maturity to an interaction, app, download. Static information that is compliant with HTML and Javascript canp be accessed most broadly.

Markdown is the ideal candidate to represent this type of information

# Jekyll blog information
layout: post
title: Literate presentation streams

What is a (markdown)stream?

A stream is a Github Flavored Markdown document. Code fences separate streams with ```. Four-tab indents are parts of semantic text. A markdown stream always starts with semantic text. A markdown stream always alternates between semantic text and code. GFM adds syntax highlighting by default, but it also indicates the language a code block is written in.

  • Standard markdown only contains code and not code.
  • RMarkdown code-fence parameters do not have meaning outside of R. RMarkdown does very much influence the ability to create many presentation formats, but there needs to be a heavier focus on the web.
  • Matlab markup sucks, most people don't even know it exists.
  • GFM has a large user base and has proven to be language agnostic.
print('This is python code and output')
This is python code and output

The Meaning of the Presentation Layer

There are many methods to present information, but each method can infer the information in the stream differently.

For example, in the two code cells above:

  • The python indicates syntax highlighting and Python code
  • There is a blank markdown cell in between
  • One can imagine creating a parser that uses that pattern to control a JSON-ified notebook with input and output code.
  • Even without IPython notebook the document renders as Markdown in gist.
some code
<!-- some Bokeh output -->

Bokeh can embed beautiful HTML5 visualizations

Haha, how is this going to work? I think it can render in bl.ocks or python notebooks.

extensions:
  blocks: 
  gist:
  nbviewer:
  notebook: # download nbviwer link
  jekyll:

HTML Presentation

There doesn't always need to be markdown It can be HTML

# references at the bottom
references:
  jekyll: www.jekyllrb.com
  rmarkdown: http://rmarkdown.rstudio.com/

Now what?

All the major data has been displayed. The most accessible presentation of data is the underlying motive. After the data is presented we make it dance.

console.log('coffeescript')
### Update the list of extensions in this readme ###
d3.select 'ul#ext-list'
  .selectAll 'li'
  .data d3.entries document.__data__.extensions
  .call (s)->
    s.enter().append 'li'
  .each (d,i)->
    d3.select @
      .append 'a'
      .text d.key
<!doctype html>
<!--
index.html is a naming convention adopted by blocks single gist paages
the languages shown in this example can all be parsed with cell
magics in the ipython notebooks
yaml, coffeescript, javascript, json, html, python
-->
<head>
<script src="http://cdn.jsdelivr.net/g/marked,d3js,handlebarsjs">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-yaml/3.3.1/js-yaml.min.js">
</script>
<script src="http://coffeescript.org/extras/coffee-script.js">
</script>
</head>
<body>
<script type="text/coffeescript">
d3.text 'readme.md', (readme)->
markdown = d3.select 'body'
.append 'div'
.attr 'classed','markdown'
.html marked readme
### Store yaml and json data on document object ###
document.__data__ = {}
gfm = (lang)->
['','lang-','highlight-'].map (prefix)-> ".#{prefix}#{lang}"
.join ','
.slice 0,-1
markdown.selectAll gfm 'json'
.each ()->
d3.entries JSON.parse @innerText
.forEach (d)->
document.__data__[d.key] = d.value
markdown.selectAll gfm 'yaml'
.each ()->
d3.entries jsyaml.load @innerText
.forEach (d)->
document.__data__[d.key] = d.value
### run any parts of the stream in that are javascript and coffeescript ###
markdown.selectAll gfm 'javascript'
.each ()->
CoffeeScript.run @innerText
### Run coffeescript cells ###
markdown.selectAll gfm 'coffeescript'
.each ()->
CoffeeScript.run @innerText
###
Template with Handlebars
Handlebars is not compatiable with Jekyll's liquid syntax so this example stays simple
Template languages insert data into the semantic text.
###
markdown.html ()->
template = Handlebars.compile @innerHTML
template document.__data__
</script>
</body>
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment