├── .gitignore ├── Confluence-html-to-github-markdown.js ├── LICENSE ├── README.md └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # parcel-bundler cache (https://parceljs.org/) 61 | .cache 62 | 63 | # next.js build output 64 | .next 65 | 66 | # nuxt.js build output 67 | .nuxt 68 | 69 | # vuepress build output 70 | .vuepress/dist 71 | 72 | # Serverless directories 73 | .serverless -------------------------------------------------------------------------------- /Confluence-html-to-github-markdown.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | var fs = require('fs-extra') 3 | var exec = require('sync-exec') 4 | var path = require('path'); 5 | 6 | var divePath = process.cwd(); 7 | var attachmentsExportPath = "public/assets/images/" 8 | var markdownImageReference = "assets/images/" 9 | // print process.argv 10 | process.argv.forEach(function (val, index, array) { 11 | if (index === 2){ 12 | divePath = process.cwd() + "/" + val; 13 | }else if (index === 3){ 14 | attachmentsExportPath = val 15 | }else if(index === 4){ 16 | markdownImageReference = val 17 | } 18 | }); 19 | dive(divePath) 20 | 21 | function dive(dir) { 22 | var list = [] 23 | var stat = "" 24 | // Read the directory 25 | list = fs.readdirSync(dir); 26 | list.forEach(function (file) { 27 | // Full path of that file 28 | var p = path.join(dir , file) 29 | 30 | // Get the file's stats 31 | stat = fs.statSync(p) 32 | 33 | // If the file is a directory 34 | if (stat && stat.isDirectory()) { 35 | dive(p); 36 | } else { 37 | console.log(file) 38 | if (file.endsWith('.html')) { 39 | var titleRegex = /([^<]*)<\/title>/i 40 | var content = fs.readFileSync(p, 'utf8') 41 | var match = content.match(titleRegex) 42 | if (match != null && match.length > 1) { 43 | fs.ensureDir("Markdown") 44 | var sanitizedfilename = match[1].replace(/[^0-9a-zA-Z]/g,"_") 45 | var outputFile = path.join("Markdown", sanitizedfilename + ".md") 46 | var command = "pandoc -f html -t markdown -o " + outputFile + " " + p 47 | var out = exec(command, {cwd: process.cwd()}) 48 | console.log(out) 49 | //images 50 | console.log("Reading : " + outputFile) 51 | var content = fs.readFileSync(outputFile, 'utf8') 52 | var matches = uniq(content.match(/(<img src=")([a-z||_|0-9|.|]+)\/([a-z||_|0-9|.|]+)\/([a-z||_|0-9|.|]+)/ig)) 53 | matches.forEach(function (img) { 54 | img = img.replace('<img src="', '') 55 | var attachments = img.replace("attachments/", ""); 56 | if (attachments == img) { 57 | return; 58 | } 59 | var fileName = attachmentsExportPath + attachments; 60 | // console.log("Creating Folder : " + fileName.substr(0, fileName.lastIndexOf('/'))) 61 | mkdirpSync(fileName.substr(0, fileName.lastIndexOf('/'))) 62 | // console.log("creating filename: " + fileName) 63 | // fs.createReadStream(img).pipe(fs.createWriteStream(fileName)); 64 | try { 65 | // var img_content = fs.readFileSync(dir + "/" + img); 66 | // fs.writeFileSync(fileName, img); 67 | fs.accessSync(dir + "/" + img, fs.F_OK); 68 | fs.createReadStream(dir + "/" + img).pipe(fs.createWriteStream(process.cwd() + "/" + fileName)); 69 | console.log("Wrote: " + dir + "/" + img + "\n To: " + process.cwd() + "/" + fileName) 70 | } catch (e) { 71 | console.log("Can't read: " + dir + "/" + img) 72 | } 73 | }) 74 | var lines = content.replace(/(<img src=")([a-z||_|0-9|.|]+)\/([a-z||_|0-9|.|]+)\/([a-z||_|0-9|.|]+)/ig, "$1"+ markdownImageReference +"$3/$4") 75 | 76 | fs.writeFileSync(outputFile, lines) 77 | } 78 | } 79 | 80 | 81 | } 82 | }) 83 | } 84 | 85 | function uniq(a) { 86 | return Array.from(new Set(a)); 87 | } 88 | 89 | function mkdirSync(path) { 90 | try { 91 | fs.mkdirSync(path); 92 | } catch (e) { 93 | if (e.code != 'EEXIST') throw e; 94 | } 95 | } 96 | 97 | function mkdirpSync(dirpath) { 98 | // console.log("Making : " + dirpath) 99 | var parts = dirpath.split(path.sep); 100 | for (var i = 1; i <= parts.length; i++) { 101 | mkdirSync(path.join.apply(null, parts.slice(0, i))); 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Eric White 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Not maintained 2 | May want to fork: https://github.com/meridius/confluence-to-markdown 3 | # Confluence-to-Github-Markdown 4 | Convert Confluence Html export to Github Markdown 5 | # Requirements 6 | **Must have pandoc command line tool** 7 | 8 | http://pandoc.org/installing.html 9 | 10 | Make sure it was installed properly by doing `pandoc --version` 11 | # Installation 12 | `npm install -g confluence-to-github-markdown` 13 | # Usage 14 | `confluence-to-github-markdown` 15 | 16 | `confluence-to-github-markdown <htmlFilesDirectory> <attachmentsExportPath> <markdownImageReference>` 17 | 18 | ### Defaults 19 | * `<htmlFilesDirectory>` : `Current Working Directory` 20 | * `<attachmentsExportPath>` : `"/public/assets/images/"` Where to export images 21 | * `<markdownImageReference>` : `"assets/images/"` Image reference in markdown files 22 | 23 | 24 | # Export to HTML 25 | Note that if the converter does not know how to handle a style, HTML to Markdown typically just leaves the HTML untouched (Markdown does allow for HTML tags). 26 | 27 | ### Step by Step Guide 28 | 29 | 1. Go to the space and choose Space tools > Content Tools on the sidebar. 30 | 2. Choose Export. This option will only be visible if you have the 'Export Space' permission. 31 | 3. Select HTML then choose Next. 32 | 4. Decide whether you need to customise the export: 33 | * Select Normal Export to produce an HTML file containing all the pages that you have permission to view. 34 | * Select Custom Export if you want to export a subset of pages, or to exclude comments from the export. 35 | 5. [Export Pages](https://confluence.atlassian.com/doc/export-content-to-word-pdf-html-and-xml-139475.html#ExportContenttoWord,PDF,HTMLandXML-ExportmultiplepagestoHTML,XML,orPDF) 36 | 6. Extract zip 37 | 7. Open shell in extracted zip 38 | 8. run `confluence-to-github-markdown` in shell 39 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "confluence-to-github-markdown", 3 | "version": "1.1.2", 4 | "description": "Convert Confluence Pages to github markdown", 5 | "bin": { 6 | "confluence-to-github-markdown": "./Confluence-html-to-github-markdown.js" 7 | }, 8 | "main": "Confluence-html-to-github-markdown.js", 9 | "repository": "git@github.com:EWhite613/Confluence-to-Github-Markdown.git", 10 | "dependencies": { 11 | "path": "^0.12.7", 12 | "sync-exec": "^0.6.2", 13 | "fs-extra":"^7.0.0" 14 | }, 15 | "devDependencies": {}, 16 | "keywords": [ 17 | "Confluence", 18 | "Markdown", 19 | "Confluence to Markdown", 20 | "Confluence to Github Markdown", 21 | "ember", 22 | "Github Markdown", 23 | "Images", 24 | "export images", 25 | "reference images" 26 | ], 27 | "scripts": { 28 | "test": "echo \"Error: no test specified\" && exit 1" 29 | }, 30 | "author": "Eric White", 31 | "license": "MIT" 32 | } 33 | --------------------------------------------------------------------------------