Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Dont process fields in code block #24

Merged
merged 1 commit into from
Feb 26, 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
16 changes: 9 additions & 7 deletions src/converters/roam/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ export class RoamConverter implements IConverter {
}

let url = undefined;
if (hasImages(nameToUse)) {
if (type !== 'codeblock' && hasImages(nameToUse)) {
const allImages = findGroups(nameToUse, '![](', ')');
// only one image, so we can create a single node
if (allImages.length === 1 && `![](${allImages[0].content})` === nameToUse) {
Expand Down Expand Up @@ -361,12 +361,14 @@ export class RoamConverter implements IConverter {
}
this.summary.totalNodes += 1;

if (isTodo(intermediateNode.name)) {
setNodeAsTodo(intermediateNode);
}
if (type !== 'codeblock') {
if (isTodo(intermediateNode.name)) {
setNodeAsTodo(intermediateNode);
}

if (isDone(intermediateNode.name)) {
setNodeAsDone(intermediateNode);
if (isDone(intermediateNode.name)) {
setNodeAsDone(intermediateNode);
}
}

// Some dates in Roam do not have the correct date-formatted UID for some reason, so we'll try to fix those
Expand All @@ -390,7 +392,7 @@ export class RoamConverter implements IConverter {
}
intermediateNode.refs = refs;

if (hasField(intermediateNode.name)) {
if (intermediateNode.type !== 'codeblock' && hasField(intermediateNode.name)) {
this.summary.fields += 1;
if (parentNode) {
this.convertToField(intermediateNode, parentNode);
Expand Down
17 changes: 17 additions & 0 deletions src/converters/roam/tests/fixtures/codeblocks.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,22 @@
":block/refs": [{ ":block/uid": "XWbzetf5I" }],
"title": "<%J:```code here```%>",
"create-time": 1588863716938
},
{
"edit-time": 1647535641290,
"refs": [],
"uid": "codefieldContainer",
"title": "Codefield",
"create-time": 1588863716938,
"children": [
{
"edit-time": 1647535641290,
"children": [],
"refs": [],
"uid": "codefield",
"title": "```\ncodefield:: codetest\n```",
"create-time": 1588863716938
}
]
}
]
3 changes: 3 additions & 0 deletions src/converters/roam/tests/roam.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ test('Code blocks', () => {

expect(f('otherCodeBlock')?.name).toBe('code here');
expect(f('otherCodeBlock')?.type).toBe('codeblock');

expect(f('codefield')?.type).toBe('codeblock');
expect(f('codefield')?.children?.map(n=>n.uid)).toEqual([])
});

test('Complex / nested node', () => {
Expand Down
Loading