-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
promote local media assets to file attachments
- Loading branch information
Showing
2 changed files
with
97 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import assert from "node:assert"; | ||
import {normalizePieceHtml} from "../src/markdown.js"; | ||
import {resolvePath} from "../src/url.js"; | ||
|
||
const html = (strings, ...values) => String.raw({raw: strings}, ...values); | ||
const mockContext = () => ({files: [], imports: [], pieces: [], startLine: 0, currentLine: 0}); | ||
|
||
describe("file attachments", () => { | ||
describe("success", () => { | ||
const sourcePath = "/attachments.md"; | ||
|
||
it("img[src]", () => { | ||
const htmlStr = html`<img src="./test.png">`; | ||
const expected = html`<img src="./_file/test.png">`; | ||
const context = mockContext(); | ||
const actual = normalizePieceHtml(htmlStr, sourcePath, context); | ||
|
||
assert.equal(expected, actual); | ||
assert.deepEqual(context.files, [ | ||
{ | ||
mimeType: "image/png", | ||
name: "./test.png", | ||
path: "./_file/test.png" | ||
} | ||
]); | ||
}); | ||
|
||
it("video[src]", () => { | ||
const htmlStr = html`<video src="observable.mov" controls> | ||
Learn more about Observable CLI | ||
</video>`; | ||
const expected = html`<video src="./_file/observable.mov" controls> | ||
Learn more about Observable CLI | ||
</video>`; | ||
const context = mockContext(); | ||
const actual = normalizePieceHtml(htmlStr, sourcePath, context); | ||
|
||
assert.equal(expected, actual); | ||
assert.deepEqual(context.files, [ | ||
{ | ||
mimeType: "video/quicktime", | ||
name: "observable.mov", | ||
path: "./_file/observable.mov" | ||
} | ||
]); | ||
}); | ||
|
||
it("video source[src]", () => { | ||
const htmlStr = html`<video width="320" height="240" controls> | ||
<source src="observable.mp4" type="video/mp4"> | ||
<source src="observable.mov" type="video/mov"> | ||
Learn more about Observable CLI | ||
</video>`; | ||
|
||
const expected = html`<video width="320" height="240" controls> | ||
<source src="./_file/observable.mp4" type="video/mp4"> | ||
<source src="./_file/observable.mov" type="video/mov"> | ||
Learn more about Observable CLI | ||
</video>`; | ||
|
||
const context = mockContext(); | ||
const actual = normalizePieceHtml(htmlStr, sourcePath, context); | ||
|
||
assert.equal(expected, actual); | ||
assert.deepEqual(context.files, [ | ||
{ | ||
mimeType: "video/mp4", | ||
name: "observable.mp4", | ||
path: "./_file/observable.mp4" | ||
}, | ||
{ | ||
mimeType: "video/quicktime", | ||
name: "observable.mov", | ||
path: "./_file/observable.mov" | ||
} | ||
]); | ||
}); | ||
}); | ||
}); |