## 2017-08-14, HTML to Markdown


### Experimenting with HTML to Markdown

Idea: Use it to allow similar direct manipulation as we allow for HTML:


- http://domchristie.github.io/to-markdown/

```JS
import ToMarkdown from 'https://domchristie.github.io/to-markdown/bower_components/to-markdown/dist/to-markdown.js'

ToMarkdown(that.innerHTML)

ToMarkdown(that.innerHTML, {converters: [{
  filter: function(node) { return true},
  replacement: function(content, node){
    return "\n\nHAHA" + node
  }
}]})
```


### http://upndown.netgusto.com/

I hit a wall with *to-markdown*, because it lost my comments.... 
When turning to "upndown", I found that they have a really nice bidirectionaly editing demo! Yeah!


### Working with bundled modules...

Upndown seems nice, but before I decide to use it, I wanted to find out how easy it is to adapt it. My use case is that html *comments* should not get lost.

Using that workflow for adapting *upndown* was hard, but we could make it more dynamic, by using the source code version `https://lively-kernel.org/lively4/upndown/src/upndown.js` directly. The problem was that it had a dependency to *htmlparser2*. There was no official support for a *htmlparser2*, that runs in the browser, but *upndown* used it any way in its *browserify* workflow.

So we first had to produce a bundle: 
```
node node_modules/.bin/browserify node_modules/htmlparser2/lib/index.js  -s htmlparser2.js > lib/htmlparser2.bundle.js 
```

And then make our module system aware of that module: 

```
SystemJS.config({
  map: {
    htmlparser2: "https://lively-kernel.org/lively4/upndown/lib/htmlparser2.bundle.js"     
  }
})
```

Idea, could we have automated this using the informatino in all the `package.js` files?





