Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions packages/smart-cells/src/__tests__/markdown-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,13 @@ Count: {str(data["items"][0]["count"])}`.trim(),
quotePrefix: "",
});
expect(pythonCode).toMatchInlineSnapshot(`
"mo.md(
"""
"mo.md("""
# Markdown Title

Some content here.
"""
)"
""")"
`);
expect(offset).toBe(16);
expect(offset).toBe(11);
});

it("should preserve r-string prefix", () => {
Expand All @@ -146,12 +144,10 @@ Count: {str(data["items"][0]["count"])}`.trim(),
quotePrefix: "f",
});
expect(pythonCode).toMatchInlineSnapshot(`
"mo.md(
f"""
"mo.md(f"""
# Title
{some_variable}
"""
)"
""")"
`);
});

Expand Down
11 changes: 0 additions & 11 deletions packages/smart-cells/src/parsers/markdown-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,7 @@ export class MarkdownParser implements LanguageParser<MarkdownMetadata> {
// If it's one line and not bounded by quotes, write it as single line
const isOneLine = !code.includes("\n");
const boundedByQuote = code.startsWith('"') || code.endsWith('"');
const startQuote = `${quotePrefix}"""`;
if (isOneLine && !boundedByQuote) {
const markdown = `${startQuote}${escapedCode}"""`;
const prefix = "mo.md(";
if (markdown.length >= 80 - prefix.length) {
// Single lines are broken up if they exceed line length
const start = `${prefix}"\n ${startQuote}`;
return {
code: `${start}${escapedCode}"""\n)`,
offset: start.length,
};
}
const start = `mo.md(${quotePrefix}"""`;
const end = `""")`;
return { code: start + escapedCode + end, offset: start.length };
Expand Down
Loading