Skip to content

Commit

Permalink
fix(widget-markdown): don't add duplicate marks (#3290)
Browse files Browse the repository at this point in the history
  • Loading branch information
erezrokah committed Feb 19, 2020
1 parent 73f6794 commit 2a0aef2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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*.
Original file line number Diff line number Diff line change
@@ -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: '.',
},
],
},
],
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down

0 comments on commit 2a0aef2

Please sign in to comment.