Markpad icon indicating copy to clipboard operation
Markpad copied to clipboard

Custom CSS

Open Fallgrim opened this issue 3 months ago • 3 comments

What problem would this solve?

  • A section to add custom CSS will lead to more personal markdown files as it gives us more freedom.
  • Actually, I think it's a must for users like me who use only markdown for their note-taking workflow; and if they can't customise a part of their workflow — the part is Markpad in this situation, it will be unusable for them.

What would you like?

  • Just add a section to let us add our own custom.css files.

What have you tried instead?

  • Just waiting for it to be happen.

Fallgrim avatar Aug 18 '26 18:08 Fallgrim

Two things that might change what's being asked for here. Notes only — not something I'm picking up right now.

Part of this may already have landed. If the goal is colouring the markdown itself — bold, italic, strikethrough, ==highlight==, inline code, links — #678 and #686 are in. The editor now reads its colours from the same comrak parse the preview is built from, so an imported theme colours those spans directly, and the rule is exact: if it renders, it can be coloured. Given #676, it would help to know what's still missing after those, because the answer may be a few specific colours rather than arbitrary CSS.

On arbitrary CSS: the code is the cheap part, and it isn't the part that decides. A text area plus a <style> element is a short diff, and the CSP already allows it (style-src 'unsafe-inline'). What it costs is elsewhere:

  • It reverses a decision that's currently enforced. Every value in an imported VS Code theme goes through isSafeCssColor (src/lib/utils/theme.ts) precisely so a value cannot terminate the declaration block and open a new rule — the comment there spells out the injection string, and the check is applied a second time at the point of interpolation to stop the hole being reintroduced by a later edit. A free-form CSS field is that hole, deliberately. That matters less for CSS the user wrote themselves and quite a lot for CSS shared between users, which is what a customisation feature tends to produce — and img-src permits https:, so url() in a shared stylesheet is an outbound channel.

  • It makes internal class names a public API. The preview is styled through Svelte-scoped rules on classes like .markdown-body. Once user stylesheets target those, renaming or restructuring them breaks people's configuration silently, and there's no test that would catch it. The specificity is awkward from the user's side too: scoped styles carry an extra class, so overrides need !important or careful selectors.

  • The next request follows immediately. Custom CSS without custom fonts is half the feature, and font-src is 'self'.

A cheaper shape, if the goal is "I want my own colours". The whole UI, preview included, already renders off a small set of --color-* / --hljs-* variables, and applyVscodeTheme writes them into one :root block. Exposing those as user-settable, with values still passing isSafeCssColor, covers most of what people mean by customisation and keeps the property above intact — no new injection surface, no new compatibility commitment, and no CSP change.

Whether the full version is worth its cost is the maintainer's call; the above is just what the bill looks like.

PathGao avatar Aug 21 '26 10:08 PathGao

I've just tested the latest version (v.2.7.6) and I'm glad for the colouring markdown syntax in editor view, but nothing has changed for the preview mode, why?

Colour highlighting is much more important in preview mode because when we open an external md file, we should be able to see the syntax clearly. (As I open the existing files in preview mode.)

Also I just want to share: I'm in love with the "animate cursor movement" feature. It makes writing so smooth!

Fallgrim avatar Aug 29 '26 20:08 Fallgrim

I've just tested the latest version (v.2.7.6) and I'm glad for the colouring markdown syntax in editor view, but nothing has changed for the preview mode, why?

Colour highlighting is much more important in preview mode because when we open an external md file, we should be able to see the syntax clearly. (As I open the existing files in preview mode.)

Also I just want to share: I'm in love with the "animate cursor movement" feature. It makes writing so smooth!

fixing now。you can import schemes to get that in next release

PathGao avatar Sep 01 '26 16:09 PathGao