Skip to the content.

Package Maintenance Info

Info for local developers to get the package up and running locally and publish it live

Run package locally

  1. In current package directory run npm link

    npm link
    
  2. In the directory you want to consume the package, run the following:

    npm link @ads-vdh/md-diff
    

Deployment

Project Setup

npm config set scope ads-vdh
npm config set access public

User Setup

Create an npm account and make sure you are added to ads-vdh org account in order to publish

Login to npm using either of the methods

A) Login to npm

npm login

or

B) For multiple accounts

Add .npmrc file in the current directory with the following info:

//registry.npmjs.org/:_authToken=***

Publish Package

Revision version number in package.json

npm publish --access public

Mocha Testing

Each test should look something like this:

it('should return del / ins on single word change', function() {
    // arrange
    let diffText = require("../src/index")
    let oldText = "your question site"
    let newText = "your answer site"
    let expected = "your <del>question</del> <ins>answer</ins> site"

    // act
    let actual = diffText(oldText, newText, false)

    // asset
    assert.equal(actual, expected);
});

HTML Testing

Test output against this fiddle which applies the following styles:

del {
    background: #ffc9c9;
    border-radius: 2px;
    text-decoration: line-through;
}

ins {
    background: #c9fff0;
    border-radius: 2px;
    text-decoration: underline;
}

RegEx

Tokenize Chars

/[\*,\."“”\[\]\(\)\n]/g

Tokenize Chars Not in Delimetr

/[\*,\."“”\[\]\(\)\n](?=(?:[^~]*~~[^~]*~~)*[^~]*$)/g

Detokenize Chars

/ (<\/?(?:ins|del)>)?([\*,\."“”\[\]\(\)\n])(<\/?(?:ins|del)>)? /g

Extract URLs

/https?:\/\/.*?(?=[\)\]\s])/g

Match Text NOT in Delimiter

/[^~]*(?=(?:[^~]*~[^~]*~)*[^~]*$)/g

Match Text NOT in 2 Char delimiter

/[^~]*(?=(?:[^~]*~~[^~]*~~)*[^~]*$)/g

Match Text Between Brackets

/(?<=<<).*?(?=>>)/g

Match Text NOT Between Brackets

/[^<>]*(?=(?:[^>]*<[^<]*>)*[^<>]*$)/g

Find NewLine in <ins>

/(?<=<ins>(?!<\/ins>)*?)(\\n\\n)(?=.*?<\/ins>)/g

Find NewLine in <ins> or <del>

/(?<=<(ins|del)>(?!<\/\1>)*?)(\\n\\n)(?=.*?<\/\1>)/g

Match Multiple Tag Groups w/ Back Reference

/<(ins|del)>.*<\/\1>/g

Match Multiple Tag Groups w/ Named Back Reference

/<(?<tag>ins|del)>.*<\/\k<tag>/g

Fix md link deltas

/\]\(<del>(.*)<\/del> <ins>(.*)<\/ins>\)/g