Bug 3: Insert CSS File Injects Inline `<style>` Block into `<body>` Not `<head>`

Viewed 3

Description

The Insert CSS File action reads the CSS file contents and injects them as an
inline <style> block directly inside <div id="wrapper"> in the document
body — not into <head>. The <style> element belongs in <head>, not
inside a <div> in <body>. While some browsers are lenient about this, it
is invalid HTML and not guaranteed to work correctly.

Steps to Reproduce

  1. In Custom Rules, add an Insert CSS File action pointing to any CSS file
  2. Export the document as HTML
  3. Inspect the HTML source around <div id="wrapper">

Expected Behavior

<head>
  <style type="text/css">
    /* Vostock style */
  </style>
  <style type="text/css">
    /* contents of injected CSS file */
  </style>
</head>

Actual Behavior

Verified from exported HTML (Parshat Bamidbar — Dvar Torah.TEMP_4.html):

</style>        ← Vostock style closes here
</head>         ← head closes here
<body class="export">
  <div id="wrapper"><style>/*
   * Hebrew Kriah Style for Marked 3
   * ================================
   ...
  */
  </style>

The full CSS file contents are injected as a <style> block at the very
start of <div id="wrapper"> — after </head> has already closed.

Documentation Reference

The Marked 3 Custom Processor docs describe Insert CSS File as injecting CSS
"after any Style selection." The Marked 3 Exporting docs state styles are
embedded in the output. Both imply CSS injection occurs in <head> alongside
the selected style — not in <body>:

"You can optionally include any of Marked's styles (or one of your custom
styles) in your export, giving you a ready-to-go document with necessary
formatting already embedded."
https://markedapp.com/help/Exporting.html

1 Answers

This is because the CSS injection happens prior to rendering, at a point whre it's still raw markdown and not a rendered HTML document. Every modern browser accepts this, whether it's valid HTML or not.

I'm looking at a way to hoist this after rendering, but it's not trivial.

Should be fixed for next release.