I am using a diff api tool to create a nice diff to show changed text. I am using the google diff tool to accomplish this. When the diff text is generated it produces a ¶
at the end of each line. I want to remove all instances of this character. How would I go about doing it? Here is a demo of the tool.
Not knowing exactly what you're calling on the API is tricky, but these are the API calls used on the demo you linked, so I'm assuming your return is something similar. The replace function is still what you want, you just need to change what you're searching for. In this case ¶
instead of ¶
const string1 = `I am the very model of a modern Major-General,
I've information vegetable, animal, and mineral,
I know the kings of England, and I quote the fights historical,
From Marathon to Waterloo, in order categorical.`;
const string2 = `I am the very model of a cartoon individual,
My animation's comical, unusual, and whimsical,
I'm quite adept at funny gags, comedic theory I have read,
From wicked puns and stupid jokes to anvils that drop on your head.`;
const dmp = new diff_match_patch;
const diff = dmp.diff_main(string1, string2);
dmp.diff_cleanupSemantic(diff);
const prettyDiff = dmp.diff_prettyHtml(diff)
console.log('Original:', prettyDiff);
console.log('Replaced:', prettyDiff.replace(/¶/g, ''));
<script src="https://neil.fraser.name/software/diff_match_patch/svn/trunk/javascript/diff_match_patch.js"></script>
The following should do the job:
var str = 'abc¶def';
var replaced = str.replace(/¶/g, '');
console.log(str);
console.log(replaced);
However be aware, that the Diff library itself doesn't even return the paragraph marks:
var dmp = new diff_match_patch();
var diff = dmp.diff_main(inp1, inp2);
// maybe also call dmp.diff_cleanupSemantic(diff);
With that snippet you simply receive an array of changes between inp1
and inp2
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With