Skip to content

Commit

Permalink
Merge pull request #147 from inokawa/issue142
Browse files Browse the repository at this point in the history
Fixed bug that inlineCode could be undefined in slate to remark
  • Loading branch information
inokawa authored Jun 11, 2023
2 parents fcfe00c + dc9293c commit 07ba10e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10469,6 +10469,33 @@ exports[`issues issue145 2`] = `
"
`;

exports[`issues issue145-2 1`] = `
{
"children": [
{
"children": [
{
"children": [
{
"type": "inlineCode",
"value": "code",
},
],
"type": "emphasis",
},
],
"type": "paragraph",
},
],
"type": "root",
}
`;

exports[`issues issue145-2 2`] = `
"_\`code\`_
"
`;

exports[`options override builders 1`] = `
[
{
Expand Down
19 changes: 19 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,4 +278,23 @@ describe("issues", () => {
const text = processor.stringify(ast);
expect(text).toMatchSnapshot();
});

it("issue145-2", () => {
const processor = unified()
.use(markdown)
.use(slateToRemark)
.use(stringify, { emphasis: "_" });
const ast = processor.runSync({
type: "root",
children: [
{
type: "paragraph",
children: [{ emphasis: true, inlineCode: true, text: "code" }],
},
],
} as any);
expect(ast).toMatchSnapshot();
const text = processor.stringify(ast);
expect(text).toMatchSnapshot();
});
});
11 changes: 10 additions & 1 deletion src/transformers/slate-to-mdast/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,16 @@ const convertTexts = (
const prev = slateTexts[j - 1];
const next = slateTexts[j + 1];
ends = [];
(["inlineCode", "emphasis", "strong", "delete"] as const).forEach((k) => {
(
[
"emphasis",
"strong",
"delete",
// inlineCode should be last because of the spec in mdast
// https://github.com/inokawa/remark-slate-transformer/issues/145
"inlineCode",
] as const
).forEach((k) => {
if (cur[k]) {
if (!prev || !prev[k]) {
starts.push(k);
Expand Down

0 comments on commit 07ba10e

Please sign in to comment.