-
Notifications
You must be signed in to change notification settings - Fork 7
Make the Obsidian plugin loadable on mobile #1391
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
Draft
trangdoan982
wants to merge
3
commits into
main
Choose a base branch
from
eng-mobile-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,36 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { DEFAULT_MIME_TYPE, getMimeTypeForPath } from "~/utils/mimeType"; | ||
|
|
||
| describe("getMimeTypeForPath", () => { | ||
| it("resolves common attachment types", () => { | ||
| expect(getMimeTypeForPath("assets/diagram.png")).toBe("image/png"); | ||
| expect(getMimeTypeForPath("notes/paper.pdf")).toBe("application/pdf"); | ||
| expect(getMimeTypeForPath("clip.mp4")).toBe("video/mp4"); | ||
| }); | ||
|
|
||
| it("is case insensitive", () => { | ||
| expect(getMimeTypeForPath("Photo.JPG")).toBe("image/jpeg"); | ||
| }); | ||
|
|
||
| it("prefixes text formats with text/ so callers can skip them", () => { | ||
| expect(getMimeTypeForPath("note.md").startsWith("text/")).toBe(true); | ||
| expect(getMimeTypeForPath("data.csv").startsWith("text/")).toBe(true); | ||
| }); | ||
|
|
||
| it("uses the last extension of a multi-dot name", () => { | ||
| expect(getMimeTypeForPath("archive.tar.png")).toBe("image/png"); | ||
| }); | ||
|
|
||
| it("falls back for unknown and extensionless paths", () => { | ||
| expect(getMimeTypeForPath("notes/README")).toBe(DEFAULT_MIME_TYPE); | ||
| expect(getMimeTypeForPath("thing.unknownext")).toBe(DEFAULT_MIME_TYPE); | ||
| }); | ||
|
|
||
| it("does not treat a dotfile as an extension", () => { | ||
| expect(getMimeTypeForPath(".gitignore")).toBe(DEFAULT_MIME_TYPE); | ||
| }); | ||
|
|
||
| it("ignores dots in parent directories", () => { | ||
| expect(getMimeTypeForPath("my.folder/file")).toBe(DEFAULT_MIME_TYPE); | ||
| }); | ||
| }); |
58 changes: 58 additions & 0 deletions
58
apps/obsidian/src/utils/__tests__/splitFrontmatter.test.ts
This file contains hidden or 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,58 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { splitFrontmatter } from "~/utils/splitFrontmatter"; | ||
|
|
||
| describe("splitFrontmatter", () => { | ||
| it("splits a standard block", () => { | ||
| expect(splitFrontmatter("---\na: 1\nb: two\n---\nbody here")).toEqual({ | ||
| yaml: "a: 1\nb: two", | ||
| body: "body here", | ||
| }); | ||
| }); | ||
|
|
||
| it("handles CRLF line endings", () => { | ||
| expect(splitFrontmatter("---\r\na: 1\r\n---\r\nbody")).toEqual({ | ||
| yaml: "a: 1", | ||
| body: "body", | ||
| }); | ||
| }); | ||
|
|
||
| it("treats an empty block as present but empty", () => { | ||
| expect(splitFrontmatter("---\n---\nbody")).toEqual({ | ||
| yaml: "", | ||
| body: "body", | ||
| }); | ||
| }); | ||
|
|
||
| it("returns no frontmatter when the file does not start with a fence", () => { | ||
| const content = "intro text\n---\na: 1\n---\nbody"; | ||
| expect(splitFrontmatter(content)).toEqual({ yaml: null, body: content }); | ||
| }); | ||
|
|
||
| it("leaves a horizontal rule in the body alone", () => { | ||
| expect(splitFrontmatter("---\na: 1\n---\nbody\n---\nafter rule")).toEqual({ | ||
| yaml: "a: 1", | ||
| body: "body\n---\nafter rule", | ||
| }); | ||
| }); | ||
|
|
||
| it("handles a file that is only frontmatter", () => { | ||
| expect(splitFrontmatter("---\na: 1\n---")).toEqual({ | ||
| yaml: "a: 1", | ||
| body: "", | ||
| }); | ||
| }); | ||
|
|
||
| it("returns no frontmatter for content with no fence at all", () => { | ||
| expect(splitFrontmatter("just a note")).toEqual({ | ||
| yaml: null, | ||
| body: "just a note", | ||
| }); | ||
| }); | ||
|
|
||
| it("keeps multi-line YAML values intact", () => { | ||
| expect(splitFrontmatter("---\ntags:\n - a\n - b\n---\nbody")).toEqual({ | ||
| yaml: "tags:\n - a\n - b", | ||
| body: "body", | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When YAML parsing fails, the function returns
body: content(the original full content), but this is inconsistent with the successful parse path. WhensplitFrontmattersucceeds butparseYamlthrows, the frontmatter block markers (---) are already stripped frombody, so returning the originalcontentre-introduces them.Impact: A file with malformed YAML frontmatter will have the raw frontmatter block (including
---delimiters) left in the body text, which will render as markdown content instead of being hidden.Fix: Return the stripped body instead:
This way, the malformed frontmatter block is removed from the body (matching the successful parse behavior), and users get empty frontmatter instead of a parsing error (the desired tolerance behavior mentioned in the PR description).
Spotted by Graphite

Is this helpful? React 👍 or 👎 to let us know.