Skip to content

Commit

Permalink
criticmarkup input/normalisation
Browse files Browse the repository at this point in the history
  • Loading branch information
davidar committed Apr 9, 2019
1 parent 2ecac98 commit da172a8
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node
const commandLineArgs = require('command-line-args')
const fs = require('fs')
const pandiff = require('.')
const pkg = require('./package.json')

Expand All @@ -16,6 +17,10 @@ async function main (opts) {
console.error('pandiff', pkg.version)
} else if (files && files.length === 1 && files[0].endsWith('.docx')) {
text = await pandiff.trackChanges(files[0], opts)
} else if (files && files.length === 1 && files[0].endsWith('.md')) {
text = fs.readFileSync(files[0], 'utf8')
delete opts.files
text = await pandiff.normalise(text, opts)
} else if (files && files.length === 2) {
let [file1, file2] = files
opts.files = true
Expand Down
11 changes: 11 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,15 @@ const criticTrackChanges = text => text
.replace(regex.critic.ins, '<span class="insertion">$1</span>')
.replace(regex.critic.sub, '<span class="deletion">$1</span><span class="insertion">$2</span>')

const criticReject = text => text
.replace(regex.critic.del, '$1')
.replace(regex.critic.ins, '')
.replace(regex.critic.sub, '$1')
const criticAccept = text => text
.replace(regex.critic.del, '')
.replace(regex.critic.ins, '$1')
.replace(regex.critic.sub, '$2')

const pandocOptionsHTML = [
'--css', require.resolve('github-markdown-css'),
'--css', path.join(__dirname, 'pandiff.css'),
Expand Down Expand Up @@ -286,3 +295,5 @@ async function postrender (text, opts = {}) {
module.exports = pandiff
module.exports.trackChanges = (file, opts = {}) =>
pandoc(file, '--track-changes=all').toString().then(html => render(html, opts))
module.exports.normalise = (text, opts = {}) =>
pandiff(criticReject(text), criticAccept(text), opts)
6 changes: 6 additions & 0 deletions test/normalise.in.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
I really love *italic {~~fonts*~>font-styles*, really~~}.

- My first list item.
- My second {--list item.
- My third list item.
- My last--} combined list item.
6 changes: 6 additions & 0 deletions test/normalise.out.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
I really love *italic {~~fonts~>font-styles~~}*{~~.~>, really.~~}

- My first list item.
- My second {--list item.--}
- {--My third list item.--}
- {--My last --}combined list item.
4 changes: 4 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ describe('Track Changes', function () {
})

describe('Misc', function () {
it('normalise', async function () {
let text = await pandiff.normalise(fs.readFileSync('test/normalise.in.md', 'utf8'))
expect(text).to.equal(fs.readFileSync('test/normalise.out.md', 'utf8'))
})
it('atx', async function () {
let text = await pandiff('test/old.md', 'test/new.md', {
'atx-headers': true,
Expand Down

0 comments on commit da172a8

Please sign in to comment.