Page 1 of 1

Customizing Markdown preview

Posted: Mon May 16, 2022 4:55 pm
by ttasovac
Hi.
I'd like to customize the Markdown preview, but I can't figure out what CSS is responsible for it and how to extend it.
Inspecting a .md file in the properties view doesn't show it as being associated with a framework:
Image
So how should one go about customizing the markdown preview?
Many thanks in advance.
All best,
Toma

Re: Customizing Markdown preview

Posted: Tue May 17, 2022 7:12 am
by Radu
Hi Toma,

The main CSS for Markdown preview for the DITA and Lightweight DITA tabs is located in "OXYGEN_INSTALL_DIR/frameworks/dita/css/edit/preview-md.css".
The main CSS for Markdown preview for the HTML tab is located in "OXYGEN_INSTALL_DIR/frameworks/xhtml/css/xhtml-md.css".

Regards,
Radu

Re: Customizing Markdown preview

Posted: Tue May 17, 2022 1:15 pm
by ttasovac
Thanks Radu. Indeed, I can change the look of the html Markdown Preview if I tinker with the CSS in the XHTML framework inside oXygen installation. But I would like to extend the XHTML framework and set up my CSS in the extended framework so that it can be shared together with our other project files.

I did the usual thing for extending frameworks (i do it already for TEI and ODD), I set up an additional stylesheet in the extended framework, but this stylesheet doesn't seem to take effect. The Markdown preview doesn't include an inspect styles option, the way Author View does, so I can't really tell what's wrong and why my CSS rules aren't getting picked up.

Any additional tips you may have for me? How does oXygen know to associate the Markdown HTML Preview with the XHTML framework?

All best,
Toma

Re: Customizing Markdown preview

Posted: Tue May 17, 2022 1:30 pm
by Radu
Hi Toma,

This is not straight forward but possible.
Oxygen tries to load the CSS directly from the "oxygen_install_dir/frameworks/xhtml/css/xhtml-md.css" location but before doing so it passes the path through its XML catalog support.
For example if you create a custom XHTML extension framework folder somewhere on your disk, it could contain inside a "catalog.xml" looking something like this:

Code: Select all

<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
  <uriSuffix uriSuffix="xhtml-md.css" uri="md-preview.css"/>
</catalog>
and next to the catalog.xml a md-preview.css with the content something like this:

Code: Select all

@import "${framework(XHTML)}/css/xhtml.css";

@namespace oxy "http://www.oxygenxml.com/extensions/author";

oxy|processing-instruction {
  display:none !important;
}

head:empty {
  display:none;
}
Oxygen's CSS validation will report the CSS as invalid but Oxygen can actually properly read the import when the CSS is used for visual editing.
So in the Oxygen Preferences->"Document Type Associations" page if you edit your XHTML framework extension, in the "Catalogs" tab you can add a reference to ${framework}/catalog.xml and Oxygen should start passing through your XML catalog when looking for the "xhtml-md.css".
The Markdown XHTML preview tab has some caches in place so you may need to reopen Oxygen after you change the custom preview CSS.

Regards,
Radu

Re: Customizing Markdown preview

Posted: Tue May 17, 2022 1:47 pm
by ttasovac
Brilliant. Thanks a lot, Radu. This works perfectly for me.
All best,
Toma