fix(widget-markdown): don't add duplicate marks (#3290)

This commit is contained in:
Erez Rokah 2020-02-19 19:21:50 +01:00 committed by GitHub
parent 73f679480b
commit 2a0aef27d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 1 deletions

View File

@ -0,0 +1 @@
Fill to_*this*_mark, and your charge is but a penny; to_*this*_a penny more; and so on to the full glass—the Cape Horn measure, which you may gulp down for a shilling.\n\nUpon entering the place I found a number of young seamen gathered about a table, examining by a dim light divers specimens of_*skrimshander*.

View File

@ -0,0 +1,41 @@
import path from 'path';
import fs from 'fs';
import { markdownToSlate } from '../';
describe('markdownToSlate', () => {
it('should handle use case from issue 3280', () => {
const mdast = fs.readFileSync(path.join(__dirname, '__fixtures__', 'issue_3280.md'));
const slate = markdownToSlate(mdast);
expect(slate).toEqual({
object: 'block',
type: 'root',
nodes: [
{
object: 'block',
type: 'paragraph',
nodes: [
{
object: 'text',
text: 'Fill to',
},
{
object: 'text',
text:
'this_mark, and your charge is but a penny; tothisa penny more; and so on to the full glass—the Cape Horn measure, which you may gulp down for a shilling.\\n\\nUpon entering the place I found a number of young seamen gathered about a table, examining by a dim light divers specimens ofskrimshander',
marks: [
{
type: 'italic',
},
],
},
{
object: 'text',
text: '.',
},
],
},
],
});
});
});

View File

@ -230,7 +230,9 @@ export default function remarkToSlate({ voidCodeBlock } = {}) {
* mark nodes, if any.
*/
const markType = markMap[node.type];
const marks = markType ? [...parentMarks, { type: markMap[node.type] }] : parentMarks;
const marks = markType
? [...parentMarks.filter(({ type }) => type !== markType), { type: markType }]
: parentMarks;
const children = flatMap(node.children, child => processMarkChild(child, marks));