I use Quill.js editor for editing text, I have bold and italic button but the problem that I need to transform html to markdown. For correct markdown I need that there are no spaces before or after strong or em tag, the best place I think will be to move spaces in html string
For example
let html = '<p><strong>some </strong><em>text</em> <strong>is </strong><em>here</em></p>';
The result must be
let html = '<p><strong>some</strong> <em>text</em> <strong>is</strong> <em>here</em></p>';
The space before close tag is moved after
How can I achive this result?
I try to split string for spaces and there get first tags but I can’t finish because I think I need some regExp
`const tags = ['strong', 'em']
let newHtml = ''
tags.forEach(tag => {
let splitOnMarker = html.split(' ')
})
let result = arr.reduce((acc, item) => {
item = item.replace(/(<\/strong>).*/, '</strong> ');
acc += item;
return acc;
}, '');`
>Solution :
You can do a simple replacement like so:
let html = '<p><strong>some </strong><em>text</em> <strong>is </strong><em>here</em></p>';
console.log(html);
html = html.replace(/ <\/strong>/g, '</strong> ');
html = html.replace(/ <\/em>/g, '</em> ');
html = html.replace(/<strong> /g, ' <strong>');
html = html.replace(/<em> /g, ' <em>');
console.log(html);