nothingislost / obsidian-dynamic-highlights

An experimental Obsidian plugin that highlights all occurrences of the word under the cursor
MIT License
132 stars 7 forks source link

Allow Multi line Matches (`s` flag for a regex) #27

Open chrisgrieser opened 2 years ago

chrisgrieser commented 2 years ago

I'd like to create a highlighter for Pandoc's Custom Style Syntax, which looks like this:

::: {custom-style="foobar"}
blabla
blabla
:::

This means I need a regex with the s flag, and would be able to even make good use of the capture group feature. however, it seems multi-line regex or custom flags are not supported? I tried entering this as a highlighter rule.

/::: {custom-style="(.*)"}\n(.*)\n:::/s
nothingislost commented 2 years ago

I forgot that I looked into this but I seem to have an example that works in the current version if you want to try it. It appears that capture groups are not getting marked when multi-line matching happens, so I'll need to take a look into why that's breaking.

{
  "pandoc": {
    "class": "pandoc",
    "color": "#5CF60038",
    "regex": true,
    "query": "::: \\{custom-style=\"(?<group1>[^\"]*?)\"\\}(?<group2>[\\s\\S]*?):::",
    "mark": [
      "match",
      "group"
    ],
    "css": ""
  }
}
zcysxy commented 2 years ago

I also want to create a block highlight, but seems like the parent line only applies to the first line

image
zcysxy commented 2 years ago

Is it possible to surround the multi-line matches with <div> tags?