Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add new reg expresion #6

Open
indadev opened this issue Dec 11, 2021 · 1 comment
Open

add new reg expresion #6

indadev opened this issue Dec 11, 2021 · 1 comment

Comments

@indadev
Copy link

indadev commented Dec 11, 2021

Hi Im trying to add a new inlineRegexps. I want to bold the @text like text
to archive that Im doing this:

const inlineRegexps = {
  context: /^@(?=\S)([\S]*?\S)+/,
  strong: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
  em: /^_(?=\S)([\s\S]*?\S)_(?!_)|^\*(?=\S)([\s\S]*?\S)\*(?!\*)/,
  inlineCode: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
  link: /^!?\[([\s\S]+)\]\(\s*([\s\S]+)(?:\s+([\s\S]+))?\s*\)/,

  // order matters. text should be last for correct parsed
  text: /^(`+|[^`])(?:[\s\S]*?(?:(?=[\\<!\[`*]|\b_|$)|[^ ](?= {2,}\n))|(?= {2,}\n))/,
};

adding context to the inlineRegexps and

space: (token) => token.text,
  text: (token) => token.text,

  em: (token) => createElement('i', token.text, token.type),
  strong: (token) => createElement('b', token.text, token.type),
  context: (token) => createElement('b', token.text, token.type),

to the defaultRenderers.

What I am doing wrong?
I think I dont fully understand the regexpresions.

Thanks
I really like your yace and mdhl :D

@petersolopov
Copy link
Owner

Hi! Redefining inline or block regExps is not part of external API. But if you try to rewrite internal code for handling @test block and making it bold your version is definitely should work! It should be something like:

highlight('@test'); // => <span class="mdhl-paragraph"><b class="mdhl-context">@test</b></span>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants