github.com/titpetric/pendulum@v0.1.180207-1512.0.20180514135826-1f399445df57/front/src/markdown/index_test.js (about) 1 var fs = require("fs"); 2 var assert = require("assert"); 3 4 //import markdown from 'index.js' 5 var markdown = require("./index.js"); 6 7 describe('Markdown', function () { 8 describe('Replacements', function () { 9 10 var folder = '/test' 11 12 it('should replace metadata', function () { 13 var content = `title: 'The thing about dates' 14 date: 2017-08-16 18:00:00 15 tags: [golang, tips, tricks] 16 --- 17 18 Adorable`; 19 20 var contentExpected = `| Name | Value | 21 |------|-------| 22 | title | 'The thing about dates' | 23 | date | 2017-08-16 18 | 24 | tags | [golang, tips, tricks] | 25 --- 26 27 Adorable` 28 29 contentNew = markdown.Transform(content, folder) 30 31 assert.equal(contentNew, contentExpected) 32 }) 33 34 it('should replace metadata image', function () { 35 var content = `title: 'The thing about dates' 36 image: ../post/the-thing-about-dates/heading.jpg 37 --- 38 39 Adorable`; 40 41 var contentExpected = `| Name | Value | 42 |------|-------| 43 | title | 'The thing about dates' | 44 | image |  | 45 --- 46 47 Adorable` 48 49 contentNew = markdown.Transform(content, folder) 50 51 assert.equal(contentNew, contentExpected) 52 }) 53 54 it('should replace single quoted metadata image', function () { 55 var content = `title: 'The thing about dates' 56 image: '../post/the-thing-about-dates/heading.jpg' 57 --- 58 59 Adorable`; 60 61 var contentExpected = `| Name | Value | 62 |------|-------| 63 | title | 'The thing about dates' | 64 | image |  | 65 --- 66 67 Adorable` 68 69 contentNew = markdown.Transform(content, folder) 70 71 assert.equal(contentNew, contentExpected) 72 }) 73 74 it('should replace double quoted metadata image', function () { 75 var content = `title: 'The thing about dates' 76 image: "../post/the-thing-about-dates/heading.jpg" 77 --- 78 79 Adorable`; 80 81 var contentExpected = `| Name | Value | 82 |------|-------| 83 | title | 'The thing about dates' | 84 | image |  | 85 --- 86 87 Adorable` 88 89 contentNew = markdown.Transform(content, folder) 90 91 assert.equal(contentNew, contentExpected) 92 }) 93 94 it('should keep http/s images', function () { 95 var content = '' 96 var expected = '' 97 assert.equal(markdown.Transform(content, folder), expected) 98 }) 99 100 it('should replace image', function () { 101 var content = '{% asset_img heading.jpg %} {% asset_img heading.jpg %}' 102 var expected = ' ' 103 assert.equal(markdown.Transform(content, folder), expected) 104 }) 105 106 it('should replace image with caption', function () { 107 var content = '{% asset_img heading.jpg "caption one" %} {% asset_img heading.jpg \'caption two\' %}' 108 var expected = ' ' 109 assert.equal(markdown.Transform(content, folder), expected) 110 }) 111 112 it('should replace pagebreak from hugo', function () { 113 var content = '<!--more--> <!--more-->' 114 var expected = '<hr class="pagebreak"/> <!--more-->' 115 assert.equal(markdown.Transform(content, folder), expected) 116 }) 117 118 it('should replace pagebreak from leanpub', function () { 119 var content = '{pagebreak} {pagebreak}' 120 var expected = '<hr class="pagebreak"/> {pagebreak}' 121 assert.equal(markdown.Transform(content, folder), expected) 122 }) 123 124 it('should replace cite from leanpub', function () { 125 var content = 'A> this is a bordered citation using `A>` syntax' 126 var expected = '> this is a bordered citation using `A>` syntax' 127 assert.equal(markdown.Transform(content, folder), expected) 128 }) 129 }) 130 }); 131