markdowndiffpatch
v1.0.1
Published
Create and apply patches for markdown content using jsondiffpatch-compatible interfaces
Downloads
12
Maintainers
Readme
markdowndiffpatch
A markdown-focused diff and patch library with jsondiffpatch-compatible interfaces.
Installation
npm install markdowndiffpatchUsage
import markdownDiffPatch from 'markdowndiffpatch';
const left = '# Hello\n\nThis is a test.';
const right = '# Hello\n\nThis is a test.\n\nNew paragraph.';
// Create a diff
const delta = markdownDiffPatch.diff(left, right);
// Apply the patch
const patched = markdownDiffPatch.patch(left, delta);
// Reverse the patch
const unpatched = markdownDiffPatch.unpatch(right, delta);
// Reverse the delta
const reversedDelta = markdownDiffPatch.reverse(delta);API
diff(left: string, right: string, options?: DiffOptions): DiffResult | undefined
Creates a diff between two markdown strings. Returns undefined if the strings are identical.
patch(left: string, delta: DiffResult, options?: PatchOptions): string
Applies a diff to a markdown string.
unpatch(right: string, delta: DiffResult): string
Reverses a patch operation.
reverse(delta: DiffResult): DiffResult
Reverses a delta so that it can be applied in the opposite direction.
Related Projects
- jsondiffpatch - Diff & patch JavaScript objects
- htmldiffpatch - Diff & patch for HTML documents
License
MIT
