├── .gitignore ├── .nvmrc ├── LICENSE ├── Procfile ├── README.md ├── bin └── build ├── build └── client.js ├── fetchAuthors.js ├── findTransclusions.js ├── hypermarkdown_badge.png ├── hypermarkdown_badge_small.png ├── images ├── clippy.svg └── loading.gif ├── index.html ├── package.json ├── regexps.js ├── server.js ├── source └── client.js ├── styles.css ├── test ├── index.js ├── treeBuild_test.js └── youtubeAutoEmbed_test.js ├── tidyMarkdown.js ├── treeBuild.js ├── treePartialRender.js ├── treeToDependencies.js ├── treeToHtml.js └── youtubeAutoEmbed.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | npm-debug.log 3 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 4.2.1 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: npm run prod 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # hypermarkdown 2 | 3 | This is a dynamic mardkown transclusion server - it parses special inclusion syntax and includes remote markdown, then renderes the resulting markdown. 4 | 5 | parts of the project: 6 | 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. 11 | 12 | ## notation 13 | 14 | To include a MD file within your MD file, use the normal markdown-link syntax, prefixed with a '+' 15 | 16 | e.g. 17 | ``` 18 | +[example include](https://github.com/mixmix/example-course/blob/master/README.md) 19 | ``` 20 | 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 a rendered example here](https://hypermarkdown.herokuapp.com/?source=https://github.com/mixmix/cultural_modules/blob/master/recipes/small_group_process.md) 26 | 27 | -------------------------------------------------------------------------------- /bin/build: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | echo "creating fresh build" 3 | rm -rf build 4 | mkdir build 5 | 6 | browserify source/client.js -o build/client.js 7 | 8 | echo "DONE" 9 | -------------------------------------------------------------------------------- /fetchAuthors.js: -------------------------------------------------------------------------------- 1 | var request = require('request') 2 | var url = require('url') 3 | 4 | var userAgent = process.env.USER_AGENT || 'hypermarkdown' 5 | 6 | module.exports = fetchAuthorData 7 | 8 | function fetchAuthorData (ownerAndRepo, query, callback) { 9 | fetchCommits(ownerAndRepo, query, afterFetchCommits) 10 | 11 | function afterFetchCommits (err, result) { 12 | if (err) { return callback(err) } 13 | 14 | var users = mapAuthorData(result) 15 | callback(null, users) 16 | } 17 | } 18 | 19 | function fetchCommits (ownerAndRepo, query, callback) { 20 | request( buildGithubRequest('repos/'+ownerAndRepo+'/commits', query), function(err, response, body) { 21 | if (err) { callback(err) } 22 | 23 | fetchMoreCommits(response, query, callback) 24 | 25 | var responseArray = JSON.parse(body) 26 | 27 | callback(null, responseArray) 28 | }) 29 | } 30 | 31 | function buildGithubRequest (apiPath, params) { 32 | var request = { 33 | url: url.format({ 34 | protocol: 'https', 35 | host: 'api.github.com', 36 | pathname: apiPath, 37 | query: params, 38 | }), 39 | headers: { 40 | 'User-Agent': userAgent, 41 | }, 42 | } 43 | 44 | return request 45 | } 46 | 47 | function fetchMoreCommits(response, query, callback) { 48 | if (response.headers.link == null) return 49 | 50 | var paginationRegex = /&page\=(\d+)\>; rel\=.next/ 51 | var nextPageMatch = response.headers.link.match(paginationRegex) 52 | 53 | if (nextPageMatch != null) { 54 | var newQuery = query 55 | newQuery['page'] = nextPageMatch[1] 56 | 57 | fetchCommits(newQuery, callback) 58 | } 59 | } 60 | 61 | function mapAuthorData (array) { 62 | var users = {} 63 | array.forEach( function(el) { 64 | var author = 65 | //if (users[author]) { next } 66 | 67 | users[el.author.login] = { 68 | 'author': el.author.login, 69 | 'avatar_url': el.author.avatar_url, 70 | 'html_url': el.author.html_url, 71 | } 72 | }) 73 | return users; 74 | } 75 | 76 | 77 | -------------------------------------------------------------------------------- /findTransclusions.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | md: function findMdTransclusions(text) { 3 | // General +[]() transclusion link 4 | //var mdLinks = text.match(/\+ \[ [^\[\]]* \] \( [^\)]+ \) /g) 5 | //var mdLinks = text.match(/\+\[[^\[\]]*\]\([^\)]+\)/g) 6 | 7 | // Specific +[](.md) transclusion link 8 | //var mdLinks = text.match(/\+ \[ [^\[\]]* \] \( [^\)]+\.md\) /g) 9 | var mdLinks = text.match(/\+\[[^\[\]]*\]\([^\)]+\.md\)/g) 10 | if (mdLinks == null) return [] 11 | 12 | return mdLinks.map( seperateLabelAndLink ) 13 | }, 14 | 15 | image: function findImageTransclusions(text) { 16 | //var link_pattern_matches = text.match(/\! \[ [^\[\]]* \] \( ^\)]+ \) /g) 17 | var imageLinks = text.match(/\!\[[^\[\]]*\]\([^\)]+\)/g) 18 | if (imageLinks == null) return [] 19 | 20 | return imageLinks.map( seperateLabelAndLink ) 21 | }, 22 | } 23 | 24 | 25 | function seperateLabelAndLink(string) { 26 | return { 27 | label: string.replace(/^\+\[/, '').replace(/\].*$/, ''), 28 | url: string.replace(/^.*\(/, '').replace(/\).*$/, '') 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /hypermarkdown_badge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mixmix/hypermarkdown/c83482063832f80e5266cc69ae1895b8726987c4/hypermarkdown_badge.png -------------------------------------------------------------------------------- /hypermarkdown_badge_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mixmix/hypermarkdown/c83482063832f80e5266cc69ae1895b8726987c4/hypermarkdown_badge_small.png -------------------------------------------------------------------------------- /images/clippy.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /images/loading.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mixmix/hypermarkdown/c83482063832f80e5266cc69ae1895b8726987c4/images/loading.gif -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | source 11 |
12 |

hypermarkdown

13 |
14 |
15 | 16 |
17 |
18 |
19 | 20 |

Loading...

21 |
22 | 32 |
33 | 40 |
41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hypermarkdown", 3 | "version": "0.0.1", 4 | "description": "a markdown transcluder that accepts web addresses for .hmd / .md files", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "node ./test/index.js | tap-spec", 8 | "testify": "nodemon ./test/index.js | tap-spec", 9 | "build": "browserify source/client.js -o build/client.js", 10 | "watch": "watchify source/client.js -o build/client.js -v", 11 | "start": "npm run watch & nodemon server.js", 12 | "deploy": "git push heroku master", 13 | "prod": "NODE_ENV=production node server.js" 14 | }, 15 | "repository": { 16 | "type": "git", 17 | "url": "https://github.com/mixmix/hypermarkdown.git" 18 | }, 19 | "author": "mixmix", 20 | "license": "GPLv2", 21 | "bugs": { 22 | "url": "https://github.com/mixmix/hypermarkdown/issues" 23 | }, 24 | "homepage": "https://github.com/mixmix/hypermarkdown", 25 | "dependencies": { 26 | "archy": "^1.0.0", 27 | "async": "^0.9.0", 28 | "clipboard": "^1.4.0", 29 | "domquery": "^1.2.0", 30 | "json-stringify-safe": "^5.0.1", 31 | "markdown-it": "^5.0.0", 32 | "request": "^2.65.0", 33 | "routes": "^2.1.0", 34 | "xhr": "^2.1.0" 35 | }, 36 | "devDependencies": { 37 | "browserify": "^12.0.0", 38 | "nock": "^2.15.0", 39 | "nodemon": "^1.8.0", 40 | "tap-spec": "^4.1.0", 41 | "tape": "^4.2.2", 42 | "watchify": "^3.5.0" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /regexps.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 'mdUrl': /\.md(\#[\w-_]*)?/, 3 | 'githublab': /git(hub|lab).com/, 4 | 'youtubeTransclusionAnchors': /\+\]+(www.youtube.com[^<]+<\/a>)/g, 5 | 'youtubeId': /v\=([a-zA-Z\d_]+)[&'"]+/, 6 | 7 | } 8 | 9 | -------------------------------------------------------------------------------- /server.js: -------------------------------------------------------------------------------- 1 | var isProd = process.env.NODE_ENV === 'production' 2 | var canonicalHost = process.env.CANONICAL_HOST || "http://hyper.mixmix.io" 3 | 4 | var Router = require('routes') 5 | var router = Router() 6 | var http = require('http') 7 | var url = require('url') 8 | var fs = require('fs') 9 | var request = require('request') 10 | var stringify = require('json-stringify-safe') 11 | 12 | var treeBuild = require('./treeBuild') 13 | var treePartialRender = require('./treePartialRender') 14 | var fetchAuthors = require('./fetchAuthors') 15 | var regexps = require('./regexps') 16 | 17 | 18 | router.addRoute('/', rootRequestResponse) 19 | function rootRequestResponse(req, res, match) { 20 | var referer = req.headers.referer || '' 21 | //linked from an md file? 22 | if (referer.match( regexps.mdUrl )) { 23 | res.writeHead(302, {'Location': 'http://hyper.mixmix.io/?source=' + referer, }) 24 | res.end() 25 | } 26 | else { 27 | res.writeHead(200, {'content-type': 'text/html'}) 28 | fs.createReadStream('./index.html').pipe(res) 29 | } 30 | } 31 | 32 | router.addRoute('/api/render', buildHypermarkdownTree) 33 | function buildHypermarkdownTree(req, res, match) { 34 | var requestDetails = url.parse(req.url, true) 35 | var source = requestDetails.query.source 36 | 37 | if (source && source.match( regexps.mdUrl ) ) { 38 | treeBuild(source, function(err, tree) { 39 | if (err) { 40 | res.writeHead(400, {'content-type': 'text/plain'}) 41 | res.write("You've hit a bad url somewhere in there, we got the error:
"+ err) 42 | res.end() 43 | return 44 | } 45 | 46 | res.writeHead(200, {'content-type': 'application/json'}) 47 | 48 | tree = treePartialRender(tree) 49 | res.write( stringify(tree, null, 2) ) 50 | res.end() 51 | }) 52 | } 53 | else { 54 | res.writeHead(400, {'content-type': 'text/plain'}) 55 | res.write("You need to provide a link to a markdown file.
Check you're using the format /?source=address_to_file.md or /api/render/?source=address_to_file.md if you're using the API") 56 | res.end() 57 | } 58 | } 59 | 60 | //router.addRoute('/api/authors', authorsResponse) 61 | //function authorsResponse(req, res, match) { 62 | //var requestDetails = url.parse(req.url, true) 63 | //var source = requestDetails.query.source 64 | 65 | //if (source && source.match( regexps.mdUrl ) && source.match( regexps.githublab )) { 66 | //var ownerAndRepo = source.match(/.*github.com\/([\w-_]+\/[\w-_]+)/)[1] 67 | //// this path assumes a lot about the source provided 68 | //var path = source.match(/.*github.com\/[\w-_]+\/[\w-_]+\/(.*\.md)/)[1].replace('blob/master/', '') 69 | 70 | //fetchAuthors(ownerAndRepo, {path: path}, function(err, users) { 71 | //if (err) { 72 | //res.writeHead(400, {'content-type': 'text/plain'}) 73 | //res.write("You've hit a bad url somewhere in there, we got the error:
"+ err) 74 | //res.end() 75 | //return 76 | //} 77 | 78 | //console.log(users) 79 | //res.writeHead(200, {'content-type': 'application/json'}) 80 | 81 | //res.write( stringify(users, null, 2) ) 82 | //res.end() 83 | //}) 84 | //} 85 | //else { 86 | //res.writeHead(400, {'content-type': 'text/plain'}) 87 | //res.write("error or no easy way to determine authors") 88 | //res.end() 89 | //} 90 | //} 91 | 92 | 93 | function handler(req, res) { 94 | var requestDetails = url.parse(req.url, true) 95 | var match = router.match(requestDetails.pathname) 96 | 97 | if (match) { 98 | match.fn(req, res, match) 99 | } 100 | // static-resources: 101 | else if (req.url === '/app.js') { 102 | fs.createReadStream('./build/client.js').pipe(res) 103 | } 104 | else if (req.url === '/clipboard.min.js') { 105 | fs.createReadStream('./node_modules/clipboard/dist/clipboard.min.js').pipe(res) 106 | } 107 | else if (req.url === '/styles.css') { 108 | fs.createReadStream('./styles.css').pipe(res) 109 | } 110 | else if (req.url === '/images/loading.gif') { 111 | fs.createReadStream('./images/loading.gif').pipe(res) 112 | } 113 | else if (req.url === '/images/clippy.svg') { 114 | fs.createReadStream('./images/clippy.svg').pipe(res) 115 | } 116 | else if (requestDetails.path.match( regexps.mdUrl )) { 117 | // redirects shortened urls 118 | res.writeHead(302, {'Location': canonicalHost + '/?source=https://www.github.com' + requestDetails.path, }) 119 | res.end() 120 | } 121 | } 122 | 123 | 124 | 125 | function startServer() { 126 | var port = process.env.PORT || 5000 127 | http.createServer( handler ).listen(port) 128 | } 129 | 130 | function keepAwake() { 131 | setInterval( 132 | function() { 133 | console.log('POKE') 134 | http.get(canonicalHost); 135 | }, 136 | 300000 // every 5 minutes (300000) 137 | ) 138 | } 139 | 140 | startServer() 141 | keepAwake() 142 | 143 | -------------------------------------------------------------------------------- /source/client.js: -------------------------------------------------------------------------------- 1 | var url = require('url') 2 | var xhr = require('xhr') 3 | var dom = require('domquery') 4 | 5 | var treeToHtml = require('../treeToHtml') 6 | var treeToDependencies = require('../treeToDependencies') 7 | 8 | var requestDetails = url.parse(window.location.href, true) 9 | var source = requestDetails.query.source 10 | var mode = requestDetails.query.style 11 | 12 | if (source) { 13 | xhr({ 14 | uri: '/api/render?source=' + source, 15 | headers: { 16 | "Content-Type": "application/json" 17 | } 18 | }, renderResponse) 19 | } 20 | else { 21 | dom('#loading').addClass('hidden') 22 | dom('#how-to').removeClass('hidden') 23 | } 24 | 25 | function renderResponse (err, resp, body) { 26 | if (resp.statusCode == 400) { 27 | var insertContent = body 28 | } 29 | else { 30 | //console.log(body) 31 | var results = JSON.parse(body) 32 | 33 | if (mode == 'plain') { 34 | var insertContent = treeToHtml.plain(results) 35 | } 36 | else { 37 | var insertContent = treeToHtml.stitched(results) 38 | } 39 | } 40 | 41 | dom('.container.target').replace('#loading', "
{insert}
", {insert: insertContent} ) 42 | 43 | dom('.container.header').toggleClass('hidden') 44 | 45 | dom('.container.dependencies .target').add( "
{insert}
", {insert: treeToDependencies(results).replace(/\n/g, '
')} )
46 |   new Clipboard('.btn.clipboard')
47 |   dom('.container.dependencies').toggleClass('hidden')
48 | }
49 | 
50 | dom('.container.controls button.toggle-stitches').on('click', toggleStitches)
51 | dom('body').on('click', '.stitch-mark .collapser', toggleCollapse)
52 | 
53 | function toggleStitches(evt) {
54 |   dom('.container.controls button.toggle-stitches').toggleClass('active')
55 |   dom('.stitch-mark').toggleClass('visible')
56 | 
57 |   dom('.stitch-mark .collapser').toggleClass('hidden')
58 | } 
59 | 
60 | function toggleCollapse(evt) {
61 |   var sectionHandle = evt.target.parentNode.attributes['data-url'].value
62 | 
63 |   dom('.stitch-mark[data-url="'+sectionHandle+'"] .collapser').toggleClass('has-plus')
64 |   dom('.stitch-mark[data-url="'+sectionHandle+'"] .content').toggleClass('hidden')
65 | }
66 | 
67 | 
68 | 


--------------------------------------------------------------------------------
/styles.css:
--------------------------------------------------------------------------------
  1 | body {
  2 |   color: #37362F;
  3 |   background: #EEEFF0 url("http://subtlepatterns2015.subtlepatterns.netdna-cdn.com/patterns/contemporary_china.png") repeat fixed 0% 0%;
  4 | }
  5 | 
  6 | h1.header, .source-link, #loading, #how-to, .container.controls, .container.dependencies {
  7 |   font-family: "opensans-light","opensans",sans-serif;
  8 |   font-weight: 300;
  9 | }
 10 | 
 11 | h1 { 
 12 |   font-size: 50px;
 13 |   padding: 40px 0 10px;
 14 | }
 15 | 
 16 | .stitch-mark div.content h1:nth-child(1) { 
 17 |   padding-top: 0;
 18 |   margin-top: 10px;
 19 | }
 20 | 
 21 | .stitch-mark div.content h2:nth-child(1) { 
 22 |   padding-top: 0;
 23 |   margin-top: 10px;
 24 | }
 25 | 
 26 | a { 
 27 |   color: #363434
 28 | }
 29 | 
 30 | .source-link {
 31 |   position: fixed;
 32 |   top: 10px;
 33 |   right: 10px;
 34 | }
 35 | 
 36 | #loading {
 37 |   text-align: center;
 38 |   padding: 100px;
 39 | }
 40 | #loading p {
 41 |   padding-left: 16px;
 42 | }
 43 | 
 44 | #how-to {
 45 |   padding-top: 40px;
 46 | }
 47 | #how-to p {
 48 |   text-align: right; 
 49 | }
 50 | 
 51 | main {
 52 |   width: 1000px;
 53 |   margin-right: auto;
 54 |   margin-left: auto;
 55 |   text-align: left;
 56 | }
 57 | 
 58 | .container {
 59 |   background: #ffffff;
 60 |   padding: 0 20px;
 61 |   margin: 0;
 62 |   padding-top: 10px;
 63 | }
 64 | 
 65 | .container.controls { 
 66 |   position: relative;
 67 |   padding: 0px 0px 20px 820px;
 68 | }
 69 | 
 70 | .container.controls button { 
 71 |   position: absolute;
 72 | }
 73 | 
 74 | button.collapser {
 75 |   background-color: #B0F6EF;
 76 |   float: right;
 77 |   width: 16px;
 78 |   padding: 0px;
 79 |   margin-top: 4px;
 80 |   /*position: absolute;*/
 81 |   /*left: -8px;*/
 82 |   /*top:12px;*/
 83 |   z-index: 999;
 84 |   position: relative;
 85 | }
 86 | 
 87 | button.collapser::after { 
 88 |   content: '-';
 89 | }
 90 | button.collapser.has-plus::after { 
 91 |   content: '+';
 92 | }
 93 | 
 94 | .container.target {
 95 |   min-height: 1000px;
 96 |   margin-bottom: 30px;
 97 |   padding-bottom: 60px;
 98 | }
 99 | 
100 | .container.dependencies { 
101 |   padding-bottom: 20px;
102 |   margin-bottom: 40px;
103 | }
104 | 
105 | .container.dependencies .target {
106 |   padding: 15px 0 20px 20px;
107 | }
108 | 
109 | .container.dependencies .target pre {
110 |   font-size: 14px;
111 |   padding 0;
112 |   margin: 0;
113 | }
114 | 
115 | .container.dependencies .target pre:hover button {
116 |   opacity: .5;
117 | }
118 | 
119 | 
120 | .stitch-mark.visible {
121 |   /*box-shadow: 2px 3px 8px #D2D2D2;*/
122 |   /*margin: 0px 8px;*/
123 |   border: 1px dashed #D2D2D2;
124 |   box-shadow: inset 0px 0px 30px rgba(238, 239, 240, 0.48);
125 |   margin: 0px;
126 |   padding: 10px;
127 |   /*position: relative;*/
128 | }
129 | 
130 | .stitch-mark .content.collapsed { 
131 |   display: inline-block;
132 |   margin-left: 8px;
133 | }
134 | .stitch-mark .content.collapsed.hidden{ 
135 |   display: none;
136 | }
137 | 
138 | button { 
139 |   border: none;
140 |   border-radius: 2px;
141 |   margin-right: 10px;
142 | }
143 | 
144 | button.btn.clipboard {
145 |   background-color: #fff;
146 |   opacity: 0;
147 | }
148 | 
149 | 
150 | .container.dependencies .target pre button.btn.clipboard:hover {
151 |   cursor: pointer;
152 |   opacity: 1;
153 | }
154 | 
155 | button.active {
156 |   background: rgba(52, 233, 213, 0.39);
157 | }
158 | 
159 | button::-moz-focus-inner {
160 |   border: 0;
161 | }
162 | 
163 | .youtube-embed {
164 |   text-align: center;
165 | }
166 | 
167 | .hide, .hidden { 
168 |   display: none;
169 | }
170 | 
171 | 
172 | 
173 | 
174 | 
175 | /*markdown style from : https://github.com/jasonm23/markdown-css-themes/blob/gh-pages/markdown.css*/
176 | 
177 | html { font-size: 100%; overflow-y: scroll; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }
178 | 
179 | body{
180 | color:#444;
181 | font-family:Georgia, Palatino, 'Palatino Linotype', Times, 'Times New Roman', serif;
182 | font-size:12px;
183 | line-height:1.5em;
184 | /*padding:1em;*/
185 | /*margin:auto;*/
186 | /*max-width:42em;*/
187 | /*background:#fefefe;*/
188 | }
189 | 
190 | a{ color: #0645ad; text-decoration:none;}
191 | a:visited{ color: #0b0080; }
192 | a:hover{ color: #06e; }
193 | a:active{ color:#faa700; }
194 | a:focus{ outline: thin dotted; }
195 | a:hover, a:active{ outline: 0; }
196 | 
197 | ::-moz-selection{background:rgba(255,255,0,0.3);color:#000}
198 | ::selection{background:rgba(255,255,0,0.3);color:#000}
199 | 
200 | a::-moz-selection{background:rgba(255,255,0,0.3);color:#0645ad}
201 | a::selection{background:rgba(255,255,0,0.3);color:#0645ad}
202 | 
203 | p{
204 | margin:1em 0;
205 | }
206 | 
207 | img{
208 | max-width:100%;
209 | }
210 | 
211 | h1,h2,h3,h4,h5,h6{
212 | font-weight:normal;
213 | color:#111;
214 | line-height:1em;
215 | }
216 | h4,h5,h6{ font-weight: bold; }
217 | h1{ font-size:2.5em; }
218 | h2{ font-size:2em; }
219 | h3{ font-size:1.5em; }
220 | h4{ font-size:1.2em; }
221 | h5{ font-size:1em; }
222 | h6{ font-size:0.9em; }
223 | 
224 | blockquote{
225 | color:#666666;
226 | margin:0;
227 | padding-left: 3em;
228 | border-left: 0.5em #EEE solid;
229 | }
230 | hr { display: block; height: 2px; border: 0; border-top: 1px solid #aaa;border-bottom: 1px solid #eee; margin: 1em 0; padding: 0; }
231 | pre, code, kbd, samp { color: #000; font-family: monospace, monospace; _font-family: 'courier new', monospace; font-size: 0.98em; }
232 | pre { white-space: pre; white-space: pre-wrap; word-wrap: break-word; }
233 | 
234 | b, strong { font-weight: bold; }
235 | 
236 | dfn { font-style: italic; }
237 | 
238 | ins { background: #ff9; color: #000; text-decoration: none; }
239 | 
240 | mark { background: #ff0; color: #000; font-style: italic; font-weight: bold; }
241 | 
242 | sub, sup { font-size: 75%; line-height: 0; position: relative; vertical-align: baseline; }
243 | sup { top: -0.5em; }
244 | sub { bottom: -0.25em; }
245 | 
246 | ul, ol { margin: 1em 0; padding: 0 0 0 2em; }
247 | li p:last-child { margin:0 }
248 | dd { margin: 0 0 0 2em; }
249 | 
250 | img { border: 0; -ms-interpolation-mode: bicubic; vertical-align: middle; }
251 | 
252 | table { border-collapse: collapse; border-spacing: 0; }
253 | td { vertical-align: top; }
254 | 
255 | @media only screen and (min-width: 480px) {
256 | body{font-size:14px;}
257 | }
258 | 
259 | @media only screen and (min-width: 768px) {
260 | body{font-size:16px;}
261 | }
262 | 
263 | @media print {
264 |   * { background: transparent !important; color: black !important; filter:none !important; -ms-filter: none !important; }
265 |   body{font-size:12pt; max-width:100%;}
266 |   a, a:visited { text-decoration: underline; }
267 |   hr { height: 1px; border:0; border-bottom:1px solid black; }
268 |   a[href]:after { content: " (" attr(href) ")"; }
269 |   abbr[title]:after { content: " (" attr(title) ")"; }
270 |   .ir a:after, a[href^="javascript:"]:after, a[href^="#"]:after { content: ""; }
271 |   pre, blockquote { border: 1px solid #999; padding-right: 1em; page-break-inside: avoid; }
272 |   tr, img { page-break-inside: avoid; }
273 |   img { max-width: 100% !important; }
274 |   @page :left { margin: 15mm 20mm 15mm 10mm; }
275 |   @page :right { margin: 15mm 10mm 15mm 20mm; }
276 |   p, h2, h3 { orphans: 3; widows: 3; }
277 |   h2, h3 { page-break-after: avoid; }
278 | }
279 | /*github markdown style, source: https://github.com/sindresorhus/github-markdown-css/blob/gh-pages/github-markdown.css*/
280 | 
281 | /*@font-face {*/
282 |   /*font-family: octicons-anchor;*/
283 |   /*src: url(data:font/woff;charset=utf-8;base64,d09GRgABAAAAAAYcAA0AAAAACjQAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABGRlRNAAABMAAAABwAAAAca8vGTk9TLzIAAAFMAAAARAAAAFZG1VHVY21hcAAAAZAAAAA+AAABQgAP9AdjdnQgAAAB0AAAAAQAAAAEACICiGdhc3AAAAHUAAAACAAAAAj//wADZ2x5ZgAAAdwAAADRAAABEKyikaNoZWFkAAACsAAAAC0AAAA2AtXoA2hoZWEAAALgAAAAHAAAACQHngNFaG10eAAAAvwAAAAQAAAAEAwAACJsb2NhAAADDAAAAAoAAAAKALIAVG1heHAAAAMYAAAAHwAAACABEAB2bmFtZQAAAzgAAALBAAAFu3I9x/Nwb3N0AAAF/AAAAB0AAAAvaoFvbwAAAAEAAAAAzBdyYwAAAADP2IQvAAAAAM/bz7t4nGNgZGFgnMDAysDB1Ml0hoGBoR9CM75mMGLkYGBgYmBlZsAKAtJcUxgcPsR8iGF2+O/AEMPsznAYKMwIkgMA5REMOXicY2BgYGaAYBkGRgYQsAHyGMF8FgYFIM0ChED+h5j//yEk/3KoSgZGNgYYk4GRCUgwMaACRoZhDwCs7QgGAAAAIgKIAAAAAf//AAJ4nHWMMQrCQBBF/0zWrCCIKUQsTDCL2EXMohYGSSmorScInsRGL2DOYJe0Ntp7BK+gJ1BxF1stZvjz/v8DRghQzEc4kIgKwiAppcA9LtzKLSkdNhKFY3HF4lK69ExKslx7Xa+vPRVS43G98vG1DnkDMIBUgFN0MDXflU8tbaZOUkXUH0+U27RoRpOIyCKjbMCVejwypzJJG4jIwb43rfl6wbwanocrJm9XFYfskuVC5K/TPyczNU7b84CXcbxks1Un6H6tLH9vf2LRnn8Ax7A5WQAAAHicY2BkYGAA4teL1+yI57f5ysDNwgAC529f0kOmWRiYVgEpDgYmEA8AUzEKsQAAAHicY2BkYGB2+O/AEMPCAAJAkpEBFbAAADgKAe0EAAAiAAAAAAQAAAAEAAAAAAAAKgAqACoAiAAAeJxjYGRgYGBhsGFgYgABEMkFhAwM/xn0QAIAD6YBhwB4nI1Ty07cMBS9QwKlQapQW3VXySvEqDCZGbGaHULiIQ1FKgjWMxknMfLEke2A+IJu+wntrt/QbVf9gG75jK577Lg8K1qQPCfnnnt8fX1NRC/pmjrk/zprC+8D7tBy9DHgBXoWfQ44Av8t4Bj4Z8CLtBL9CniJluPXASf0Lm4CXqFX8Q84dOLnMB17N4c7tBo1AS/Qi+hTwBH4rwHHwN8DXqQ30XXAS7QaLwSc0Gn8NuAVWou/gFmnjLrEaEh9GmDdDGgL3B4JsrRPDU2hTOiMSuJUIdKQQayiAth69r6akSSFqIJuA19TrzCIaY8sIoxyrNIrL//pw7A2iMygkX5vDj+G+kuoLdX4GlGK/8Lnlz6/h9MpmoO9rafrz7ILXEHHaAx95s9lsI7AHNMBWEZHULnfAXwG9/ZqdzLI08iuwRloXE8kfhXYAvE23+23DU3t626rbs8/8adv+9DWknsHp3E17oCf+Z48rvEQNZ78paYM38qfk3v/u3l3u3GXN2Dmvmvpf1Srwk3pB/VSsp512bA/GG5i2WJ7wu430yQ5K3nFGiOqgtmSB5pJVSizwaacmUZzZhXLlZTq8qGGFY2YcSkqbth6aW1tRmlaCFs2016m5qn36SbJrqosG4uMV4aP2PHBmB3tjtmgN2izkGQyLWprekbIntJFing32a5rKWCN/SdSoga45EJykyQ7asZvHQ8PTm6cslIpwyeyjbVltNikc2HTR7YKh9LBl9DADC0U/jLcBZDKrMhUBfQBvXRzLtFtjU9eNHKin0x5InTqb8lNpfKv1s1xHzTXRqgKzek/mb7nB8RZTCDhGEX3kK/8Q75AmUM/eLkfA+0Hi908Kx4eNsMgudg5GLdRD7a84npi+YxNr5i5KIbW5izXas7cHXIMAau1OueZhfj+cOcP3P8MNIWLyYOBuxL6DRylJ4cAAAB4nGNgYoAALjDJyIAOWMCiTIxMLDmZedkABtIBygAAAA==) format('woff');*/
284 | /*}*/
285 | 
286 | /*.markdown-body {*/
287 |   /*-ms-text-size-adjust: 100%;*/
288 |   /*-webkit-text-size-adjust: 100%;*/
289 |   /*color: #333;*/
290 |   /*[>overflow: hidden;<]*/
291 |   /*font-family: "Helvetica Neue", Helvetica, "Segoe UI", Arial, freesans, sans-serif;*/
292 |   /*font-size: 16px;*/
293 |   /*line-height: 1.6;*/
294 |   /*word-wrap: break-word;*/
295 | /*}*/
296 | 
297 | /*.markdown-body a {*/
298 |   /*background: transparent;*/
299 | /*}*/
300 | 
301 | /*.markdown-body a:active,*/
302 | /*.markdown-body a:hover {*/
303 |   /*outline: 0;*/
304 | /*}*/
305 | 
306 | /*.markdown-body strong {*/
307 |   /*font-weight: bold;*/
308 | /*}*/
309 | 
310 | /*.markdown-body h1 {*/
311 |   /*font-size: 2em;*/
312 |   /*margin: 0.67em 0;*/
313 | /*}*/
314 | 
315 | /*.markdown-body img {*/
316 |   /*border: 0;*/
317 | /*}*/
318 | 
319 | /*.markdown-body hr {*/
320 |   /*box-sizing: content-box;*/
321 |   /*height: 0;*/
322 | /*}*/
323 | 
324 | /*.markdown-body pre {*/
325 |   /*overflow: auto;*/
326 | /*}*/
327 | 
328 | /*.markdown-body code,*/
329 | /*.markdown-body kbd,*/
330 | /*.markdown-body pre {*/
331 |   /*font-family: monospace, monospace;*/
332 |   /*font-size: 1em;*/
333 | /*}*/
334 | 
335 | /*.markdown-body input {*/
336 |   /*color: inherit;*/
337 |   /*font: inherit;*/
338 |   /*margin: 0;*/
339 | /*}*/
340 | 
341 | /*.markdown-body html input[disabled] {*/
342 |   /*cursor: default;*/
343 | /*}*/
344 | 
345 | /*.markdown-body input {*/
346 |   /*line-height: normal;*/
347 | /*}*/
348 | 
349 | /*.markdown-body input[type="checkbox"] {*/
350 |   /*box-sizing: border-box;*/
351 |   /*padding: 0;*/
352 | /*}*/
353 | 
354 | /*.markdown-body table {*/
355 |   /*border-collapse: collapse;*/
356 |   /*border-spacing: 0;*/
357 | /*}*/
358 | 
359 | /*.markdown-body td,*/
360 | /*.markdown-body th {*/
361 |   /*padding: 0;*/
362 | /*}*/
363 | 
364 | /*.markdown-body * {*/
365 |   /*box-sizing: border-box;*/
366 | /*}*/
367 | 
368 | /*.markdown-body input {*/
369 |   /*font: 13px/1.4 Helvetica, arial, nimbussansl, liberationsans, freesans, clean, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol";*/
370 | /*}*/
371 | 
372 | /*.markdown-body a {*/
373 |   /*color: #4183c4;*/
374 |   /*text-decoration: none;*/
375 | /*}*/
376 | 
377 | /*.markdown-body a:hover,*/
378 | /*.markdown-body a:active {*/
379 |   /*text-decoration: underline;*/
380 | /*}*/
381 | 
382 | /*.markdown-body hr {*/
383 |   /*height: 0;*/
384 |   /*margin: 15px 0;*/
385 |   /*overflow: hidden;*/
386 |   /*background: transparent;*/
387 |   /*border: 0;*/
388 |   /*border-bottom: 1px solid #ddd;*/
389 | /*}*/
390 | 
391 | /*.markdown-body hr:before {*/
392 |   /*display: table;*/
393 |   /*content: "";*/
394 | /*}*/
395 | 
396 | /*.markdown-body hr:after {*/
397 |   /*display: table;*/
398 |   /*clear: both;*/
399 |   /*content: "";*/
400 | /*}*/
401 | 
402 | /*.markdown-body h1,*/
403 | /*.markdown-body h2,*/
404 | /*.markdown-body h3,*/
405 | /*.markdown-body h4,*/
406 | /*.markdown-body h5,*/
407 | /*.markdown-body h6 {*/
408 |   /*margin-top: 15px;*/
409 |   /*margin-bottom: 15px;*/
410 |   /*line-height: 1.1;*/
411 | /*}*/
412 | 
413 | /*.markdown-body h1 {*/
414 |   /*font-size: 30px;*/
415 | /*}*/
416 | 
417 | /*.markdown-body h2 {*/
418 |   /*font-size: 21px;*/
419 | /*}*/
420 | 
421 | /*.markdown-body h3 {*/
422 |   /*font-size: 16px;*/
423 | /*}*/
424 | 
425 | /*.markdown-body h4 {*/
426 |   /*font-size: 14px;*/
427 | /*}*/
428 | 
429 | /*.markdown-body h5 {*/
430 |   /*font-size: 12px;*/
431 | /*}*/
432 | 
433 | /*.markdown-body h6 {*/
434 |   /*font-size: 11px;*/
435 | /*}*/
436 | 
437 | /*.markdown-body blockquote {*/
438 |   /*margin: 0;*/
439 | /*}*/
440 | 
441 | /*.markdown-body ul,*/
442 | /*.markdown-body ol {*/
443 |   /*padding: 0;*/
444 |   /*margin-top: 0;*/
445 |   /*margin-bottom: 0;*/
446 | /*}*/
447 | 
448 | /*.markdown-body ol ol,*/
449 | /*.markdown-body ul ol {*/
450 |   /*list-style-type: lower-roman;*/
451 | /*}*/
452 | 
453 | /*.markdown-body ul ul ol,*/
454 | /*.markdown-body ul ol ol,*/
455 | /*.markdown-body ol ul ol,*/
456 | /*.markdown-body ol ol ol {*/
457 |   /*list-style-type: lower-alpha;*/
458 | /*}*/
459 | 
460 | /*.markdown-body dd {*/
461 |   /*margin-left: 0;*/
462 | /*}*/
463 | 
464 | /*.markdown-body code {*/
465 |   /*font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace;*/
466 |   /*font-size: 12px;*/
467 | /*}*/
468 | 
469 | /*.markdown-body pre {*/
470 |   /*margin-top: 0;*/
471 |   /*margin-bottom: 0;*/
472 |   /*font: 12px Consolas, "Liberation Mono", Menlo, Courier, monospace;*/
473 | /*}*/
474 | 
475 | /*.markdown-body .octicon {*/
476 |   /*font: normal normal normal 16px/1 octicons-anchor;*/
477 |   /*display: inline-block;*/
478 |   /*text-decoration: none;*/
479 |   /*text-rendering: auto;*/
480 |   /*-webkit-font-smoothing: antialiased;*/
481 |   /*-moz-osx-font-smoothing: grayscale;*/
482 |   /*-webkit-user-select: none;*/
483 |   /*-moz-user-select: none;*/
484 |   /*-ms-user-select: none;*/
485 |   /*user-select: none;*/
486 | /*}*/
487 | 
488 | /*.markdown-body .octicon-link:before {*/
489 |   /*content: '\f05c';*/
490 | /*}*/
491 | 
492 | /*.markdown-body>*:first-child {*/
493 |   /*margin-top: 0 !important;*/
494 | /*}*/
495 | 
496 | /*.markdown-body>*:last-child {*/
497 |   /*margin-bottom: 0 !important;*/
498 | /*}*/
499 | 
500 | /*.markdown-body a:not([href]) {*/
501 |   /*color: inherit;*/
502 |   /*text-decoration: none;*/
503 | /*}*/
504 | 
505 | /*.markdown-body .anchor {*/
506 |   /*position: absolute;*/
507 |   /*top: 0;*/
508 |   /*left: 0;*/
509 |   /*display: block;*/
510 |   /*padding-right: 6px;*/
511 |   /*padding-left: 30px;*/
512 |   /*margin-left: -30px;*/
513 | /*}*/
514 | 
515 | /*.markdown-body .anchor:focus {*/
516 |   /*outline: none;*/
517 | /*}*/
518 | 
519 | /*.markdown-body h1,*/
520 | /*.markdown-body h2,*/
521 | /*.markdown-body h3,*/
522 | /*.markdown-body h4,*/
523 | /*.markdown-body h5,*/
524 | /*.markdown-body h6 {*/
525 |   /*position: relative;*/
526 |   /*margin-top: 1em;*/
527 |   /*margin-bottom: 16px;*/
528 |   /*font-weight: bold;*/
529 |   /*line-height: 1.4;*/
530 | /*}*/
531 | 
532 | /*.markdown-body h1 .octicon-link,*/
533 | /*.markdown-body h2 .octicon-link,*/
534 | /*.markdown-body h3 .octicon-link,*/
535 | /*.markdown-body h4 .octicon-link,*/
536 | /*.markdown-body h5 .octicon-link,*/
537 | /*.markdown-body h6 .octicon-link {*/
538 |   /*display: none;*/
539 |   /*color: #000;*/
540 |   /*vertical-align: middle;*/
541 | /*}*/
542 | 
543 | /*.markdown-body h1:hover .anchor,*/
544 | /*.markdown-body h2:hover .anchor,*/
545 | /*.markdown-body h3:hover .anchor,*/
546 | /*.markdown-body h4:hover .anchor,*/
547 | /*.markdown-body h5:hover .anchor,*/
548 | /*.markdown-body h6:hover .anchor {*/
549 |   /*padding-left: 8px;*/
550 |   /*margin-left: -30px;*/
551 |   /*text-decoration: none;*/
552 | /*}*/
553 | 
554 | /*.markdown-body h1:hover .anchor .octicon-link,*/
555 | /*.markdown-body h2:hover .anchor .octicon-link,*/
556 | /*.markdown-body h3:hover .anchor .octicon-link,*/
557 | /*.markdown-body h4:hover .anchor .octicon-link,*/
558 | /*.markdown-body h5:hover .anchor .octicon-link,*/
559 | /*.markdown-body h6:hover .anchor .octicon-link {*/
560 |   /*display: inline-block;*/
561 | /*}*/
562 | 
563 | /*.markdown-body h1 {*/
564 |   /*padding-bottom: 0.3em;*/
565 |   /*font-size: 2.25em;*/
566 |   /*line-height: 1.2;*/
567 |   /*border-bottom: 1px solid #eee;*/
568 | /*}*/
569 | 
570 | /*.markdown-body h1 .anchor {*/
571 |   /*line-height: 1;*/
572 | /*}*/
573 | 
574 | /*.markdown-body h2 {*/
575 |   /*padding-bottom: 0.3em;*/
576 |   /*font-size: 1.75em;*/
577 |   /*line-height: 1.225;*/
578 |   /*border-bottom: 1px solid #eee;*/
579 | /*}*/
580 | 
581 | /*.markdown-body h2 .anchor {*/
582 |   /*line-height: 1;*/
583 | /*}*/
584 | 
585 | /*.markdown-body h3 {*/
586 |   /*font-size: 1.5em;*/
587 |   /*line-height: 1.43;*/
588 | /*}*/
589 | 
590 | /*.markdown-body h3 .anchor {*/
591 |   /*line-height: 1.2;*/
592 | /*}*/
593 | 
594 | /*.markdown-body h4 {*/
595 |   /*font-size: 1.25em;*/
596 | /*}*/
597 | 
598 | /*.markdown-body h4 .anchor {*/
599 |   /*line-height: 1.2;*/
600 | /*}*/
601 | 
602 | /*.markdown-body h5 {*/
603 |   /*font-size: 1em;*/
604 | /*}*/
605 | 
606 | /*.markdown-body h5 .anchor {*/
607 |   /*line-height: 1.1;*/
608 | /*}*/
609 | 
610 | /*.markdown-body h6 {*/
611 |   /*font-size: 1em;*/
612 |   /*color: #777;*/
613 | /*}*/
614 | 
615 | /*.markdown-body h6 .anchor {*/
616 |   /*line-height: 1.1;*/
617 | /*}*/
618 | 
619 | /*.markdown-body p,*/
620 | /*.markdown-body blockquote,*/
621 | /*.markdown-body ul,*/
622 | /*.markdown-body ol,*/
623 | /*.markdown-body dl,*/
624 | /*.markdown-body table,*/
625 | /*.markdown-body pre {*/
626 |   /*margin-top: 0;*/
627 |   /*margin-bottom: 16px;*/
628 | /*}*/
629 | 
630 | /*.markdown-body hr {*/
631 |   /*height: 4px;*/
632 |   /*padding: 0;*/
633 |   /*margin: 16px 0;*/
634 |   /*background-color: #e7e7e7;*/
635 |   /*border: 0 none;*/
636 | /*}*/
637 | 
638 | /*.markdown-body ul,*/
639 | /*.markdown-body ol {*/
640 |   /*padding-left: 2em;*/
641 | /*}*/
642 | 
643 | /*.markdown-body ul ul,*/
644 | /*.markdown-body ul ol,*/
645 | /*.markdown-body ol ol,*/
646 | /*.markdown-body ol ul {*/
647 |   /*margin-top: 0;*/
648 |   /*margin-bottom: 0;*/
649 | /*}*/
650 | 
651 | /*.markdown-body li>p {*/
652 |   /*margin-top: 16px;*/
653 | /*}*/
654 | 
655 | /*.markdown-body dl {*/
656 |   /*padding: 0;*/
657 | /*}*/
658 | 
659 | /*.markdown-body dl dt {*/
660 |   /*padding: 0;*/
661 |   /*margin-top: 16px;*/
662 |   /*font-size: 1em;*/
663 |   /*font-style: italic;*/
664 |   /*font-weight: bold;*/
665 | /*}*/
666 | 
667 | /*.markdown-body dl dd {*/
668 |   /*padding: 0 16px;*/
669 |   /*margin-bottom: 16px;*/
670 | /*}*/
671 | 
672 | /*.markdown-body blockquote {*/
673 |   /*padding: 0 15px;*/
674 |   /*color: #777;*/
675 |   /*border-left: 4px solid #ddd;*/
676 | /*}*/
677 | 
678 | /*.markdown-body blockquote>:first-child {*/
679 |   /*margin-top: 0;*/
680 | /*}*/
681 | 
682 | /*.markdown-body blockquote>:last-child {*/
683 |   /*margin-bottom: 0;*/
684 | /*}*/
685 | 
686 | /*.markdown-body table {*/
687 |   /*display: block;*/
688 |   /*width: 100%;*/
689 |   /*overflow: auto;*/
690 |   /*word-break: normal;*/
691 |   /*word-break: keep-all;*/
692 | /*}*/
693 | 
694 | /*.markdown-body table th {*/
695 |   /*font-weight: bold;*/
696 | /*}*/
697 | 
698 | /*.markdown-body table th,*/
699 | /*.markdown-body table td {*/
700 |   /*padding: 6px 13px;*/
701 |   /*border: 1px solid #ddd;*/
702 | /*}*/
703 | 
704 | /*.markdown-body table tr {*/
705 |   /*background-color: #fff;*/
706 |   /*border-top: 1px solid #ccc;*/
707 | /*}*/
708 | 
709 | /*.markdown-body table tr:nth-child(2n) {*/
710 |   /*background-color: #f8f8f8;*/
711 | /*}*/
712 | 
713 | /*.markdown-body img {*/
714 |   /*max-width: 100%;*/
715 |   /*box-sizing: border-box;*/
716 | /*}*/
717 | 
718 | /*.markdown-body code {*/
719 |   /*padding: 0;*/
720 |   /*padding-top: 0.2em;*/
721 |   /*padding-bottom: 0.2em;*/
722 |   /*margin: 0;*/
723 |   /*font-size: 85%;*/
724 |   /*background-color: rgba(0,0,0,0.04);*/
725 |   /*border-radius: 3px;*/
726 | /*}*/
727 | 
728 | /*.markdown-body code:before,*/
729 | /*.markdown-body code:after {*/
730 |   /*letter-spacing: -0.2em;*/
731 |   /*content: "\00a0";*/
732 | /*}*/
733 | 
734 | /*.markdown-body pre>code {*/
735 |   /*padding: 0;*/
736 |   /*margin: 0;*/
737 |   /*font-size: 100%;*/
738 |   /*word-break: normal;*/
739 |   /*white-space: pre;*/
740 |   /*background: transparent;*/
741 |   /*border: 0;*/
742 | /*}*/
743 | 
744 | /*.markdown-body .highlight {*/
745 |   /*margin-bottom: 16px;*/
746 | /*}*/
747 | 
748 | /*.markdown-body .highlight pre,*/
749 | /*.markdown-body pre {*/
750 |   /*padding: 16px;*/
751 |   /*overflow: auto;*/
752 |   /*font-size: 85%;*/
753 |   /*line-height: 1.45;*/
754 |   /*background-color: #f7f7f7;*/
755 |   /*border-radius: 3px;*/
756 | /*}*/
757 | 
758 | /*.markdown-body .highlight pre {*/
759 |   /*margin-bottom: 0;*/
760 |   /*word-break: normal;*/
761 | /*}*/
762 | 
763 | /*.markdown-body pre {*/
764 |   /*word-wrap: normal;*/
765 | /*}*/
766 | 
767 | /*.markdown-body pre code {*/
768 |   /*display: inline;*/
769 |   /*max-width: initial;*/
770 |   /*padding: 0;*/
771 |   /*margin: 0;*/
772 |   /*overflow: initial;*/
773 |   /*line-height: inherit;*/
774 |   /*word-wrap: normal;*/
775 |   /*background-color: transparent;*/
776 |   /*border: 0;*/
777 | /*}*/
778 | 
779 | /*.markdown-body pre code:before,*/
780 | /*.markdown-body pre code:after {*/
781 |   /*content: normal;*/
782 | /*}*/
783 | 
784 | /*.markdown-body kbd {*/
785 |   /*display: inline-block;*/
786 |   /*padding: 3px 5px;*/
787 |   /*font-size: 11px;*/
788 |   /*line-height: 10px;*/
789 |   /*color: #555;*/
790 |   /*vertical-align: middle;*/
791 |   /*background-color: #fcfcfc;*/
792 |   /*border: solid 1px #ccc;*/
793 |   /*border-bottom-color: #bbb;*/
794 |   /*border-radius: 3px;*/
795 |   /*box-shadow: inset 0 -1px 0 #bbb;*/
796 | /*}*/
797 | 
798 | /*.markdown-body .pl-c {*/
799 |   /*color: #969896;*/
800 | /*}*/
801 | 
802 | /*.markdown-body .pl-c1,*/
803 | /*.markdown-body .pl-s .pl-v {*/
804 |   /*color: #0086b3;*/
805 | /*}*/
806 | 
807 | /*.markdown-body .pl-e,*/
808 | /*.markdown-body .pl-en {*/
809 |   /*color: #795da3;*/
810 | /*}*/
811 | 
812 | /*.markdown-body .pl-s .pl-s1,*/
813 | /*.markdown-body .pl-smi {*/
814 |   /*color: #333;*/
815 | /*}*/
816 | 
817 | /*.markdown-body .pl-ent {*/
818 |   /*color: #63a35c;*/
819 | /*}*/
820 | 
821 | /*.markdown-body .pl-k {*/
822 |   /*color: #a71d5d;*/
823 | /*}*/
824 | 
825 | /*.markdown-body .pl-pds,*/
826 | /*.markdown-body .pl-s,*/
827 | /*.markdown-body .pl-s .pl-pse .pl-s1,*/
828 | /*.markdown-body .pl-sr,*/
829 | /*.markdown-body .pl-sr .pl-cce,*/
830 | /*.markdown-body .pl-sr .pl-sra,*/
831 | /*.markdown-body .pl-sr .pl-sre {*/
832 |   /*color: #183691;*/
833 | /*}*/
834 | 
835 | /*.markdown-body .pl-v {*/
836 |   /*color: #ed6a43;*/
837 | /*}*/
838 | 
839 | /*.markdown-body .pl-id {*/
840 |   /*color: #b52a1d;*/
841 | /*}*/
842 | 
843 | /*.markdown-body .pl-ii {*/
844 |   /*background-color: #b52a1d;*/
845 |   /*color: #f8f8f8;*/
846 | /*}*/
847 | 
848 | /*.markdown-body .pl-sr .pl-cce {*/
849 |   /*color: #63a35c;*/
850 |   /*font-weight: bold;*/
851 | /*}*/
852 | 
853 | /*.markdown-body .pl-ml {*/
854 |   /*color: #693a17;*/
855 | /*}*/
856 | 
857 | /*.markdown-body .pl-mh,*/
858 | /*.markdown-body .pl-mh .pl-en,*/
859 | /*.markdown-body .pl-ms {*/
860 |   /*color: #1d3e81;*/
861 |   /*font-weight: bold;*/
862 | /*}*/
863 | 
864 | /*.markdown-body .pl-mq {*/
865 |   /*color: #008080;*/
866 | /*}*/
867 | 
868 | /*.markdown-body .pl-mi {*/
869 |   /*color: #333;*/
870 |   /*font-style: italic;*/
871 | /*}*/
872 | 
873 | /*.markdown-body .pl-mb {*/
874 |   /*color: #333;*/
875 |   /*font-weight: bold;*/
876 | /*}*/
877 | 
878 | /*.markdown-body .pl-md {*/
879 |   /*background-color: #ffecec;*/
880 |   /*color: #bd2c00;*/
881 | /*}*/
882 | 
883 | /*.markdown-body .pl-mi1 {*/
884 |   /*background-color: #eaffea;*/
885 |   /*color: #55a532;*/
886 | /*}*/
887 | 
888 | /*.markdown-body .pl-mdr {*/
889 |   /*color: #795da3;*/
890 |   /*font-weight: bold;*/
891 | /*}*/
892 | 
893 | /*.markdown-body .pl-mo {*/
894 |   /*color: #1d3e81;*/
895 | /*}*/
896 | 
897 | /*.markdown-body kbd {*/
898 |   /*display: inline-block;*/
899 |   /*padding: 3px 5px;*/
900 |   /*font: 11px Consolas, "Liberation Mono", Menlo, Courier, monospace;*/
901 |   /*line-height: 10px;*/
902 |   /*color: #555;*/
903 |   /*vertical-align: middle;*/
904 |   /*background-color: #fcfcfc;*/
905 |   /*border: solid 1px #ccc;*/
906 |   /*border-bottom-color: #bbb;*/
907 |   /*border-radius: 3px;*/
908 |   /*box-shadow: inset 0 -1px 0 #bbb;*/
909 | /*}*/
910 | 
911 | /*.markdown-body .task-list-item {*/
912 |   /*list-style-type: none;*/
913 | /*}*/
914 | 
915 | /*.markdown-body .task-list-item+.task-list-item {*/
916 |   /*margin-top: 3px;*/
917 | /*}*/
918 | 
919 | /*.markdown-body .task-list-item input {*/
920 |   /*margin: 0 0.35em 0.25em -1.6em;*/
921 |   /*vertical-align: middle;*/
922 | /*}*/
923 | 
924 | /*.markdown-body :checked+.radio-label {*/
925 |   /*z-index: 1;*/
926 |   /*position: relative;*/
927 |   /*border-color: #4183c4;*/
928 | /*}*/
929 | 
930 | 


--------------------------------------------------------------------------------
/test/index.js:
--------------------------------------------------------------------------------
1 | process.env.NODE_ENV = 'testing'
2 | 
3 | var youtubeAutoEmbed = require('./youtubeAutoEmbed_test')()
4 | var treeBuild_test   = require('./treeBuild_test')()
5 | 
6 | 


--------------------------------------------------------------------------------
/test/treeBuild_test.js:
--------------------------------------------------------------------------------
 1 | var test = require('tape')
 2 | var nock = require('nock')
 3 | var treeBuild = require('../treeBuild')
 4 | 
 5 | var mockDomain = 'http://wwww.mock.com'
 6 | var q = {
 7 |   none: {
 8 |     path: '/none.md',
 9 |     response: 'Test string, with [normal link](www.google.com), nice '
10 |   },
11 |   transclude: {
12 |     path: '/transclude.md',
13 |     response: 'a +[hypermarkdown](http://wwww.mock.com/_target.md) transclusion.'
14 |   },
15 |   relativeTransclude: {
16 |     path: '/relative_transclude.md',
17 |     response: 'a +[hypermarkdown](./_target.md) transclusion.'
18 |   },
19 |   refTransclude: {
20 |     path: '/reference_transclude.md',
21 |     response: "and a transclusion which uses +[some reference][urlReferenceName] break\n\n " +
22 |                "[urlReferenceName]: http://wwww.mock.com/_target.md"
23 |   },
24 |   transcludeTarget: {
25 |    path: '/_target.md',
26 |    response: 'My sweet **transcluded** text!',
27 |    times: 3,
28 |   }
29 | }
30 | 
31 | module.exports = function() {
32 |   test('treeBuild', function(t) {
33 | 
34 |     var networkMocker = nock(mockDomain)
35 | 
36 |     // build mock responses from the mock called q
37 |     Object.keys(q).forEach( function(queryName) {
38 |       var query = q[queryName]
39 |       var times = query.times || 1
40 | 
41 |       networkMocker.get(query.path)
42 |                    .times(times)
43 |                    .reply(200, query.response)
44 |     })
45 | 
46 |     treeBuild(mockDomain + q.none.path, function(err, res) {
47 |       if (err) throw err
48 |       t.deepEqual( res.children, [], '0 transclusion > it builds a tree one level deep')
49 |     })
50 | 
51 |     treeBuild(mockDomain + q.transclude.path, function(err, res) {
52 |       if (err) throw err
53 |       t.notDeepEqual( res.children,               [],                                   '1 transclusion (explicit) > it is only 2 levels deep')
54 |       t.deepEqual(    res.children[0]['content'], q.transcludeTarget.response,          '1 transclusion (explicit) > it loads branch text')
55 |       t.deepEqual(    res.children[0]['url'],     mockDomain + q.transcludeTarget.path, '1 transclusion (explicit) > it loads branch url')
56 |     })
57 | 
58 |     treeBuild(mockDomain + q.relativeTransclude.path, function(err, res) {
59 |       if (err) throw err
60 |       t.notDeepEqual( res.children,               [],                                   '1 transclusion (relative) > it is only 2 levels deep')
61 |       t.deepEqual(    res.children[0]['content'], q.transcludeTarget.response,          '1 transclusion (relative) > it loads branch text')
62 |       t.deepEqual(    res.children[0]['url'],     mockDomain + q.transcludeTarget.path, '1 transclusion (relative) > it loads branch url')
63 |     })
64 | 
65 |     treeBuild(mockDomain + q.refTransclude.path, function(err, res) {
66 |       if (err) throw err
67 |       t.notDeepEqual( res.children, [],                                             '1 transclusion (reference) > it is only 2 levels deep')
68 |       t.deepEqual(    res.children[0]['content'], q.transcludeTarget.response,      '1 transclusion (reference) > it loads branch text')
69 |       t.deepEqual(    res.children[0]['url'], mockDomain + q.transcludeTarget.path, '1 transclusion (reference) > it loads branch url')
70 |     })
71 | 
72 |     //scope.done()
73 |     t.end()
74 |   })
75 | }
76 | 
77 | 
78 | function returnChildrenCallback( err, response ) {
79 |   if (err)  console.log( err )
80 | 
81 |   console.log(response)
82 |   //console.log(response['response'])
83 |   console.log( response.children  )
84 |   return response.children
85 | }
86 | 


--------------------------------------------------------------------------------
/test/youtubeAutoEmbed_test.js:
--------------------------------------------------------------------------------
 1 | var test = require('tape')
 2 | var youtubeAutoEmbed = require('../youtubeAutoEmbed')
 3 | 
 4 | module.exports = function() {
 5 |   test('youtubeAutoEmbed', function(t) {
 6 |     t.equal(
 7 |       youtubeAutoEmbed('plain string'),
 8 |       'plain string',
 9 |       'returns plain strings unmodified'
10 |     )
11 |     t.equal(
12 |       youtubeAutoEmbed('link +test'),
13 |       'link +test',
14 |       'returns non-youtube links unmodified'
15 |     )
16 |     t.equal(
17 |       youtubeAutoEmbed('link +test'),
18 |       'link 
', 19 | 'replaces youtube links with embedded videos' 20 | ) 21 | 22 | t.end() 23 | }) 24 | } 25 | 26 | -------------------------------------------------------------------------------- /tidyMarkdown.js: -------------------------------------------------------------------------------- 1 | var path = require('path') 2 | var findTransclusions = require('./findTransclusions') 3 | 4 | module.exports = function tidyMarkdown( treeNode ) { 5 | [ 6 | stripHyperMarkdownBadge, 7 | replaceReferenceStyleTransclusions, 8 | absolutifyTransclusionLinks, 9 | absolutifyImageLinks 10 | ] 11 | .map( function(fn) { fn(treeNode) } ) 12 | } 13 | 14 | 15 | function stripHyperMarkdownBadge( treeNode ) { 16 | treeNode.content = treeNode.content. 17 | replace('[![](https://github.com/mixmix/hypermarkdown/raw/master/hypermarkdown_badge.png)](http://hyper.mixmix.io)', ''). 18 | replace('[![](https://github.com/mixmix/hypermarkdown/raw/master/hypermarkdown_badge.png)](https://hypermarkdown.herokuapp.com)', '') 19 | } 20 | 21 | function replaceReferenceStyleTransclusions( treeNode ) { 22 | string = treeNode.content 23 | var referenceTransclusions = string.match(/\+\[[^\[\]]*\]\[[^\]]+\]/g) 24 | if (referenceTransclusions == null ) return string 25 | 26 | referenceTransclusions.forEach( function(match) { 27 | var referenceHandle = match.replace(/(.*\[|\])+/g, '') 28 | var referenceUrlMatch = string.match( new RegExp( "\\[" + referenceHandle + "\\]:\\s*([^\\s]+)" )) 29 | 30 | if (referenceUrlMatch) { 31 | var referenceLabel = match.replace(/(\+\[|\].+)/g, '') 32 | var standardTransclusion = match.replace( /\[[^\[]+\s*$/, "("+ referenceUrlMatch[1] + ")" ) 33 | 34 | var regex = new RegExp("\\+\\[" + referenceLabel + "\\]\\[" + referenceHandle + "\\]", 'g') 35 | 36 | string = string.replace(new RegExp("\\+\\[" + referenceLabel + "\\]\\[" + referenceHandle + "\\]", 'g'), standardTransclusion) 37 | 38 | } 39 | }) 40 | treeNode.content = string 41 | } 42 | 43 | function absolutifyTransclusionLinks( treeNode ) { 44 | var links = findTransclusions.md( treeNode.content ).map( function(el) { return el.url } ) 45 | 46 | links.forEach(function(link) { 47 | if ( !link.match(/^(http|www)/) ) { 48 | var fixedUrl = buildAbsoluteUrl( treeNode, link ) 49 | 50 | var matcher = new RegExp( "\\+\\[([^\\]]*)]\\(" + link + "\\)", 'g' ) 51 | treeNode.content = treeNode.content.replace(matcher, "+[$1](" + fixedUrl + ")") 52 | } 53 | }) 54 | } 55 | 56 | function absolutifyImageLinks( treeNode ) { 57 | var links = findTransclusions.image( treeNode.content ).map( function(el) { return el.url } ) 58 | 59 | links.forEach(function(link) { 60 | if ( !link.match(/^(http|www)/) ) { 61 | var fixedUrl = buildAbsoluteUrl( treeNode, link ) 62 | if ( fixedUrl.match(/blob\/master/) ) { 63 | fixedUrl = fixedUrl + "?raw=true" 64 | } 65 | 66 | var matcher = new RegExp( "\\!\\[([^\\]]*)]\\(" + link + "\\)", 'g' ) 67 | treeNode.content = treeNode.content.replace(matcher, "![$1](" + fixedUrl + ")") 68 | } 69 | }) 70 | } 71 | 72 | function buildAbsoluteUrl( treeNode, url ) { 73 | var parentUrlDir = treeNode.url.replace(/\/[^\/]*$/,'') 74 | 75 | return path.join(parentUrlDir, url) 76 | .replace(/(^https?:\/)/,"$1/") 77 | } 78 | 79 | -------------------------------------------------------------------------------- /treeBuild.js: -------------------------------------------------------------------------------- 1 | var async = require('async') 2 | var request = require('request') 3 | var tidyMarkdown = require('./tidyMarkdown') 4 | var findTransclusions = require('./findTransclusions') 5 | var regexps = require('./regexps') 6 | 7 | module.exports = function( url, callback ) { 8 | var parentTree = Tree({ 9 | label: null, 10 | url: url, 11 | parent: null, 12 | depth: 0, 13 | }) 14 | 15 | expandTree( parentTree, callback ) 16 | } 17 | 18 | function Tree( attrs ) { 19 | return { 20 | label: attrs['label'], 21 | url: attrs['url'], 22 | parent: attrs['parent'], 23 | depth: attrs['depth'], 24 | content: null, 25 | children: null, 26 | } 27 | } 28 | 29 | function treeWithParent( treeNode ) { 30 | return function ( attrs ) { 31 | attrs.parent = treeNode 32 | attrs.depth = treeNode.depth + 1 33 | 34 | return Tree( attrs ) 35 | } 36 | } 37 | 38 | function expandTree( treeNode, callback ) { 39 | if (isInfiniteLoop(treeNode)) return callback(null, treeNode) 40 | 41 | var getUrl = prepareUrl(treeNode) 42 | 43 | request.get( getUrl, function(err, response, body) { 44 | if (err) { 45 | console.error("there was an error getting: " + treeNode.url) 46 | return callback(err) 47 | } 48 | 49 | treeNode.content = body 50 | tidyMarkdown( treeNode ) 51 | treeNode.children = findTransclusions.md(treeNode.content).map( treeWithParent(treeNode) ) 52 | 53 | async.each( 54 | treeNode.children, 55 | expandTree, 56 | function (err) { 57 | callback(err, treeNode) 58 | } 59 | ) 60 | }) 61 | } 62 | 63 | function isInfiniteLoop( tree, url ) { 64 | if (tree.parent == null) return false 65 | if (url == null) { 66 | return isInfiniteLoop( tree.parent, tree.url ) 67 | } 68 | 69 | if (tree.url === url) return true 70 | 71 | return isInfiniteLoop ( tree.parent, url ) 72 | } 73 | 74 | function prepareUrl( treeNode ) { 75 | url = makeRaw(treeNode.url) 76 | 77 | printGet( url, treeNode ) 78 | return url 79 | } 80 | 81 | function printGet( url, treeNode ) { 82 | if (process.env.NODE_ENV != 'testing') { 83 | console.log( Array(treeNode.depth*2).join(' ') + green('[Get] ') + url) 84 | } 85 | } 86 | 87 | function green(string) { return ("\033[32m"+ string +"\033[0m") } 88 | 89 | function makeRaw( url ) { 90 | if (url.match( regexps.githublab )) { 91 | url = url.replace(/\/blob\//, '/raw/') 92 | } 93 | return url 94 | } 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /treePartialRender.js: -------------------------------------------------------------------------------- 1 | var Markdown = require('markdown-it') 2 | var md = new Markdown() 3 | 4 | module.exports = function treePartialRender( tree ) { 5 | tree.content = md.render(tree.content) 6 | tree.children.forEach(function (childTree) { 7 | treePartialRender(childTree) 8 | }) 9 | return tree 10 | } 11 | 12 | -------------------------------------------------------------------------------- /treeToDependencies.js: -------------------------------------------------------------------------------- 1 | var archy = require('archy') 2 | 3 | module.exports = treeToDependencies 4 | 5 | function treeToDependencies( tree ) { 6 | return archy(treeToArchyTree(tree), '', {'unicode': false}) 7 | } 8 | 9 | function treeToArchyTree(tree) { 10 | var newTree = {} 11 | 12 | function recurssiveArchyFormat(tree, newTree) { 13 | var label = tree.parent == null ? tree.url.replace(/^.*\//,'') : tree.label 14 | 15 | newTree.label = ""+label+"" 16 | newTree.label += "" 19 | 20 | newTree.nodes = [] 21 | 22 | tree.children.forEach( function(childTree, index) { 23 | newTree.nodes[index] = {} 24 | newTree.nodes[index] = recurssiveArchyFormat(childTree, newTree.nodes[index]) 25 | }) 26 | 27 | return newTree 28 | } 29 | 30 | recurssiveArchyFormat(tree, newTree) 31 | return newTree 32 | } 33 | 34 | -------------------------------------------------------------------------------- /treeToHtml.js: -------------------------------------------------------------------------------- 1 | var youtubeAutoEmbed = require('./youtubeAutoEmbed') 2 | 3 | module.exports = { 4 | plain: treeToPlainHtml, 5 | stitched: treeToStitchedHtml, 6 | } 7 | 8 | function treeToPlainHtml ( tree ) { 9 | var html = html || '' 10 | if (tree.parent == null) html = tree.content 11 | 12 | function recurssiveStitch(tree) { 13 | tree.children.forEach( function(childTree) { 14 | html = plainSubstitute( childTree.url, childTree.content, html ) 15 | recurssiveStitch( childTree ) 16 | }) 17 | } 18 | 19 | recurssiveStitch(tree) 20 | html = youtubeAutoEmbed(html) 21 | return html 22 | } 23 | 24 | // TODO ask Mikey why this didn't work 25 | //function treeToStitchedHtml ( tree ) { 26 | //var html = html || '' 27 | //if (tree.parent == null) html = tree.content 28 | 29 | //tree.children.forEach( function(childTree) { 30 | //html = stitchSubstitute( childTree.url, childTree.content, html ) 31 | //treeToStitchedHtml( childTree ) 32 | //}) 33 | //return html 34 | //} 35 | 36 | function treeToStitchedHtml ( tree ) { 37 | var html = html || '' 38 | if (tree.parent == null) html = tree.content 39 | 40 | function recurssiveStitch(tree) { 41 | tree.children.forEach( function(childTree) { 42 | html = stitchSubstitute( childTree, html ) 43 | recurssiveStitch( childTree ) 44 | }) 45 | } 46 | 47 | recurssiveStitch(tree) 48 | html = youtubeAutoEmbed(html) 49 | return html 50 | } 51 | 52 | function plainSubstitute (url, importedText, wholeText) { 53 | var regex = new RegExp('\\+\', 'g') 54 | return wholeText.replace(regex, importedText) 55 | } 56 | 57 | function stitchSubstitute (treeNode, wholeText) { 58 | var regex = new RegExp('\\+\', 'g') 59 | var importedText = "
" + 60 | "" + 61 | "
" + treeNode.content + "
" + 62 | "" + 63 | "
" 64 | return wholeText.replace(regex, importedText) 65 | } 66 | 67 | -------------------------------------------------------------------------------- /youtubeAutoEmbed.js: -------------------------------------------------------------------------------- 1 | var regexps = require('./regexps') 2 | 3 | module.exports = function youtubeAutoEmbed(string) { 4 | var matches = string.match( regexps.youtubeTransclusionAnchors ) 5 | if (matches) { 6 | matches.forEach( function(match) { 7 | string = string.replace( match, convertAnchorToEmbed(match) ) 8 | }) 9 | } 10 | 11 | return string 12 | } 13 | 14 | 15 | function convertAnchorToEmbed( string ) { 16 | var youtubeID = string.match( regexps.youtubeId )[1] 17 | 18 | return '
' 19 | } 20 | 21 | --------------------------------------------------------------------------------