-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import non-Notion markdown directory (#273)
add experimental markdown / Obsidian importer - add source type to importer to support notion vs non-notion - conditionally strip and track notion Id from note title - resolve and convert [[Wikilinks]] - track and convert inline #tags - skip title parsing from front matter; fallback to file name when non-Notion import - use birthtime and mtime, not ctime, for default note creation date when front-matter not present - refactor file moving and resolving to walk all files, then move if referenced by a note - (bugfix) check for empty / null value when selecting new chronicles root - it implies the user clicked cancel - drop legacy importer code (was unused and kept for reference)
- Loading branch information
Showing
19 changed files
with
777 additions
and
767 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
declare module "mdast" { | ||
interface OfmTag extends Literal { | ||
type: "ofmTag"; | ||
value: string; | ||
} | ||
|
||
interface RootContentMap { | ||
ofmTag: OfmTag; | ||
} | ||
|
||
interface PhrasingContentMap { | ||
ofmTag: OfmTag; | ||
} | ||
} | ||
|
||
export { ofmTagFromMarkdown } from "./lib/fromMarkdown.js"; | ||
export { ofmTagToMarkdown } from "./lib/toMarkdown.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type { Extension } from "mdast-util-from-markdown"; | ||
|
||
/** | ||
* Create an extension for `mdast-util-from-markdown` to enable OFM tags in markdown. | ||
*/ | ||
export function ofmTagFromMarkdown(): Extension { | ||
return { | ||
enter: { | ||
ofmTag: function (token) { | ||
this.enter({ type: "ofmTag", value: "" }, token); | ||
}, | ||
ofmTagContent: function (token) { | ||
// note: modified this line to avoid needing es2022 which weirdly breaks | ||
// other stuff. | ||
// const node = this.stack.at(-1); | ||
const node = this.stack[this.stack.length - 1]; | ||
if (node?.type === "ofmTag") node.value = this.sliceSerialize(token); | ||
}, | ||
}, | ||
exit: { | ||
ofmTag: function (token) { | ||
this.exit(token); | ||
}, | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { Options } from "mdast-util-to-markdown"; | ||
|
||
/** | ||
* Create an extension for `mdast-util-to-markdown` to enable OFM tags in markdown. | ||
*/ | ||
export function ofmTagToMarkdown(): Options { | ||
return { | ||
handlers: { | ||
ofmTag(node) { | ||
const value = node.value; | ||
return `#${value}`; | ||
}, | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
declare module "micromark-util-types" { | ||
interface TokenTypeMap { | ||
ofmTag: "ofmTag"; | ||
ofmTagMarker: "ofmTagMarker"; | ||
ofmTagContent: "ofmTagContent"; | ||
} | ||
} | ||
|
||
// export { ofmTagHtml } from "./lib/html.js"; | ||
export { ofmTag } from "./lib/syntax.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
import type { | ||
Code, | ||
Effects, | ||
Extension, | ||
State, | ||
TokenizeContext, | ||
} from "micromark-util-types"; | ||
|
||
// ASCI Codes | ||
const SPACE = 32; | ||
const NUMBER_SIGN = 35; | ||
const DASH = 45; | ||
const SLASH = 47; | ||
const DIGIT_0 = 48; | ||
const DIGIT_9 = 57; | ||
const LETTER_A = 65; | ||
const LETTER_Z = 90; | ||
const UNDERSCORE = 95; | ||
const LETTER_a = 97; | ||
const LETTER_z = 122; | ||
|
||
/** | ||
* Create an extension for `micromark` to enable OFM tag syntax. | ||
*/ | ||
export function ofmTag(): Extension { | ||
return { | ||
text: { | ||
[NUMBER_SIGN]: { | ||
name: "ofmTag", | ||
tokenize: tokenize, | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
/** | ||
* A tokenizer for Obsidian tag syntax. | ||
* The tag must include at least one non-numerical character. | ||
*/ | ||
function tokenize( | ||
this: TokenizeContext, | ||
effects: Effects, | ||
ok: State, | ||
nok: State, | ||
) { | ||
const previous = this.previous; | ||
const events = this.events; | ||
return start; | ||
|
||
/** | ||
* Start of tag | ||
* | ||
* ```markdown | ||
* > | #123/tag | ||
* ^ | ||
* ``` | ||
*/ | ||
function start(code: Code) { | ||
// Only tags can be chained directly without space | ||
if ( | ||
previous && | ||
previous > SPACE && | ||
events[events.length - 1][1].type !== "ofmTag" | ||
) { | ||
return nok(code); | ||
} | ||
|
||
effects.enter("ofmTag"); | ||
effects.enter("ofmTagMarker"); | ||
effects.consume(code); | ||
effects.exit("ofmTagMarker"); | ||
effects.enter("ofmTagContent"); | ||
return inside_tag_candidate; | ||
} | ||
|
||
/** | ||
* Inside a tag without any non-numerical character | ||
* | ||
* ```markdown | ||
* > | #123/tag | ||
* ^^^ | ||
* ``` | ||
*/ | ||
function inside_tag_candidate(code: Code) { | ||
if (code && code >= DIGIT_0 && code <= DIGIT_9) { | ||
effects.consume(code); | ||
return inside_tag_candidate; | ||
} | ||
|
||
if ( | ||
code && | ||
((code >= LETTER_A && code <= LETTER_Z) || | ||
(code >= LETTER_a && code <= LETTER_z) || | ||
code === UNDERSCORE || | ||
code === DASH || | ||
code === SLASH) | ||
) { | ||
effects.consume(code); | ||
return inside_tag; | ||
} | ||
|
||
return nok(code); | ||
} | ||
|
||
/** | ||
* Inside a tag with at least one non-numerical character | ||
* | ||
* ```markdown | ||
* > | #123/tag | ||
* ^^^^ | ||
* ``` | ||
*/ | ||
function inside_tag(code: Code) { | ||
if ( | ||
code && | ||
((code >= DIGIT_0 && code <= DIGIT_9) || | ||
(code >= LETTER_A && code <= LETTER_Z) || | ||
(code >= LETTER_a && code <= LETTER_z) || | ||
code === UNDERSCORE || | ||
code === DASH || | ||
code === SLASH) | ||
) { | ||
effects.consume(code); | ||
return inside_tag; | ||
} | ||
|
||
effects.exit("ofmTagContent"); | ||
effects.exit("ofmTag"); | ||
return ok(code); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.