hagenburger / pimd

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

Highlight plugin #19

Closed hagenburger closed 5 years ago

hagenburger commented 6 years ago

New feature

Allow highlighting important parts of code examples.

Specifications

``` html +highlight="important-class"
<div class="important-class other-class">
  Lorem ipsum.
</div>


Result:

![preview](https://user-images.githubusercontent.com/103399/44298223-763e4800-a2df-11e8-83af-32fc8637a760.png)

### The following syntax should be valid:

* `+highlight="xxx"` – hightlight string
* `+highlight="xxx","yyy"` – hightlight multiple strings
* `+highlight=/xxx/` – search for RegExp
* `+highlight=/xxx/g` – allow modifiers
* `+highlight=/xxx/,/yyy/` – allow multiple RegExp
* `+highlight="xxx",/yyy/,/zzz/gi` – mix everything up

### Multiple highlights

When multiple highlights are given (separated by `;`), the highlights should get a different CSS class and different background color. To avoid this, the `|` operator can be used:

* `+highlight=/xxx|yyy/` – highlight `xxx` and `yyy` in yellow
* `+highlight=/xxx/,/yyy/` – highlight `xxx` in yellow, `yyy` in second color (tbd.)

## Open questions

* How to escape `"` and `/`? → Use JavaScript syntax
* Should `"` and `'` be allowed? → No, use JSON syntax (double quotes)
* Maybe `/class=".*(my-class).*"/` could highlight `my-class` only (as in the group). This could be useful for highlighting the tag name of `li` in `<li class="list-item">` but not within `list-item`. Background: Look ahead/behind in JavaScript’s RegExp are not supported well and hard to read/write. Using a group could be much more easy.
violetadev commented 6 years ago

#19 Highlight plugin