Closed janoshrubos closed 3 years ago
We could reuse the title from the markdown ie. > **Whatever**: something
would render a tip with Whatever
as the title instead of Note
.
Here's one possible regex to also match a few more possible cases like multiline quotes:
/^>\s+\*{2}([^\*]+)\*{2}:?\s+(.+(?:\n>.*)*)/gim
matches all of these variants:
> **Tip:** This is the content of the tip **including** other syntax like __this__ or _this_ or whatever else like `code` etc.
> **Tip**: This is the content of the tip **including** other syntax like __this__ or _this_ or whatever else like `code` etc.
> **Note:** This is the content of the tip **including** other syntax like __this__ or _this_ or whatever else like `code` etc.
> **Note**: This is the content of the tip **including** other syntax like __this__ or _this_ or whatever else like `code` etc.
> **Note**: This is the content of the tip **including** other syntax like __this__ or _this_ or whatever else like `code` etc.
> but also multi line comments and code blocks like
> ```ts
> console.log('hello world')
> ```
> also accepts spaces and stuff...
>
With this we get 2 capture groups:
**<title>**
qutoesPost-processing needed:
:
to make both > **Note:**
and **Note**:
work consistently /^>\s+/
in the second matching group to get rid of extra >
's from multiline quotes.A quick test that seems to cover all of the above:
(() => {
const debug = false;
let content = `
> **Tip:** This is the content of the tip **including** other syntax like __this__ or _this_ or whatever else like \`code\` etc.
> **Tip**: This is the content of the tip **including** other syntax like __this__ or _this_ or whatever else like \`code\` etc.
> **Note:** This is the content of the tip **including** other syntax like __this__ or _this_ or whatever else like \`code\` etc.
> **Note**: This is the content of the tip **including** other syntax like __this__ or _this_ or whatever else like \`code\` etc.
> **Note**: This is the content of the tip **including** other syntax like __this__ or _this_ or whatever else like \`code\` etc.
> but also multi line comments and code blocks like
> \`\`\`ts
> console.log('hello world')
> \`\`\`
> also accepts spaces and stuff...
>
`
const NOTE_RE = /^>\s+\*{2}([^\*]+)\*{2}:?\s+(.+(?:\n>.*)*)/gim;
let match_;
while(match_ = NOTE_RE.exec(content)) {
let [match, title, cont] = match_;
debug && console.log({
match, title, cont
})
// normalize title
title = title.replace(/:/g, '');
// replace "> " from multiline quotes
cont = cont.replace(/^>\s*/gim, '');
// generate replacement
const replacement = `:::tip ${title}\n\n${cont}\n\n:::`
// replace the match with the replacement
content = content.replace(match, replacement);
}
console.log(content);
})()
This enhancement will wrap the notes in the plugins docs with
:::tip Note ::::
, so the plugins will follow the main docs styling without messing up the originalREADME.md
Before:
After
: