@mieweb/wikigdrive
Version:
Google Drive to MarkDown synchronization
29 lines (28 loc) • 1.16 kB
JavaScript
import { walkRecursiveSync } from '../markdownNodesUtils.js';
// Related tests:
// test ./issue-434
// test ./example-document.md
export function fixSpacesInsideInlineFormatting(markdownChunks) {
walkRecursiveSync(markdownChunks.body, (chunk, ctx) => {
if (!chunk.parent) {
return;
}
if (chunk.isTag && ['B', 'I'].indexOf(chunk.tag) > -1) {
const prevChunk = chunk.children[chunk.children.length - 1];
if (prevChunk && prevChunk.isTag === false) {
const text = prevChunk.text;
const removedTrailingSpaces = text.replace(/[\s]+$/, '');
const spaces = text.substring(removedTrailingSpaces.length);
if (spaces.length > 0) {
prevChunk.text = removedTrailingSpaces;
chunk.parent.children.splice(ctx.nodeIdx + 1, 0, {
isTag: false,
text: spaces,
comment: 'fixSpacesInsideInlineFormatting.ts: spaces.length > 0'
});
// position++;
}
}
}
});
}