hagenburger / pimd

PIMD – Processing Instructions for Markdown
https://hagenburger.github.io/pimd-docs/
MIT License
20 stars 5 forks source link

Add custom CSS (or Sass/SCSS/Less) to a page #27

Open hagenburger opened 6 years ago

hagenburger commented 6 years ago

New feature

Allow page/code block-specific CSS.

Specification

<style>
  a { color: blue; }
</style>

Should add the text content of <style> to the contents of the document:

document.contents.add('css', '\n  a { color: blue; }\n')

Preprocessors

<style type="scss">
  a { color: lighten(blue, 10%); }
</style>

Should add the text content of <style> to the SCSS contents of the document:

document.contents.add('scss', '\n  a { color: lighten(blue, 10%); }\n')

The same must work for sass and less. Tbd: There should be a list of valid types which can be extended via plugin. If the type is not defined, it should raise an error.

Scoping

Often it is useful to add additional CSS to make an example look good in a style guide. A notification might have position: absolute but within the example it needs to be changed to position: relative. This change must not apply globally as the notification might be used outside of examples.

This could be solved by adding a class/ID to the code block and a scope to the <style>:

``` html .my-notification-example
<div class="my-notification error">
  An error happened.
</div>

That might be a bit too much to type. This should get a shortcut:

```` markdown
``` html
<div class="my-notification error">
  An error happened.
</div>

Tbd. `previous-element ` is just a first idea and needs to be discussed. It could be used elsewhere:

```` markdown
# Headline [link](#url)

<style previous-element>
  a { color: red; }
</style>

This requires automatically generated IDs (#26).