Skip to content

Commit 20da9f6

Browse files
committed
fix: Image upload works when mixed within links
The image handling code for uploading was written in a way such that if there were links _after_ the image, the image handling wouldn't work.
1 parent fe24524 commit 20da9f6

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -180,26 +180,27 @@ I need to explain more about [medialinks](http://example.com/medialink).
180180
p.s. I have not tested how this works, if you have configured Obsidian to use
181181
markdown links instead of medialinks.
182182

183-
## Missing features
183+
> [!WARNING]
184+
> This feature does not work for medialinks in a footnote due to a [bug in the
185+
> Obsidian API](https://github.com/obsidianmd/obsidian-api/issues/166).
186+
187+
## Desired features
184188

185189
### Essential
186190

187-
- Handle images.
188-
- Allows the user to specify tags (the DEV tags would probably be kept separate
189-
from Obsidian tags initially, but perhaps user configurable over time).
190-
- Securely handle API keys through system keychain/secure storage (although some
191+
* Securely handle API keys through system keychain/secure storage (although some
191192
research seems to indicate that this is not possible).
193+
* Better image handling. DEV doesn't support image upload through the API,
194+
requiring you to upload them manually, and configure the mapping in the
195+
frontmatter.
196+
* One possibility is to upload to another site, or AWS S3 instead.
197+
* Control published state from Obsidian. Right now, new articles are created as
198+
draft, allowing you to control everything before publishing.
199+
* Suggestion from @Rooyca: Autopublish - configurable by the user
192200

193201
So unfortunately, one essential feature seems to be impossible, let me know if
194202
you happen to know how a way to securely handle secrets from Obsidian plugins.
195203

196-
### Nice to have
197-
198-
- Control published state from Obsidian. Right now, new articles are created as
199-
draft, allowing you to control everything before publishing.
200-
- Suggestion from @Rooyca: Autopublish - configurable by the user
201-
202-
203204
## Filing a bug report
204205

205206
If creating a note doesn't work, first check, and double check that the

src/publisher.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ export default class Publisher<TFile extends { path: string }> {
9292
const flattened = replaceInstructions.filter(
9393
(x) => !replaceInstructions.find((y) => x.from > y.from && x.to < y.to),
9494
);
95+
flattened.sort((a, b) => a.from - b.from);
96+
// console.log("Replace instructions", flattened);
9597

9698
const result = flattened.reduce(
9799
(prev, curr) => {

test/markdown-processing.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ describe("Image resolution", () => {
135135
const gateway = createGatewayStubWithDefaults();
136136
const publisher = createPublisher(fakeApp, gateway);
137137
const file = fakeApp.fileManager.createFakeFile({
138-
contents: "A file with ![[embedded-image.png]] in it",
138+
contents: "A file with ![[embedded-image.png|an embedded image]] in it",
139139
frontmatter: {
140140
"dev-article-id": 42,
141141
"dev-image-map": [
@@ -150,7 +150,7 @@ describe("Image resolution", () => {
150150
gateway.updateArticle.should.have.been.calledOnce;
151151
const data = gateway.updateArticle.firstCall.args[0];
152152
data.article.markdown.should.equal(
153-
"A file with ![embedded-image.png](https://example.com/image.png) in it",
153+
"A file with ![an embedded image](https://example.com/image.png) in it",
154154
);
155155
});
156156
});

0 commit comments

Comments
 (0)