-
-
Notifications
You must be signed in to change notification settings - Fork 111
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
Fix: Add ability to reference external themes (closes #183) #571
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ import fs from 'fs' | |
import path from 'path' | ||
import { Marpit } from '@marp-team/marpit' | ||
import { isDynamicPattern } from 'globby' | ||
import { warn } from './cli' | ||
import { warn, info } from './cli' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused import? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was from debugging, but I can remove it in the next commit. |
||
import { isError } from './error' | ||
import { File } from './file' | ||
|
||
|
@@ -33,7 +33,23 @@ export class Theme { | |
} | ||
|
||
async load() { | ||
this.readBuffer = await fs.promises.readFile(this.filename) | ||
if (this.isUrl(this.filename)) { | ||
// Fetch the content from a remote URL | ||
const response = await fetch(this.filename) | ||
this.readBuffer = Buffer.from(await response.text()) | ||
} else { | ||
// Read the content from a local file | ||
this.readBuffer = await fs.promises.readFile(this.filename) | ||
} | ||
} | ||
|
||
private isUrl(filename: string): boolean { | ||
try { | ||
new URL(filename) | ||
return true | ||
} catch { | ||
return false | ||
} | ||
} | ||
Comment on lines
+46
to
53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
static isRemoteUrl(filename: string) {
try {
const url = new URL(filename)
return url.protocol === 'http' || url.protocol === 'https'
} catch {
return false
}
} {
path: Theme.isRemoteUrl(this.args.theme) ? this.args.theme : path.resolve(this.args.theme)
} |
||
|
||
private genUniqName() { | ||
|
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.
The path normalization is required also for the
theme
string from the configuration file. (marp.config.js
etc)