GithubHelp home page GithubHelp logo

accraze / split-md Goto Github PK

View Code? Open in Web Editor NEW
23.0 3.0 11.0 35 KB

:wavy_dash: Split a Markdown file into smaller files

Home Page: https://www.npmjs.com/package/split-md

License: MIT License

JavaScript 100.00%
smaller-files delimiter cli markdown markdown-parser

split-md's Issues

'split-md': command not found

Hello, I'm excited to use this package. I tried to install, and it seems to have gone well:

drive$ npm i split-md

up to date, audited 15 packages in 773ms

1 package is looking for funding
  run `npm fund` for details

found 0 vulnerabilities

But then I tried to use the script in the fashion you mention:

split-md 'Letters.md' '### v' '###' '' 10 true

And I got this:

-bash: split-md: command not found

Any idea what might be going on? Thanks!

Invalid path and filename in Windows

Firstly, thanks for the utility it helped me split my large MD files (and learn a bit about Node JS).

I'm posting my solution because I have never done a pull request before.

My MD file has headings like this (note the embedded ':' and '/')

#### AAA-BBB-1100: Some Title / Other Text

My split-md args were:

cli.args[0]="F:/a/b/c/markdownfile.md";
cli.args[1]="#### ";
cli.args[2]="####";
cli.args[3]="F:/a/b/c/";

So after Line 28

title="F:/a/b/c/AAA-BBB-1100: Some Title / Other Text"

The title/path is still ok at this point.
but after Line 29

title="F/a/b/c/AAA-BBB-1100:Some Title / Other Text.md"

The first ':' is removed making the drive field invalid. Remaining ':' are not removed because title.replace() only replaces the first occurrence. The same happens with the space ' ' replacement.
Anothe problem is that the '/' in the ""filename" is not removed also making it an invalid path.

I replaced these two lines...

split-md/src/splitter.js

Lines 28 to 29 in 495101e

title = writePath + array[i].replace(cleanName, "").trim()
title = title.replace(":", "").replace(" ", "") + ".md"

With these 3 lines...

      title = array[i].replace(cleanName, "").trim()
      title = sanitize(title, {replacement: "-"});
      title = writePath + title + ".md"; 

The writePath is only added after the title is cleaned otherwise it messes up the path.
I used the sanitize-filename library.

const sanitize = require('sanitize-filename');

p.s. I prefer leaving the spaces in the filename and replace illegal characters with a dash. '-'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.