-
-
Notifications
You must be signed in to change notification settings - Fork 108
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?
Fix: Add ability to reference external themes (closes #183) #571
Conversation
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.
Some concerns:
theme
field from the configuration file should recognize URL as same as--theme
CLI option.- How about in
--theme-set
CLI options /themeSet
field in the configuration file? - Compatibillity with watch mode: In
ThemeSet
class, the URL should except from the observing files.
Line 122 in 04a1bcf
const fn = [...baseFn, ...themes.map((t) => t.filename)] |
@@ -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 comment
The 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 comment
The 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.
private isUrl(filename: string): boolean { | ||
try { | ||
new URL(filename) | ||
return true | ||
} catch { | ||
return false | ||
} | ||
} |
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.
isUrl()
may be better to make public class method, and also use for testing whether apply path.resolve
to the passed theme. In addition, it might be good to limit the URL protocol to http
or https
.
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)
}
path: path.resolve(this.args.theme), | ||
path: this.args.theme.includes(`http`) | ||
? this.args.theme | ||
: path.resolve(this.args.theme), | ||
} | ||
|
||
if (this.conf.theme) |
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)
Is anybody still working on that? Is there a best practice suggested to use external Theme Urls? |
Marp team is not working on this PR, to keep CLI secure by reducing remote access capabilities. See marp-team/marp#523. But any contributors who are intersted in this can pick up this and can improve implementation by following the review. |
Description
I like Marp, but I don't particularly like using VS Code. As a user of the CLI, I'd like to be able to write my markdown in any editor and then reference a hosted stylesheet to use as a particular theme. This is common — as an example — for my organization, as we want to use a single source of truth for our template(s).
Implementation
In the
config.ts
, we don't try to resolve the local path ifhttp
is included within the string passed to the--theme
argument:Further, on the
load()
function, we either use the local file via a buffer, or fetch the remote file:Testing
Coverage was above the 95% threshold 🎉
You can use this ref when building the binary: