├── .gitignore ├── .npmrc ├── LICENSE ├── changelog.md ├── code-of-conduct.md ├── contributing.md ├── index.js ├── package.json ├── readme.md ├── test.js └── utils ├── cli.js ├── convert.js └── end.js /.gitignore: -------------------------------------------------------------------------------- 1 | # NPM # 2 | ########## 3 | # Ignore all directories called node_modules in current folder and any subfolders. 4 | node_modules/ 5 | /node_modules/ 6 | 7 | # Packages # 8 | ############ 9 | *.7z 10 | *.dmg 11 | *.gz 12 | *.bz2 13 | *.iso 14 | *.jar 15 | *.rar 16 | *.tar 17 | *.zip 18 | *.tgz 19 | *.map 20 | 21 | # Logs and databases # 22 | ###################### 23 | *.log 24 | *.sql 25 | *.env 26 | 27 | # OS generated files # 28 | ###################### 29 | **.DS_Store* 30 | ehthumbs.db 31 | Icon? 32 | Thumbs.db 33 | ._* 34 | 35 | # Vim generated files # 36 | ###################### 37 | *.un~ 38 | 39 | # SASS # 40 | ########## 41 | **/.sass-cache 42 | **/.sass-cache/* 43 | **/.map 44 | 45 | # Composer # 46 | ########## 47 | !assets/js/vendor/ 48 | wpcs/ 49 | /vendor/ 50 | 51 | # Bower # 52 | ########## 53 | assets/bower_components/* 54 | 55 | # Codekit # 56 | ########## 57 | /codekit-config.json 58 | *.codekit 59 | **.codekit-cache/* 60 | 61 | # Compiled Files and Build Dirs # 62 | ########## 63 | /README.html 64 | 65 | # PhpStrom Project Files # 66 | .idea/ 67 | library/vendors/composer 68 | assets/img/.DS_Store 69 | 70 | # Visual Studio Project Files # 71 | .vs/ 72 | 73 | # No lock files. 74 | package-lock.json 75 | yarn.lock 76 | settings.dat 77 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Saad Irfan 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 | -------------------------------------------------------------------------------- /changelog.md: -------------------------------------------------------------------------------- 1 | # Changes Across Different Versions of docx-to- 2 | 3 | ## 🚀 v1.3.0 4 | 5 | - Fixed path issue 6 | 7 | ## 🚀 v1.0.0 8 | 9 | - Converting all the docx files to markdown 10 | -------------------------------------------------------------------------------- /code-of-conduct.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at mrsaadirfan@gmail.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | 1. Open the issue first. 4 | 2. Fork the repository. 5 | 3. Create and switch to the new branch. New branch name convention must be like this yourUsername/newFeature, for instance, `msaaddev/pr-review` 6 | 4. Commit the changes in your forked repository. 7 | 5. Open a pull request & mention the issue number in the pull request for reference. 8 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /** 4 | * 5 | * Author Saad Irfan 6 | * GitHub msaaddev 7 | * Twitter 8 | */ 9 | 10 | const welcome = require('cli-welcome'); 11 | const pkgJSON = require('./package.json'); 12 | const cli = require('./utils/cli'); 13 | 14 | (module.exports = async () => { 15 | welcome({ 16 | title: `docx to markdown`, 17 | tagLine: `by ${pkgJSON.author.name}`, 18 | description: `${pkgJSON.description}`, 19 | bgColor: `#5D39FD`, 20 | color: `#FFF`, 21 | bold: true, 22 | clear: true, 23 | version: `${pkgJSON.version}`, 24 | }); 25 | 26 | await cli(); 27 | })(); 28 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "docx-to-markdown", 3 | "description": "docx to markdown with `npx docx-to-markdown`", 4 | "version": "1.3.1", 5 | "author": { 6 | "name": "Saad Irfan", 7 | "email": "mrsaadirfan@gmail.com", 8 | "url": "https://twitter.com/msaaddev" 9 | }, 10 | "main": "index.js", 11 | "bin": { 12 | "docx-to-markdown": "index.js" 13 | }, 14 | "repository": "msaaddev/docx-to-markdown.git", 15 | "keywords": [ 16 | "Saad Irfan", 17 | "docx to markdown", 18 | "docs to markdown", 19 | "markdown converter", 20 | "docx converter" 21 | ], 22 | "license": "MIT", 23 | "dependencies": { 24 | "chalk": "^4.1.0", 25 | "cli-welcome": "^2.2.2", 26 | "execa": "^4.0.3", 27 | "ora": "^5.1.0" 28 | }, 29 | "scripts": { 30 | "test": "node test.js" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 |
2 |

🦉 docx-to-markdown
3 | MIT license 4 | version 5 | downloads 6 |

7 |
8 | 9 | > A CLI that converts your docx files to markdown 10 | 11 | ## 🏗 SETUP 12 | 13 | Before running the CLI, first run the following command on the terminal to install [Pandoc](https://pandoc.org/index.html). 14 | 15 | ```sh 16 | brew install pandoc 17 | ``` 18 | 19 | If you are Windows user, you can install Pandoc from [here](https://github.com/jgm/pandoc/releases/tag/2.10.1). 20 | 21 | `NOTE` This is one time thingy. 22 | 23 | ## ⚙️ USAGE 24 | 25 | Navigate to the directory via terminal where all the docx files are present. Then run the following there. 26 | 27 | ```sh 28 | npx docx-to-markdown 29 | ``` 30 | ![Working](https://i.imgur.com/hxBLQMt.png) 31 | 32 | ## 👨🏻‍💻 AUTHOR 33 | 34 | Howdy, you! This is [Saad Irfan](http://msaad.dev/), an aspiring JavaScript developer, former Google Developer Student Club's Lead, Microsoft Learn Student Ambassador, and an undergrad student. You can read more about me [here](https://github.com/msaaddev/msaaddev). 35 | 36 |
37 | 38 | Saad Irfan | Twitter 39 | 40 | 41 | Saad's LinkdeIN 42 | 43 | 44 | Saad's Facebook 45 | 46 | 47 | Saad's instagram 48 | 49 |
50 |
51 | 52 | ## ⚡️ Other Projects 53 | 54 | I have curated a [detailed list](https://github.com/msaaddev/open-source) of all the open-source projects I have authored. Do take out a moment and take a look. 55 | 56 | ## 🔑 LICENSE 57 | 58 | - MIT 59 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | const cli = require('./index'); 2 | 3 | cli(); 4 | -------------------------------------------------------------------------------- /utils/cli.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | const convert = require('./convert'); 3 | const end = require('./end'); 4 | const chalk = require('chalk'); 5 | const cwd = process.cwd(); 6 | 7 | module.exports = async () => { 8 | const filenames = []; 9 | 10 | fs.readdir(cwd, async (err, files) => { 11 | files.forEach(file => { 12 | if (file[file.length - 1] === 'x' && file[file.length - 2] === 'c') { 13 | const res = file.split('.'); 14 | if (res[0] !== '') filenames.push(res[0]); 15 | } 16 | }); 17 | 18 | if (filenames.length === 0) { 19 | console.log(`${chalk.hex('#DF661E').inverse(' INFO ')} No docx file/s found`); 20 | end(); 21 | return; 22 | } else await convert(filenames); 23 | end(); 24 | }); 25 | }; 26 | -------------------------------------------------------------------------------- /utils/convert.js: -------------------------------------------------------------------------------- 1 | const execa = require('execa'); 2 | const ora = require('ora'); 3 | const chalk = require('chalk'); 4 | 5 | module.exports = async filenames => { 6 | let spinner = ora(); 7 | 8 | spinner.start(`Converting docx files to markdown`); 9 | try { 10 | await execa(`mkdir`, [`markdown`]); 11 | filenames.map(async file => { 12 | try { 13 | await execa(`pandoc`, [ 14 | `-f`, 15 | `docx`, 16 | `-t`, 17 | `markdown`, 18 | `${file}.docx`, 19 | `-o`, 20 | `markdown/${file}.md`, 21 | ]); 22 | } catch (error) {} 23 | }); 24 | spinner.succeed( 25 | `${chalk.hex(`#6cc644`).inverse(` DONE `)} ${filenames.length} file/s converted` 26 | ); 27 | } catch (error) { 28 | spinner.fail(`${chalk.hex(`#FF0000`).inverse(` ERROR `)} Couldn't convert the file/s.`); 29 | } 30 | }; 31 | -------------------------------------------------------------------------------- /utils/end.js: -------------------------------------------------------------------------------- 1 | const chalk = require('chalk'); 2 | 3 | module.exports = () => { 4 | console.log(''); 5 | console.log( 6 | chalk.hex('#FAD000').inverse(' STAR '), 7 | 'the CLI -> ', 8 | chalk.dim('https://github.com/msaaddev/docx-to-markdown') 9 | ); 10 | console.log( 11 | chalk.hex('#1da1f2').inverse(' CONNECT '), 12 | 'with me on Twitter -> ', 13 | chalk.dim('https://twitter.com/msaaddev/\n') 14 | ); 15 | }; 16 | --------------------------------------------------------------------------------