How to use an external css-file in conjunction with the default marp theme?

See original GitHub issue

Hello Marp-Community,

I am using marp-cli to create lecture slides. In order to fine tune the slide content, I have created a custom-css that extends some style rules implemented in the marp default css template.

My objective: I want to externalize the css rules in a separate custom-theme.css file and remove them from the .md-document in which the slides’ content resides.

The problem: When calling the custom-theme.css using marp-cli with the --theme-set option, I can not specify that my css “extends” the style rules of the default template or that both styles should be used in conjunction

The question: What is the best way to tell marp-cli that my custom-theme.css should be used in conjunction with the marp default template?

Thanks in advance for the support.

N.B. Following your support rules, I wanted to post this question on stackoverflow but creating a marp or marp-cli tag requires a reputation of 1500.

N.B.(2) I forgot to mention that I really like the marp tool set and appreciate all the hard work the developers put into the project.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
yhattcommented, Jul 26, 2020

Hm, I’m feeling it’s weird. I’ve tried to use default theme + custom styling in minimum assets and it is working correctly.

---
theme: custom-theme
---

# Hello, world!
/* custom-theme.css */
/* @theme custom-theme */

@import 'default';

section {
  /* Override default background */
  background: #def;
}
marp --engine ./engine.js --bespoke.progress --watch --theme-set custom-theme.css -- mymarkdownfile.md
1reaction
StefanZandercommented, Jul 26, 2020

@yhatt, I require customization in order to use extensions (markdown-it-mark, markdown-it-container, markdown-it-attrs etc.); therefore, I am using the engine.js implementation as stated in the docs.

Thanks for the code fragment; my code in engine.js looks identical to yours

// engine.js
const { Marp } = require('@marp-team/marp-core')

const markdownItMark = require('markdown-it-mark')
const markdownItAttrs = require('markdown-it-attrs')
const markdownItContainer = require('markdown-it-container')
const markdownItFootnote = require('markdown-it-footnote')
const markdownItDiv = require('markdown-it-div')
// const markdownIt = require('markdown-it')

module.exports = (opts) => new Marp(opts)
// .use(markdownIt)
.use(markdownItMark)
.use(markdownItAttrs)
.use(markdownItContainer, 'definition')
.use(markdownItContainer, 'task')
.use(markdownItContainer, 'note')
.use(markdownItContainer, 'columns')
.use(markdownItContainer, '1st-col')
.use(markdownItContainer, '2nd-col')
.use(markdownItContainer, '3nd-col')
// .use(markdownItFootnote) // disabled because it causes error with marp-cli
.use(markdownItDiv)
.use(require('markdown-it-fontawesome'));

I used the marp class exactly as you described but then I could not make the marp-cli to use both, the default theme and my custom theme in conjunction.

Anyway, not be best solution but I could still revert to including all style information in the markdown-file, although I would love to have them separated to reuse the custom-theme in other marp projects.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Marp-CLI: How to use a custom theme that imports the default ...
My objective: I want to externalize the css rules in a custom-theme.css file and remove them from the .md -document in which the...
Read more >
Theme CSS - Marpit
Marpit has a default content: attr(data-marpit-pagination) , indicates the current page number. Theme CSS can add other strings and attributes to the shown...
Read more >
Making Mermaid Diagrams in Markdown - CSS-Tricks
You'll want to use the minified code (e.g., mermaid.min.js ) instead of the default export of mermaid.core.js . For example:
Read more >
wp_remote_post() failed. some theme features may not work. please ...
OSCHINA.NET 是目前领先的中文开源技术社区。我们传播开源的理念,推广开源项目,为 IT 开发者提供了一个发现、使用、并交流开源技术的平台.
Read more >
How to use Themes | MARP Template Library - GitHub Pages
The hard way (with Marp CLI)​ · Find your theme in our library (Dracula for example). · Download the css file from the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found