Skip to content

Commit 14000fb

Browse files
committed
rename some files, update README, mini refactor
1 parent b3e1ba1 commit 14000fb

File tree

5 files changed

+21
-23
lines changed

5 files changed

+21
-23
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ This is a dynamic mardkown transclusion server - it parses special inclusion syn
44

55
parts of the project:
66

7-
- builder.js, which accepts text, and a callback. It fetches md / hmd file from the web translcuding then hands the result to the callback
8-
- a server which you can point at an hmd file. It uses the builder to transclude and then render the markdown
7+
- `treeBuilder( markdownText, callback )` : reads text and recursively fetches markdown files that have been linked to in the `+[file name](url)` format. It stores the markdown (original and fetched) in a json tree, and passes this to the callback.
8+
- `treePartialRender( tree )` : renders the markdown partials of a built tree into html, and returns that tree.
9+
- `treeToHtml( tree )` : provides a couple of methods for rendering tree of html partials into a a single html string.
10+
- server : serves client static files, and provides and api which client-side code can request built and rendered trees of markdown.
911

1012
## notation
1113

@@ -16,3 +18,9 @@ e.g.
1618
+[example include](https://github.com/mixmix/example-course/blob/master/README.md)
1719
```
1820

21+
With normal markdown renderers this makes a link like this:
22+
23+
+[example include](https://github.com/mixmix/example-course/blob/master/README.md)
24+
25+
[See this same file rendered by hypermarkdown](https://hypermarkdown.herokuapp.com)
26+

regexps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
'mdUrl': /\.md(\#[\w-_]*)?/)
2+
'mdUrl': /\.md(\#[\w-_]*)?/,
33
'githublab': /git(hub|lab).com/,
44
'youtubeTransclusionAnchors': /\+\<a[^>]+(www.youtube.com[^<]+<\/a>)/g,
55
'youtubeId': /v\=([a-zA-Z\d]+)[&'"]+/,

server.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ var fs = require('fs')
88
var request = require('request')
99
var stringify = require('json-stringify-safe')
1010

11-
var build = require('./builder')
12-
var renderTree = require('./renderTree')
11+
var treeBuild = require('./treeBuild')
12+
var treePartialRender = require('./treePartialRender')
1313
var fetchAuthors = require('./fetchAuthors')
1414
var regexps = require('./regexps')
1515

@@ -34,7 +34,7 @@ function buildHypermarkdownTree(req, res, match) {
3434
var source = requestDetails.query.source
3535

3636
if (source && source.match( regexps.mdUrl ) ) {
37-
build(source, function(err, tree) {
37+
treeBuild(source, function(err, tree) {
3838
if (err) {
3939
res.writeHead(400, {'content-type': 'text/plain'})
4040
res.write("You've hit a bad url somewhere in there, we got the error:<br />"+ err)
@@ -44,8 +44,8 @@ function buildHypermarkdownTree(req, res, match) {
4444

4545
res.writeHead(200, {'content-type': 'application/json'})
4646

47-
var renderedTree = renderTree(tree)
48-
res.write( stringify(renderedTree, null, 2) )
47+
tree = treePartialRender(tree)
48+
res.write( stringify(tree, null, 2) )
4949
res.end()
5050
})
5151
}

builder.js renamed to treeBuild.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,9 @@ module.exports = function( url, callback ) {
1111
depth: 0,
1212
})
1313

14-
dig( parentTree, callback )
14+
expandTree( parentTree, callback )
1515
}
1616

17-
if (!module.parent) {
18-
var url = 'http://github.com/mixmix/example-course/blob/master/mix-recipe.md'
19-
20-
module.exports(url, function (err, results) {
21-
if (err) { throw err }
22-
var renderedTree = renderTreeContent(results)
23-
console.log(renderedTree)
24-
console.log(treeToHtml(renderedTree))
25-
})
26-
}
2717

2818
function Tree( attrs ) {
2919
return {
@@ -45,7 +35,7 @@ function treeWithParent( treeNode ) {
4535
}
4636
}
4737

48-
function dig( treeNode, callback ) {
38+
function expandTree( treeNode, callback ) {
4939
if (isInfiniteLoop(treeNode)) return callback(null, treeNode)
5040

5141
var getUrl = makeRaw(treeNode.url)
@@ -64,7 +54,7 @@ function dig( treeNode, callback ) {
6454

6555
async.each(
6656
treeNode.children,
67-
dig,
57+
expandTree,
6858
function (err) {
6959
callback(err, treeNode)
7060
}

renderTree.js renamed to treePartialRender.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
var Markdown = require('markdown-it')
22
var md = new Markdown()
33

4-
module.exports = function renderTreeContent( tree ) {
4+
module.exports = function treePartialRender( tree ) {
55
tree.content = md.render(tree.content)
66
tree.children.forEach(function (childTree) {
7-
renderTreeContent(childTree)
7+
treePartialRender(childTree)
88
})
99
return tree
1010
}

0 commit comments

Comments
 (0)