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

Aliases can be defined as regexes and use regex replacement expressions #80

merged 3 commits into from Mar 27, 2018


None yet
2 participants
Copy link

commented Feb 2, 2018

I wanted to be able to define a single alias that would handle a range of expressions (essentially, giving aliases internal parameters that could be included in the replacement). So I made that a thing.

Changes proposed by this pull request:

  • XRegExp added as a dependency to allow for named groups (a must, IMO)
  • Aliases can define 'regex' instead of 'alias' to use regex matching
  • 'replaceWith' and 'end' can be defined as XRegExp replacement expressions, which allow including match groups from 'regex' in the replaced text. This is awesome.

@invicticide to review


This comment has been minimized.

Copy link

commented Feb 9, 2018

Can you comment back with an example of how this would work?

  • What the macro looks like in the source text
  • How the alias is defined in the project's fractive.json
  • What the expected result of that replacement is

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 10, 2018

Alongside a regular alias definition, a regex definition looks like this:

"aliases": [
		{ "regex": "vibe:(?<tag>[A-Za-z]+)", "replaceWith": "<span class='conditional' data-vibe-tag='${tag}'>", "end": "</span>" },
		{ "alias": "backButton", "replaceWith": "<a href='javascript:Core.GotoPreviousSection();'><i class=\"fa fa-arrow-left\" aria-hidden=\"true\"></i> Back</a>" }

A regex alias looks exactly like a regular one when it's invoked, depending on how complicated the regex is. In the given example, anything in the pattern {vibe:[SomeWord]} will be converted into the replaceWith pattern that can invoke [SomeWord] wherever it needs to.

What this means for me is, if I need to define a lot of divs in the body of my sections, and each with their own id, I could declare an alias like this:

{ "regex": "div:(?<id>[A-Za-z]+)", "replaceWith": "<div id='${id}'>" and suddenly I have a very convenient way to define an identifiable div in Markdown.

@invicticide invicticide merged commit 9a07569 into invicticide:dev Mar 27, 2018


This comment has been minimized.

Copy link

commented Mar 27, 2018

What? Six weeks is a totally normal amount of time for reviewing and accepting a PR... right? >_>

@NQNStudios NQNStudios deleted the NQNStudios:regex-aliases branch May 28, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.