Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

πŸ‘¨πŸ»β€πŸ’» Fix inlineCode to work with children #847

Merged
merged 1 commit into from
Jan 11, 2024
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
5 changes: 5 additions & 0 deletions .changeset/thirty-islands-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'myst-to-typst': patch
---

Fix inlinecode when there are children
12 changes: 6 additions & 6 deletions packages/myst-to-typst/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,16 @@ const handlers: Record<string, Handler> = {
},
inlineCode(node, state) {
let ticks = '`';
// inlineCode can sometimes have children (e.g. from latex)
const value = toText(node);
// Double ticks create empty inline code; we never want that for start/end
while (ticks === '``' || node.value.includes(ticks)) {
while (ticks === '``' || value.includes(ticks)) {
ticks += '`';
}
state.write(ticks);
if (node.value.startsWith('`')) state.write(' ');
state.write(node.value);
if (node.value.endsWith('`')) state.write(' ');
if (value.startsWith('`')) state.write(' ');
state.write(value);
if (value.endsWith('`')) state.write(' ');
state.write(ticks);
},
subscript(node, state) {
Expand All @@ -206,8 +208,6 @@ const handlers: Record<string, Handler> = {
state.ensureNewLine();
},
abbreviation(node, state) {
// TODO: \newacronym{gcd}{GCD}{Greatest Common Divisor}
// https://www.overleaf.com/learn/latex/glossaries
state.renderChildren(node, true);
},
link: linkHandler,
Expand Down
Loading