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

Feat: Generate lists from RegExp Patterns #161

Closed
about-code opened this issue Jun 1, 2021 · 0 comments · Fixed by #162
Closed

Feat: Generate lists from RegExp Patterns #161

about-code opened this issue Jun 1, 2021 · 0 comments · Fixed by #162
Labels
enhancement New feature or request

Comments

@about-code
Copy link
Owner

about-code commented Jun 1, 2021

User Story
Currently lists can be generated from arbitrary HTML tags with an id identifier, for example, anchor tags:

<a id="some id", class="listOf_class", title="Some Title"></a>
Book section to be listed...

As a vuepress author I would like to generate a list of Tasks from vuepress Custom Containers, e.g. a :::details container but I do not want to prepend every such task with an HTML anchor tag:

:::details Task: This could be the list item title

1. Do this
2. Do that
:::

I would like to be able to generate a list of tasks using a Regular Expression which

  • matches a particular pattern
  • may optionally contain a RegExp Capture Group in braces ^(group)$ to extract the list item title.

For example, I would like to be able to configure glossarify-md like this:

{
   "generateFiles": {
     "listOf": [{ 
       "class": "task",
       "title": "Tasks", 
       "file": "list-of-tasks.md", 
       "pattern": ":::details Task: ([a-zA-Z0-9].*)"
     }]
   }
}

Internally when glossarify-md finds an mdAst text node which matches the given pattern it should generate and prepend the required HTML target element itself by the following algorithm:

Anchorizer Algorithm:

  1. Obtain the listOf config that matched against an mdAst text node's value
  2. Obtain as target <element class="..."> the class of the listOf config that matched
  3. Obtain as target <element title=" " >
    • a) the value extracted by pattern capture group $1 when matched against the mdAst text node value
    • b) the mdAst text node value, if there's no capture group
  4. Obtain as target <element id="..."> a length-limited slug of the title extracted in 3. with a unifying number appended

Appending a unifying number is required since there could be another listOf pattern matching the same text node and extracting the identical title which would result in an identical id. Yet the spec of the id-Attribute requires a unique value for the attribute.

@about-code about-code added the enhancement New feature or request label Jun 1, 2021
@about-code about-code changed the title Feat: Generate lists from RegExp Patterns matching against text nodes Feat: Generate lists from RegExp Patterns Jun 1, 2021
about-code added a commit that referenced this issue Jun 1, 2021
* feat: 'listOf' patterns
* test: New test cases
* test: New baseline
* Extend Config Schema (Backwards Compatible)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant