Skip to content

Commit

Permalink
Merge pull request #24 from tanainc/sh/fieldCode
Browse files Browse the repository at this point in the history
Dont process fields in code block
  • Loading branch information
houshuang committed Feb 26, 2024
2 parents cb4e5d7 + 9828a9c commit 65920f1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
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

0 comments on commit 65920f1

Please sign in to comment.